Completed
Push — master ( 35a6df...32735f )
by Brian
18s queued 13s
created
includes/wpinv-item-functions.php 1 patch
Spacing   +302 added lines, -302 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by_id( $id ) {
6
-    return wpinv_get_item_by( 'id', $id );
5
+function wpinv_get_item_by_id($id) {
6
+    return wpinv_get_item_by('id', $id);
7 7
 }
8 8
 
9
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
10
-    if( empty( $field ) || empty( $value ) ) {
9
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
10
+    if (empty($field) || empty($value)) {
11 11
         return false;
12 12
     }
13 13
     
14 14
     $posts = array();
15 15
 
16
-    switch( strtolower( $field ) ) {
16
+    switch (strtolower($field)) {
17 17
         case 'id':
18
-            $item = new WPInv_Item( $value );
18
+            $item = new WPInv_Item($value);
19 19
 
20
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
20
+            if (!empty($item) && $item->post_type == 'wpi_item') {
21 21
                 return $item;
22 22
             }
23 23
             return false;
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
 
27 27
         case 'slug':
28 28
         case 'name':
29
-            $posts = get_posts( array(
29
+            $posts = get_posts(array(
30 30
                 'post_type'      => 'wpi_item',
31 31
                 'name'           => $value,
32 32
                 'posts_per_page' => 1,
33 33
                 'post_status'    => 'any'
34
-            ) );
34
+            ));
35 35
 
36 36
             break;
37 37
         case 'custom_id':
38
-            if ( empty( $value ) || empty( $type ) ) {
38
+            if (empty($value) || empty($type)) {
39 39
                 return false;
40 40
             }
41 41
             
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
                 'post_status'    => 'any',
56 56
                 'orderby'        => 'ID',
57 57
                 'order'          => 'ASC',
58
-                'meta_query'     => array( $meta_query )
58
+                'meta_query'     => array($meta_query)
59 59
             );
60 60
             
61
-            $posts = get_posts( $args );
61
+            $posts = get_posts($args);
62 62
 
63 63
             break;
64 64
 
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
             return false;
67 67
     }
68 68
     
69
-    if ( !empty( $posts[0] ) ) {
70
-        $item = new WPInv_Item( $posts[0]->ID );
69
+    if (!empty($posts[0])) {
70
+        $item = new WPInv_Item($posts[0]->ID);
71 71
 
72
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
72
+        if (!empty($item) && $item->post_type == 'wpi_item') {
73 73
             return $item;
74 74
         }
75 75
     }
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
     return false;
78 78
 }
79 79
 
80
-function wpinv_get_item( $item = 0 ) {
81
-    if ( is_numeric( $item ) ) {
82
-        $item = get_post( $item );
83
-        if ( ! $item || 'wpi_item' !== $item->post_type )
80
+function wpinv_get_item($item = 0) {
81
+    if (is_numeric($item)) {
82
+        $item = get_post($item);
83
+        if (!$item || 'wpi_item' !== $item->post_type)
84 84
             return null;
85 85
         return $item;
86 86
     }
@@ -93,18 +93,18 @@  discard block
 block discarded – undo
93 93
 
94 94
     $item = get_posts($args);
95 95
 
96
-    if ( $item ) {
96
+    if ($item) {
97 97
         return $item[0];
98 98
     }
99 99
 
100 100
     return null;
101 101
 }
102 102
 
103
-function wpinv_get_all_items( $args = array() ) {
103
+function wpinv_get_all_items($args = array()) {
104 104
 
105
-    $args = wp_parse_args( $args, array(
106
-        'status'         => array( 'publish' ),
107
-        'limit'          => get_option( 'posts_per_page' ),
105
+    $args = wp_parse_args($args, array(
106
+        'status'         => array('publish'),
107
+        'limit'          => get_option('posts_per_page'),
108 108
         'page'           => 1,
109 109
         'exclude'        => array(),
110 110
         'orderby'        => 'date',
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         'meta_query'     => array(),
114 114
         'return'         => 'objects',
115 115
         'paginate'       => false,
116
-    ) );
116
+    ));
117 117
 
118 118
     $wp_query_args = array(
119 119
         'post_type'      => 'wpi_item',
@@ -123,26 +123,26 @@  discard block
 block discarded – undo
123 123
         'fields'         => 'ids',
124 124
         'orderby'        => $args['orderby'],
125 125
         'order'          => $args['order'],
126
-        'paged'          => absint( $args['page'] ),
126
+        'paged'          => absint($args['page']),
127 127
     );
128 128
 
129
-    if ( ! empty( $args['exclude'] ) ) {
130
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
129
+    if (!empty($args['exclude'])) {
130
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
131 131
     }
132 132
 
133
-    if ( ! $args['paginate' ] ) {
133
+    if (!$args['paginate']) {
134 134
         $wp_query_args['no_found_rows'] = true;
135 135
     }
136 136
 
137
-    if ( ! empty( $args['search'] ) ) {
137
+    if (!empty($args['search'])) {
138 138
         $wp_query_args['s'] = $args['search'];
139 139
     }
140 140
 
141
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
142
-        $types = wpinv_parse_list( $args['type'] );
141
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
142
+        $types = wpinv_parse_list($args['type']);
143 143
         $wp_query_args['meta_query'][] = array(
144 144
             'key'     => '_wpinv_type',
145
-            'value'   => implode( ',', $types ),
145
+            'value'   => implode(',', $types),
146 146
             'compare' => 'IN',
147 147
         );
148 148
     }
@@ -150,17 +150,17 @@  discard block
 block discarded – undo
150 150
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
151 151
 
152 152
     // Get results.
153
-    $items = new WP_Query( $wp_query_args );
153
+    $items = new WP_Query($wp_query_args);
154 154
 
155
-    if ( 'objects' === $args['return'] ) {
156
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
157
-    } elseif ( 'self' === $args['return'] ) {
155
+    if ('objects' === $args['return']) {
156
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
157
+    } elseif ('self' === $args['return']) {
158 158
         return $items;
159 159
     } else {
160 160
         $return = $items->posts;
161 161
     }
162 162
 
163
-    if ( $args['paginate' ] ) {
163
+    if ($args['paginate']) {
164 164
         return (object) array(
165 165
             'items'      => $return,
166 166
             'total'         => $items->found_posts,
@@ -172,143 +172,143 @@  discard block
 block discarded – undo
172 172
 
173 173
 }
174 174
 
175
-function wpinv_is_free_item( $item_id = 0 ) {
176
-    if( empty( $item_id ) ) {
175
+function wpinv_is_free_item($item_id = 0) {
176
+    if (empty($item_id)) {
177 177
         return false;
178 178
     }
179 179
 
180
-    $item = new WPInv_Item( $item_id );
180
+    $item = new WPInv_Item($item_id);
181 181
     
182 182
     return $item->is_free();
183 183
 }
184 184
 
185
-function wpinv_item_is_editable( $item = 0 ) {
186
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
185
+function wpinv_item_is_editable($item = 0) {
186
+    if (!empty($item) && is_a($item, 'WP_Post')) {
187 187
         $item = $item->ID;
188 188
     }
189 189
         
190
-    if ( empty( $item ) ) {
190
+    if (empty($item)) {
191 191
         return true;
192 192
     }
193 193
 
194
-    $item = new WPInv_Item( $item );
194
+    $item = new WPInv_Item($item);
195 195
     
196 196
     return (bool) $item->is_editable();
197 197
 }
198 198
 
199
-function wpinv_get_item_price( $item_id = 0 ) {
200
-    if( empty( $item_id ) ) {
199
+function wpinv_get_item_price($item_id = 0) {
200
+    if (empty($item_id)) {
201 201
         return false;
202 202
     }
203 203
 
204
-    $item = new WPInv_Item( $item_id );
204
+    $item = new WPInv_Item($item_id);
205 205
     
206 206
     return $item->get_price();
207 207
 }
208 208
 
209
-function wpinv_is_recurring_item( $item_id = 0 ) {
210
-    if( empty( $item_id ) ) {
209
+function wpinv_is_recurring_item($item_id = 0) {
210
+    if (empty($item_id)) {
211 211
         return false;
212 212
     }
213 213
 
214
-    $item = new WPInv_Item( $item_id );
214
+    $item = new WPInv_Item($item_id);
215 215
     
216 216
     return $item->is_recurring();
217 217
 }
218 218
 
219
-function wpinv_item_price( $item_id = 0 ) {
220
-    if( empty( $item_id ) ) {
219
+function wpinv_item_price($item_id = 0) {
220
+    if (empty($item_id)) {
221 221
         return false;
222 222
     }
223 223
 
224
-    $price = wpinv_get_item_price( $item_id );
225
-    $price = wpinv_price( wpinv_format_amount( $price ) );
224
+    $price = wpinv_get_item_price($item_id);
225
+    $price = wpinv_price(wpinv_format_amount($price));
226 226
     
227
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
227
+    return apply_filters('wpinv_item_price', $price, $item_id);
228 228
 }
229 229
 
230
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
231
-    if ( empty( $item_id ) ) {
230
+function wpinv_item_show_price($item_id = 0, $echo = true) {
231
+    if (empty($item_id)) {
232 232
         $item_id = get_the_ID();
233 233
     }
234 234
 
235
-    $price = wpinv_item_price( $item_id );
235
+    $price = wpinv_item_price($item_id);
236 236
 
237
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
237
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
238 238
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
239
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
239
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
240 240
 
241
-    if ( $echo ) {
241
+    if ($echo) {
242 242
         echo $formatted_price;
243 243
     } else {
244 244
         return $formatted_price;
245 245
     }
246 246
 }
247 247
 
248
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
249
-    if ( is_null( $amount_override ) ) {
250
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
248
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
249
+    if (is_null($amount_override)) {
250
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
251 251
     } else {
252 252
         $original_price = $amount_override;
253 253
     }
254 254
     
255 255
     $price = $original_price;
256 256
 
257
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
257
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
258 258
 }
259 259
 
260
-function wpinv_item_custom_singular_name( $item_id ) {
261
-    if( empty( $item_id ) ) {
260
+function wpinv_item_custom_singular_name($item_id) {
261
+    if (empty($item_id)) {
262 262
         return false;
263 263
     }
264 264
 
265
-    $item = new WPInv_Item( $item_id );
265
+    $item = new WPInv_Item($item_id);
266 266
     
267 267
     return $item->get_custom_singular_name();
268 268
 }
269 269
 
270 270
 function wpinv_get_item_types() {
271 271
     $item_types = array(
272
-            'custom'    => __( 'Standard', 'invoicing' ),
273
-            'fee'       => __( 'Fee', 'invoicing' ),
272
+            'custom'    => __('Standard', 'invoicing'),
273
+            'fee'       => __('Fee', 'invoicing'),
274 274
         );
275
-    return apply_filters( 'wpinv_get_item_types', $item_types );
275
+    return apply_filters('wpinv_get_item_types', $item_types);
276 276
 }
277 277
 
278 278
 function wpinv_item_types() {
279 279
     $item_types = wpinv_get_item_types();
280 280
     
281
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
281
+    return (!empty($item_types) ? array_keys($item_types) : array());
282 282
 }
283 283
 
284
-function wpinv_get_item_type( $item_id ) {
285
-    if( empty( $item_id ) ) {
284
+function wpinv_get_item_type($item_id) {
285
+    if (empty($item_id)) {
286 286
         return false;
287 287
     }
288 288
 
289
-    $item = new WPInv_Item( $item_id );
289
+    $item = new WPInv_Item($item_id);
290 290
     
291 291
     return $item->get_type();
292 292
 }
293 293
 
294
-function wpinv_item_type( $item_id ) {
294
+function wpinv_item_type($item_id) {
295 295
     $item_types = wpinv_get_item_types();
296 296
     
297
-    $item_type = wpinv_get_item_type( $item_id );
297
+    $item_type = wpinv_get_item_type($item_id);
298 298
     
299
-    if ( empty( $item_type ) ) {
299
+    if (empty($item_type)) {
300 300
         $item_type = '-';
301 301
     }
302 302
     
303
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
303
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
304 304
 
305
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
305
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
306 306
 }
307 307
 
308
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
308
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
309 309
     global $wpinv_logs;
310 310
     
311
-    if ( empty( $wpinv_logs ) ) {
311
+    if (empty($wpinv_logs)) {
312 312
         return false;
313 313
     }
314 314
 
@@ -317,264 +317,264 @@  discard block
 block discarded – undo
317 317
         'log_type'		=> 'wpi_item'
318 318
     );
319 319
 
320
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
320
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
321 321
 
322 322
     $log_meta = array(
323 323
         'user_info'	=> $user_info,
324 324
         'user_id'	=> $user_id,
325
-        'file_id'	=> (int)$file_id,
325
+        'file_id'	=> (int) $file_id,
326 326
         'ip'		=> $ip,
327 327
         'invoice_id'=> $invoice_id,
328 328
     );
329 329
 
330
-    $wpinv_logs->insert_log( $log_data, $log_meta );
330
+    $wpinv_logs->insert_log($log_data, $log_meta);
331 331
 }
332 332
 
333
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
334
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
333
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
334
+    if ('wpi_item' !== get_post_type($item_id))
335 335
         return;
336 336
 
337 337
     global $wpinv_logs;
338 338
     
339
-    if ( empty( $wpinv_logs ) ) {
339
+    if (empty($wpinv_logs)) {
340 340
         return false;
341 341
     }
342 342
 
343 343
     // Remove all log entries related to this item
344
-    $wpinv_logs->delete_logs( $item_id );
344
+    $wpinv_logs->delete_logs($item_id);
345 345
 }
346
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
346
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
347 347
 
348
-function wpinv_get_random_item( $post_ids = true ) {
349
-    wpinv_get_random_items( 1, $post_ids );
348
+function wpinv_get_random_item($post_ids = true) {
349
+    wpinv_get_random_items(1, $post_ids);
350 350
 }
351 351
 
352
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
353
-    if ( $post_ids ) {
354
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
352
+function wpinv_get_random_items($num = 3, $post_ids = true) {
353
+    if ($post_ids) {
354
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
355 355
     } else {
356
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
356
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
357 357
     }
358 358
     
359
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
359
+    $args = apply_filters('wpinv_get_random_items', $args);
360 360
     
361
-    return get_posts( $args );
361
+    return get_posts($args);
362 362
 }
363 363
 
364
-function wpinv_get_item_token( $url = '' ) {
364
+function wpinv_get_item_token($url = '') {
365 365
     $args    = array();
366
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
367
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
366
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
367
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
368 368
 
369
-    $parts   = parse_url( $url );
369
+    $parts   = parse_url($url);
370 370
     $options = array();
371 371
 
372
-    if ( isset( $parts['query'] ) ) {
373
-        wp_parse_str( $parts['query'], $query_args );
372
+    if (isset($parts['query'])) {
373
+        wp_parse_str($parts['query'], $query_args);
374 374
 
375
-        if ( ! empty( $query_args['o'] ) ) {
376
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
375
+        if (!empty($query_args['o'])) {
376
+            $options = explode(':', rawurldecode($query_args['o']));
377 377
 
378
-            if ( in_array( 'ip', $options ) ) {
378
+            if (in_array('ip', $options)) {
379 379
                 $args['ip'] = wpinv_get_ip();
380 380
             }
381 381
 
382
-            if ( in_array( 'ua', $options ) ) {
382
+            if (in_array('ua', $options)) {
383 383
                 $ua = wpinv_get_user_agent();
384
-                $args['user_agent'] = rawurlencode( $ua );
384
+                $args['user_agent'] = rawurlencode($ua);
385 385
             }
386 386
         }
387 387
     }
388 388
 
389
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
389
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
390 390
 
391 391
     $args['secret'] = $secret;
392 392
     $args['token']  = false;
393 393
 
394
-    $url   = add_query_arg( $args, $url );
395
-    $parts = parse_url( $url );
394
+    $url   = add_query_arg($args, $url);
395
+    $parts = parse_url($url);
396 396
 
397
-    if ( ! isset( $parts['path'] ) ) {
397
+    if (!isset($parts['path'])) {
398 398
         $parts['path'] = '';
399 399
     }
400 400
 
401
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
401
+    $token = md5($parts['path'] . '?' . $parts['query']);
402 402
 
403 403
     return $token;
404 404
 }
405 405
 
406
-function wpinv_validate_url_token( $url = '' ) {
406
+function wpinv_validate_url_token($url = '') {
407 407
     $ret   = false;
408
-    $parts = parse_url( $url );
408
+    $parts = parse_url($url);
409 409
 
410
-    if ( isset( $parts['query'] ) ) {
411
-        wp_parse_str( $parts['query'], $query_args );
410
+    if (isset($parts['query'])) {
411
+        wp_parse_str($parts['query'], $query_args);
412 412
 
413
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
413
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
414 414
             'item',
415 415
             'ttl',
416 416
             'token'
417
-        ) );
417
+        ));
418 418
 
419 419
         $remove = array();
420 420
 
421
-        foreach( $query_args as $key => $value ) {
422
-            if( false === in_array( $key, $allowed ) ) {
421
+        foreach ($query_args as $key => $value) {
422
+            if (false === in_array($key, $allowed)) {
423 423
                 $remove[] = $key;
424 424
             }
425 425
         }
426 426
 
427
-        if( ! empty( $remove ) ) {
428
-            $url = remove_query_arg( $remove, $url );
427
+        if (!empty($remove)) {
428
+            $url = remove_query_arg($remove, $url);
429 429
         }
430 430
 
431
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
432
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
431
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
432
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
433 433
         }
434 434
 
435
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
435
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
436 436
             $ret = true;
437 437
         }
438 438
 
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
441
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
442 442
 }
443 443
 
444
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
444
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
445 445
     $cart_items = wpinv_get_cart_contents();
446 446
 
447 447
     $ret = false;
448 448
 
449
-    if ( is_array( $cart_items ) ) {
450
-        foreach ( $cart_items as $item ) {
451
-            if ( $item['id'] == $item_id ) {
449
+    if (is_array($cart_items)) {
450
+        foreach ($cart_items as $item) {
451
+            if ($item['id'] == $item_id) {
452 452
                 $ret = true;
453 453
                 break;
454 454
             }
455 455
         }
456 456
     }
457 457
 
458
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
458
+    return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
459 459
 }
460 460
 
461
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
461
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
462 462
     $tax = 0;
463
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
464
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
465
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
463
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
464
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
465
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
466 466
 
467
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
467
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
468 468
     }
469 469
 
470
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
470
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
471 471
 }
472 472
 
473
-function wpinv_cart_item_price( $item ) {
474
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
475
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
476
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
473
+function wpinv_cart_item_price($item) {
474
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
475
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
476
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
477 477
     
478
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
479
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
478
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
479
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
480 480
             $price += $tax;
481 481
         }
482 482
         
483
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
483
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
484 484
             $price -= $tax;
485 485
         }        
486 486
     }
487 487
 
488
-    $price = wpinv_price( wpinv_format_amount( $price ) );
488
+    $price = wpinv_price(wpinv_format_amount($price));
489 489
 
490
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
490
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
491 491
 }
492 492
 
493
-function wpinv_cart_item_subtotal( $item ) {
494
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
495
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
493
+function wpinv_cart_item_subtotal($item) {
494
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
495
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
496 496
 
497
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
497
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
498 498
 }
499 499
 
500
-function wpinv_cart_item_tax( $item ) {
500
+function wpinv_cart_item_tax($item) {
501 501
     $tax        = '';
502 502
     $tax_rate   = '';
503 503
     
504
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
505
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
506
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
507
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
504
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
505
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
506
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
507
+        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
508 508
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
509 509
     }
510 510
     
511
-    $tax        = $tax . $tax_rate;
511
+    $tax = $tax . $tax_rate;
512 512
     
513
-    if ( $tax === '' ) {
513
+    if ($tax === '') {
514 514
         $tax = 0; // Zero tax
515 515
     }
516 516
 
517
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
517
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
518 518
 }
519 519
 
520
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
520
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
521 521
     $price = 0;
522 522
     
523 523
     // Set custom price
524
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
524
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
525 525
         $price = $cart_item['custom_price'];
526 526
     } else {
527
-        $variable_prices = wpinv_has_variable_prices( $item_id );
527
+        $variable_prices = wpinv_has_variable_prices($item_id);
528 528
 
529
-        if ( $variable_prices ) {
530
-            $prices = wpinv_get_variable_prices( $item_id );
529
+        if ($variable_prices) {
530
+            $prices = wpinv_get_variable_prices($item_id);
531 531
 
532
-            if ( $prices ) {
533
-                if( ! empty( $options ) ) {
534
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
532
+            if ($prices) {
533
+                if (!empty($options)) {
534
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
535 535
                 } else {
536 536
                     $price = false;
537 537
                 }
538 538
             }
539 539
         }
540 540
 
541
-        if( ! $variable_prices || false === $price ) {
542
-            if($cart_item['item_price'] > 0){
541
+        if (!$variable_prices || false === $price) {
542
+            if ($cart_item['item_price'] > 0) {
543 543
                 $price = $cart_item['item_price'];
544 544
             } else {
545 545
                 // Get the standard Item price if not using variable prices
546
-                $price = wpinv_get_item_price( $item_id );
546
+                $price = wpinv_get_item_price($item_id);
547 547
             }
548 548
         }
549 549
     }
550 550
 
551
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
552
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
551
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
552
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
553 553
     }
554 554
 
555
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
555
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
556 556
 }
557 557
 
558
-function wpinv_get_cart_item_price_id( $item = array() ) {
559
-    if( isset( $item['item_number'] ) ) {
560
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
558
+function wpinv_get_cart_item_price_id($item = array()) {
559
+    if (isset($item['item_number'])) {
560
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
561 561
     } else {
562
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
562
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
563 563
     }
564 564
     return $price_id;
565 565
 }
566 566
 
567
-function wpinv_get_cart_item_price_name( $item = array() ) {
568
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
569
-    $prices   = wpinv_get_variable_prices( $item['id'] );
570
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
571
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
567
+function wpinv_get_cart_item_price_name($item = array()) {
568
+    $price_id = (int) wpinv_get_cart_item_price_id($item);
569
+    $prices   = wpinv_get_variable_prices($item['id']);
570
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
571
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
572 572
 }
573 573
 
574
-function wpinv_get_cart_item_name( $item = array() ) {
575
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
574
+function wpinv_get_cart_item_name($item = array()) {
575
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
576 576
 
577
-    if ( empty( $item_title ) ) {
577
+    if (empty($item_title)) {
578 578
         $item_title = $item['id'];
579 579
     }
580 580
 
@@ -584,23 +584,23 @@  discard block
 block discarded – undo
584 584
     }
585 585
     */
586 586
 
587
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
587
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
588 588
 }
589 589
 
590
-function wpinv_has_variable_prices( $item_id = 0 ) {
590
+function wpinv_has_variable_prices($item_id = 0) {
591 591
     return false;
592 592
 }
593 593
 
594
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
594
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
595 595
     $cart_items = wpinv_get_cart_contents();
596 596
 
597
-    if ( !is_array( $cart_items ) ) {
597
+    if (!is_array($cart_items)) {
598 598
         return false; // Empty cart
599 599
     } else {
600
-        foreach ( $cart_items as $position => $item ) {
601
-            if ( $item['id'] == $item_id ) {
602
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
603
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
600
+        foreach ($cart_items as $position => $item) {
601
+            if ($item['id'] == $item_id) {
602
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
603
+                    if ((int) $options['price_id'] == (int) $item['options']['price_id']) {
604 604
                         return $position;
605 605
                     }
606 606
                 } else {
@@ -613,80 +613,80 @@  discard block
 block discarded – undo
613 613
     return false; // Not found
614 614
 }
615 615
 
616
-function wpinv_get_cart_item_quantity( $item ) {
617
-    if ( wpinv_item_quantities_enabled() ) {
618
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
616
+function wpinv_get_cart_item_quantity($item) {
617
+    if (wpinv_item_quantities_enabled()) {
618
+        $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1;
619 619
     } else {
620 620
         $quantity = 1;
621 621
     }
622 622
     
623
-    if ( $quantity < 1 ) {
623
+    if ($quantity < 1) {
624 624
         $quantity = 1;
625 625
     }
626 626
     
627
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
627
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
628 628
 }
629 629
 
630
-function wpinv_get_item_suffix( $item, $html = true ) {
631
-    if ( empty( $item ) ) {
630
+function wpinv_get_item_suffix($item, $html = true) {
631
+    if (empty($item)) {
632 632
         return NULL;
633 633
     }
634 634
     
635
-    if ( is_int( $item ) ) {
636
-        $item = new WPInv_Item( $item );
635
+    if (is_int($item)) {
636
+        $item = new WPInv_Item($item);
637 637
     }
638 638
     
639
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
639
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
640 640
         return NULL;
641 641
     }
642 642
     
643
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
643
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
644 644
     
645
-    if ( !$html && $suffix ) {
646
-        $suffix = strip_tags( $suffix );
645
+    if (!$html && $suffix) {
646
+        $suffix = strip_tags($suffix);
647 647
     }
648 648
     
649
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
649
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
650 650
 }
651 651
 
652
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
653
-    if ( empty( $item ) ) {
652
+function wpinv_remove_item($item = 0, $force_delete = false) {
653
+    if (empty($item)) {
654 654
         return NULL;
655 655
     }
656 656
     
657
-    if ( is_int( $item ) ) {
658
-        $item = new WPInv_Item( $item );
657
+    if (is_int($item)) {
658
+        $item = new WPInv_Item($item);
659 659
     }
660 660
     
661
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
661
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
662 662
         return NULL;
663 663
     }
664 664
     
665
-    do_action( 'wpinv_pre_delete_item', $item );
665
+    do_action('wpinv_pre_delete_item', $item);
666 666
 
667
-    wp_delete_post( $item->ID, $force_delete );
667
+    wp_delete_post($item->ID, $force_delete);
668 668
 
669
-    do_action( 'wpinv_post_delete_item', $item );
669
+    do_action('wpinv_post_delete_item', $item);
670 670
 }
671 671
 
672
-function wpinv_can_delete_item( $post_id ) {
672
+function wpinv_can_delete_item($post_id) {
673 673
     $return = wpinv_current_user_can_manage_invoicing() ? true : false;
674 674
     
675
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
675
+    if ($return && wpinv_item_in_use($post_id)) {
676 676
         $return = false; // Don't delete item already use in invoices.
677 677
     }
678 678
     
679
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
679
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
680 680
 }
681 681
 
682 682
 function wpinv_admin_action_delete() {
683 683
     $screen = get_current_screen();
684 684
     
685
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
685
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
686 686
         $post_ids = array();
687 687
         
688
-        foreach ( $_REQUEST['post'] as $post_id ) {
689
-            if ( !wpinv_can_delete_item( $post_id ) ) {
688
+        foreach ($_REQUEST['post'] as $post_id) {
689
+            if (!wpinv_can_delete_item($post_id)) {
690 690
                 continue;
691 691
             }
692 692
             
@@ -696,88 +696,88 @@  discard block
 block discarded – undo
696 696
         $_REQUEST['post'] = $post_ids;
697 697
     }
698 698
 }
699
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
700
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
699
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
700
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
701 701
 
702
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
703
-    if ( $post->post_type == 'wpi_item' ) {
704
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
702
+function wpinv_check_delete_item($check, $post, $force_delete) {
703
+    if ($post->post_type == 'wpi_item') {
704
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
705 705
             return true;
706 706
         }
707 707
     }
708 708
     
709 709
     return $check;
710 710
 }
711
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
711
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
712 712
 
713
-function wpinv_item_in_use( $item_id ) {
713
+function wpinv_item_in_use($item_id) {
714 714
     global $wpdb, $wpi_items_in_use;
715 715
     
716
-    if ( !$item_id > 0 ) {
716
+    if (!$item_id > 0) {
717 717
         return false;
718 718
     }
719 719
     
720
-    if ( !empty( $wpi_items_in_use ) ) {
721
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
720
+    if (!empty($wpi_items_in_use)) {
721
+        if (isset($wpi_items_in_use[$item_id])) {
722 722
             return $wpi_items_in_use[$item_id];
723 723
         }
724 724
     } else {
725 725
         $wpi_items_in_use = array();
726 726
     }
727 727
     
728
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true, true ) );
728
+    $statuses = array_keys(wpinv_get_invoice_statuses(true, true));
729 729
     
730
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
731
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
730
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )";
731
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
732 732
     
733 733
     $wpi_items_in_use[$item_id] = $in_use;
734 734
     
735 735
     return $in_use;
736 736
 }
737 737
 
738
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
738
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
739 739
     // Set some defaults
740 740
     $defaults = array(
741
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
742
-        'title'                => '',                                                      // Required. Item title.
743
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
744
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
745
-        'status'               => 'pending',                                               // Optional. pending, publish
746
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
747
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
748
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
749
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
750
-        'excerpt'              => '',                                                      // Optional. Item short description
741
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
742
+        'title'                => '', // Required. Item title.
743
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
744
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
745
+        'status'               => 'pending', // Optional. pending, publish
746
+        'custom_name'          => '', // Optional. Plural sub title for item.
747
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
748
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
749
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
750
+        'excerpt'              => '', // Optional. Item short description
751 751
         /* Recurring item fields */
752
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
753
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
754
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
755
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
756
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
757
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
758
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
759
-        'minimum_price'        => '0.00',                                                  // Optional. Minimum allowed prices for items with dynamic pricing.
760
-        'dynamic_pricing'      => 0,                                                       // Optional. Whether or not the item supports dynamic prices.
752
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
753
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
754
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
755
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
756
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
757
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
758
+        'trial_interval'       => 0, // Optional. Any integer number.
759
+        'minimum_price'        => '0.00', // Optional. Minimum allowed prices for items with dynamic pricing.
760
+        'dynamic_pricing'      => 0, // Optional. Whether or not the item supports dynamic prices.
761 761
     );
762 762
 
763
-    $data = wp_parse_args( $args, $defaults );
763
+    $data = wp_parse_args($args, $defaults);
764 764
 
765
-    if ( empty( $data['type'] ) ) {
765
+    if (empty($data['type'])) {
766 766
         $data['type'] = 'custom';
767 767
     }
768 768
 
769
-    if ( !empty( $data['custom_id'] ) ) {
770
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
769
+    if (!empty($data['custom_id'])) {
770
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
771 771
     } else {
772 772
         $item = NULL;
773 773
     }
774 774
 
775
-    if ( !empty( $item ) ) {
776
-        if ( $force_update ) {
777
-            if ( empty( $args['ID'] ) ) {
775
+    if (!empty($item)) {
776
+        if ($force_update) {
777
+            if (empty($args['ID'])) {
778 778
                 $args['ID'] = $item->ID;
779 779
             }
780
-            return wpinv_update_item( $args, $wp_error );
780
+            return wpinv_update_item($args, $wp_error);
781 781
         }
782 782
 
783 783
         return $item;
@@ -788,21 +788,21 @@  discard block
 block discarded – undo
788 788
     $meta['custom_id']              = $data['custom_id'];
789 789
     $meta['custom_singular_name']   = $data['custom_singular_name'];
790 790
     $meta['custom_name']            = $data['custom_name'];
791
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
792
-    $meta['editable']               = (int)$data['editable'];
791
+    $meta['price']                  = wpinv_round_amount($data['price']);
792
+    $meta['editable']               = (int) $data['editable'];
793 793
     $meta['vat_rule']               = $data['vat_rule'];
794 794
     $meta['vat_class']              = '_standard';
795 795
     $meta['dynamic_pricing']        = (int) $data['dynamic_pricing'];
796
-    $meta['minimum_price']          = wpinv_round_amount( $data['minimum_price'] );
796
+    $meta['minimum_price']          = wpinv_round_amount($data['minimum_price']);
797 797
     
798
-    if ( !empty( $data['is_recurring'] ) ) {
798
+    if (!empty($data['is_recurring'])) {
799 799
         $meta['is_recurring']       = $data['is_recurring'];
800 800
         $meta['recurring_period']   = $data['recurring_period'];
801
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
802
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
801
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
802
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
803 803
         $meta['free_trial']         = $data['free_trial'];
804 804
         $meta['trial_period']       = $data['trial_period'];
805
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
805
+        $meta['trial_interval']     = absint($data['trial_interval']);
806 806
     } else {
807 807
         $meta['is_recurring']       = 0;
808 808
         $meta['recurring_period']   = '';
@@ -813,7 +813,7 @@  discard block
 block discarded – undo
813 813
         $meta['trial_interval']     = '';
814 814
     }
815 815
     
816
-    $post_data  = array( 
816
+    $post_data = array( 
817 817
         'post_title'    => $data['title'],
818 818
         'post_excerpt'  => $data['excerpt'],
819 819
         'post_status'   => $data['status'],
@@ -821,34 +821,34 @@  discard block
 block discarded – undo
821 821
     );
822 822
 
823 823
     $item = new WPInv_Item();
824
-    $return = $item->create( $post_data, $wp_error );
824
+    $return = $item->create($post_data, $wp_error);
825 825
 
826
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
826
+    if ($return && !empty($item) && !is_wp_error($return)) {
827 827
         return $item;
828 828
     }
829 829
 
830
-    if ( $wp_error && is_wp_error( $return ) ) {
830
+    if ($wp_error && is_wp_error($return)) {
831 831
         return $return;
832 832
     }
833 833
     return 0;
834 834
 }
835 835
 
836
-function wpinv_update_item( $args = array(), $wp_error = false ) {
837
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
836
+function wpinv_update_item($args = array(), $wp_error = false) {
837
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
838 838
 
839
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
840
-        if ( $wp_error ) {
841
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
839
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
840
+        if ($wp_error) {
841
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
842 842
         }
843 843
         return 0;
844 844
     }
845 845
     
846
-    if ( !empty( $args['custom_id'] ) ) {
847
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
846
+    if (!empty($args['custom_id'])) {
847
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
848 848
         
849
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
850
-            if ( $wp_error ) {
851
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
849
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
850
+            if ($wp_error) {
851
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
852 852
             }
853 853
             return 0;
854 854
         }
@@ -875,54 +875,54 @@  discard block
 block discarded – undo
875 875
     );
876 876
 
877 877
     $post_data = array();
878
-    if ( isset( $args['title'] ) ) { 
878
+    if (isset($args['title'])) { 
879 879
         $post_data['post_title'] = $args['title'];
880 880
     }
881
-    if ( isset( $args['excerpt'] ) ) { 
881
+    if (isset($args['excerpt'])) { 
882 882
         $post_data['post_excerpt'] = $args['excerpt'];
883 883
     }
884
-    if ( isset( $args['status'] ) ) { 
884
+    if (isset($args['status'])) { 
885 885
         $post_data['post_status'] = $args['status'];
886 886
     }
887 887
     
888
-    foreach ( $meta_fields as $meta_field ) {
889
-        if ( isset( $args[ $meta_field ] ) ) { 
890
-            $value = $args[ $meta_field ];
888
+    foreach ($meta_fields as $meta_field) {
889
+        if (isset($args[$meta_field])) { 
890
+            $value = $args[$meta_field];
891 891
 
892
-            switch ( $meta_field ) {
892
+            switch ($meta_field) {
893 893
                 case 'price':
894 894
                 case 'minimum_price':
895
-                    $value = wpinv_round_amount( $value );
895
+                    $value = wpinv_round_amount($value);
896 896
                 break;
897 897
                 case 'recurring_interval':
898 898
                 case 'recurring_limit':
899 899
                 case 'trial_interval':
900
-                    $value = absint( $value );
900
+                    $value = absint($value);
901 901
                 break;
902 902
 				case 'editable':
903 903
                     $value = (int) $value;
904 904
                 break;
905 905
             }
906 906
 
907
-            $post_data['meta'][ $meta_field ] = $value;
907
+            $post_data['meta'][$meta_field] = $value;
908 908
         };
909 909
     }
910 910
 
911
-    if ( empty( $post_data ) ) {
912
-        if ( $wp_error ) {
913
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
911
+    if (empty($post_data)) {
912
+        if ($wp_error) {
913
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
914 914
         }
915 915
         return 0;
916 916
     }
917 917
     $post_data['ID'] = $args['ID'];
918 918
 
919
-    $return = $item->update( $post_data, $wp_error );
919
+    $return = $item->update($post_data, $wp_error);
920 920
 
921
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
921
+    if ($return && !empty($item) && !is_wp_error($return)) {
922 922
         return $item;
923 923
     }
924 924
 
925
-    if ( $wp_error && is_wp_error( $return ) ) {
925
+    if ($wp_error && is_wp_error($return)) {
926 926
         return $return;
927 927
     }
928 928
     return 0;
Please login to merge, or discard this patch.
includes/wpinv-payment-functions.php 1 patch
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,155 +1,155 @@  discard block
 block discarded – undo
1 1
 <?php
2
-function wpinv_is_subscription_payment( $invoice = '' ) {
3
-    if ( empty( $invoice ) ) {
2
+function wpinv_is_subscription_payment($invoice = '') {
3
+    if (empty($invoice)) {
4 4
         return false;
5 5
     }
6 6
     
7
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
8
-        $invoice = wpinv_get_invoice( $invoice );
7
+    if (!is_object($invoice) && is_scalar($invoice)) {
8
+        $invoice = wpinv_get_invoice($invoice);
9 9
     }
10 10
     
11
-    if ( empty( $invoice ) ) {
11
+    if (empty($invoice)) {
12 12
         return false;
13 13
     }
14 14
         
15
-    if ( $invoice->is_renewal() ) {
15
+    if ($invoice->is_renewal()) {
16 16
         return true;
17 17
     }
18 18
 
19 19
     return false;
20 20
 }
21 21
 
22
-function wpinv_payment_link_transaction_id( $invoice = '' ) {
23
-    if ( empty( $invoice ) ) {
22
+function wpinv_payment_link_transaction_id($invoice = '') {
23
+    if (empty($invoice)) {
24 24
         return false;
25 25
     }
26 26
     
27
-    if ( !is_object( $invoice ) && is_scalar( $invoice ) ) {
28
-        $invoice = wpinv_get_invoice( $invoice );
27
+    if (!is_object($invoice) && is_scalar($invoice)) {
28
+        $invoice = wpinv_get_invoice($invoice);
29 29
     }
30 30
     
31
-    if ( empty( $invoice ) ) {
31
+    if (empty($invoice)) {
32 32
         return false;
33 33
     }
34 34
 
35
-    return apply_filters( 'wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice );
35
+    return apply_filters('wpinv_payment_details_transaction_id-' . $invoice->gateway, $invoice->get_transaction_id(), $invoice->ID, $invoice);
36 36
 }
37 37
 
38
-function wpinv_subscription_initial_payment_desc( $amount, $period, $interval, $trial_period = '', $trial_interval = 0 ) {
39
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
38
+function wpinv_subscription_initial_payment_desc($amount, $period, $interval, $trial_period = '', $trial_interval = 0) {
39
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
40 40
     
41
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
42
-        $amount = __( 'Free', 'invoicing' );
41
+    if ($trial_interval > 0 && !empty($trial_period)) {
42
+        $amount = __('Free', 'invoicing');
43 43
         $interval = $trial_interval;
44 44
         $period = $trial_period;
45 45
     }
46 46
     
47 47
     $description = '';
48
-    switch ( $period ) {
48
+    switch ($period) {
49 49
         case 'D' :
50 50
         case 'day' :
51
-            $description = wp_sprintf( _n( '%s for the first day.', '%s for the first %d days.', $interval, 'invoicing' ), $amount, $interval );
51
+            $description = wp_sprintf(_n('%s for the first day.', '%s for the first %d days.', $interval, 'invoicing'), $amount, $interval);
52 52
             break;
53 53
         case 'W' :
54 54
         case 'week' :
55
-            $description = wp_sprintf( _n( '%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing' ), $amount, $interval );
55
+            $description = wp_sprintf(_n('%s for the first week.', '%s for the first %d weeks.', $interval, 'invoicing'), $amount, $interval);
56 56
             break;
57 57
         case 'M' :
58 58
         case 'month' :
59
-            $description = wp_sprintf( _n( '%s for the first month.', '%s for the first %d months.', $interval, 'invoicing' ), $amount, $interval );
59
+            $description = wp_sprintf(_n('%s for the first month.', '%s for the first %d months.', $interval, 'invoicing'), $amount, $interval);
60 60
             break;
61 61
         case 'Y' :
62 62
         case 'year' :
63
-            $description = wp_sprintf( _n( '%s for the first year.', '%s for the first %d years.', $interval, 'invoicing' ), $amount, $interval );
63
+            $description = wp_sprintf(_n('%s for the first year.', '%s for the first %d years.', $interval, 'invoicing'), $amount, $interval);
64 64
             break;
65 65
     }
66 66
 
67
-    return apply_filters( 'wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval  );
67
+    return apply_filters('wpinv_subscription_initial_payment_desc', $description, $amount, $period, $interval, $trial_period, $trial_interval);
68 68
 }
69 69
 
70
-function wpinv_subscription_recurring_payment_desc( $amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0 ) {
71
-    $interval   = (int)$interval > 0 ? (int)$interval : 1;
72
-    $bill_times = (int)$bill_times > 0 ? (int)$bill_times : 0;
70
+function wpinv_subscription_recurring_payment_desc($amount, $period, $interval, $bill_times = 0, $trial_period = '', $trial_interval = 0) {
71
+    $interval   = (int) $interval > 0 ? (int) $interval : 1;
72
+    $bill_times = (int) $bill_times > 0 ? (int) $bill_times : 0;
73 73
     
74 74
     $description = '';
75
-    switch ( $period ) {
75
+    switch ($period) {
76 76
         case 'D' :
77 77
         case 'day' :            
78
-            if ( (int)$bill_times > 0 ) {
79
-                if ( $interval > 1 ) {
80
-                    if ( $bill_times > 1 ) {
81
-                        $description = wp_sprintf( __( '%s for each %d days, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
78
+            if ((int) $bill_times > 0) {
79
+                if ($interval > 1) {
80
+                    if ($bill_times > 1) {
81
+                        $description = wp_sprintf(__('%s for each %d days, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
82 82
                     } else {
83
-                        $description = wp_sprintf( __( '%s for %d days.', 'invoicing' ), $amount, $interval );
83
+                        $description = wp_sprintf(__('%s for %d days.', 'invoicing'), $amount, $interval);
84 84
                     }
85 85
                 } else {
86
-                    $description = wp_sprintf( _n( '%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
86
+                    $description = wp_sprintf(_n('%s for one day.', '%s for each day, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
87 87
                 }
88 88
             } else {
89
-                $description = wp_sprintf( _n( '%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval );
89
+                $description = wp_sprintf(_n('%s for each day.', '%s for each %d days.', $interval, 'invoicing'), $amount, $interval);
90 90
             }
91 91
             break;
92 92
         case 'W' :
93 93
         case 'week' :            
94
-            if ( (int)$bill_times > 0 ) {
95
-                if ( $interval > 1 ) {
96
-                    if ( $bill_times > 1 ) {
97
-                        $description = wp_sprintf( __( '%s for each %d weeks, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
94
+            if ((int) $bill_times > 0) {
95
+                if ($interval > 1) {
96
+                    if ($bill_times > 1) {
97
+                        $description = wp_sprintf(__('%s for each %d weeks, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
98 98
                     } else {
99
-                        $description = wp_sprintf( __( '%s for %d weeks.', 'invoicing' ), $amount, $interval );
99
+                        $description = wp_sprintf(__('%s for %d weeks.', 'invoicing'), $amount, $interval);
100 100
                     }
101 101
                 } else {
102
-                    $description = wp_sprintf( _n( '%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
102
+                    $description = wp_sprintf(_n('%s for one week.', '%s for each week, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
103 103
                 }
104 104
             } else {
105
-                $description = wp_sprintf( _n( '%s for each week.', '%s for each %d weeks.', $interval, 'invoicing' ), $amount, $interval );
105
+                $description = wp_sprintf(_n('%s for each week.', '%s for each %d weeks.', $interval, 'invoicing'), $amount, $interval);
106 106
             }
107 107
             break;
108 108
         case 'M' :
109 109
         case 'month' :            
110
-            if ( (int)$bill_times > 0 ) {
111
-                if ( $interval > 1 ) {
112
-                    if ( $bill_times > 1 ) {
113
-                        $description = wp_sprintf( __( '%s for each %d months, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
110
+            if ((int) $bill_times > 0) {
111
+                if ($interval > 1) {
112
+                    if ($bill_times > 1) {
113
+                        $description = wp_sprintf(__('%s for each %d months, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
114 114
                     } else {
115
-                        $description = wp_sprintf( __( '%s for %d months.', 'invoicing' ), $amount, $interval );
115
+                        $description = wp_sprintf(__('%s for %d months.', 'invoicing'), $amount, $interval);
116 116
                     }
117 117
                 } else {
118
-                    $description = wp_sprintf( _n( '%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
118
+                    $description = wp_sprintf(_n('%s for one month.', '%s for each month, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
119 119
                 }
120 120
             } else {
121
-                $description = wp_sprintf( _n( '%s for each month.', '%s for each %d months.', $interval, 'invoicing' ), $amount, $interval );
121
+                $description = wp_sprintf(_n('%s for each month.', '%s for each %d months.', $interval, 'invoicing'), $amount, $interval);
122 122
             }
123 123
             break;
124 124
         case 'Y' :
125 125
         case 'year' :            
126
-            if ( (int)$bill_times > 0 ) {
127
-                if ( $interval > 1 ) {
128
-                    if ( $bill_times > 1 ) {
129
-                        $description = wp_sprintf( __( '%s for each %d years, for %d installments.', 'invoicing' ), $amount, $interval, $bill_times );
126
+            if ((int) $bill_times > 0) {
127
+                if ($interval > 1) {
128
+                    if ($bill_times > 1) {
129
+                        $description = wp_sprintf(__('%s for each %d years, for %d installments.', 'invoicing'), $amount, $interval, $bill_times);
130 130
                     } else {
131
-                        $description = wp_sprintf( __( '%s for %d years.', 'invoicing'), $amount, $interval );
131
+                        $description = wp_sprintf(__('%s for %d years.', 'invoicing'), $amount, $interval);
132 132
                     }
133 133
                 } else {
134
-                    $description = wp_sprintf( _n( '%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing' ), $amount, $bill_times );
134
+                    $description = wp_sprintf(_n('%s for one year.', '%s for each year, for %d installments.', $bill_times, 'invoicing'), $amount, $bill_times);
135 135
                 }
136 136
             } else {
137
-                $description = wp_sprintf( _n( '%s for each year.', '%s for each %d years.', $interval, 'invoicing' ), $amount, $interval );
137
+                $description = wp_sprintf(_n('%s for each year.', '%s for each %d years.', $interval, 'invoicing'), $amount, $interval);
138 138
             }
139 139
             break;
140 140
     }
141 141
 
142
-    return apply_filters( 'wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
142
+    return apply_filters('wpinv_subscription_recurring_payment_desc', $description, $amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
143 143
 }
144 144
 
145
-function wpinv_subscription_payment_desc( $invoice ) {
146
-    if ( empty( $invoice ) ) {
145
+function wpinv_subscription_payment_desc($invoice) {
146
+    if (empty($invoice)) {
147 147
         return NULL;
148 148
     }
149 149
     
150 150
     $description = '';
151
-    if ( $invoice->is_parent() && $item = $invoice->get_recurring( true ) ) {
152
-        if ( $item->has_free_trial() ) {
151
+    if ($invoice->is_parent() && $item = $invoice->get_recurring(true)) {
152
+        if ($item->has_free_trial()) {
153 153
             $trial_period = $item->get_trial_period();
154 154
             $trial_interval = $item->get_trial_interval();
155 155
         } else {
@@ -157,45 +157,45 @@  discard block
 block discarded – undo
157 157
             $trial_interval = 0;
158 158
         }
159 159
         
160
-        $description = wpinv_get_billing_cycle( $invoice->get_total(), $invoice->get_recurring_details( 'total' ), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency() );
160
+        $description = wpinv_get_billing_cycle($invoice->get_total(), $invoice->get_recurring_details('total'), $item->get_recurring_period(), $item->get_recurring_interval(), $item->get_recurring_limit(), $trial_period, $trial_interval, $invoice->get_currency());
161 161
     }
162 162
     
163
-    return apply_filters( 'wpinv_subscription_payment_desc', $description, $invoice );
163
+    return apply_filters('wpinv_subscription_payment_desc', $description, $invoice);
164 164
 }
165 165
 
166
-function wpinv_get_billing_cycle( $initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '' ) {
167
-    $initial_total      = wpinv_round_amount( $initial );
168
-    $recurring_total    = wpinv_round_amount( $recurring );
166
+function wpinv_get_billing_cycle($initial, $recurring, $period, $interval, $bill_times, $trial_period = '', $trial_interval = 0, $currency = '') {
167
+    $initial_total      = wpinv_round_amount($initial);
168
+    $recurring_total    = wpinv_round_amount($recurring);
169 169
     
170
-    if ( $trial_interval > 0 && !empty( $trial_period ) ) {
170
+    if ($trial_interval > 0 && !empty($trial_period)) {
171 171
         // Free trial
172 172
     } else {
173
-        if ( $bill_times == 1 ) {
173
+        if ($bill_times == 1) {
174 174
             $recurring_total = $initial_total;
175
-        } else if ( $bill_times > 1 && $initial_total != $recurring_total ) {
175
+        } else if ($bill_times > 1 && $initial_total != $recurring_total) {
176 176
             $bill_times--;
177 177
         }
178 178
     }
179 179
     
180
-    $initial_amount     = wpinv_price( wpinv_format_amount( $initial_total ), $currency );
181
-    $recurring_amount   = wpinv_price( wpinv_format_amount( $recurring_total ), $currency );
180
+    $initial_amount     = wpinv_price(wpinv_format_amount($initial_total), $currency);
181
+    $recurring_amount   = wpinv_price(wpinv_format_amount($recurring_total), $currency);
182 182
     
183
-    $recurring          = wpinv_subscription_recurring_payment_desc( $recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval );
183
+    $recurring          = wpinv_subscription_recurring_payment_desc($recurring_amount, $period, $interval, $bill_times, $trial_period, $trial_interval);
184 184
         
185
-    if ( $initial_total != $recurring_total ) {
186
-        $initial        = wpinv_subscription_initial_payment_desc( $initial_amount, $period, $interval, $trial_period, $trial_interval );
185
+    if ($initial_total != $recurring_total) {
186
+        $initial        = wpinv_subscription_initial_payment_desc($initial_amount, $period, $interval, $trial_period, $trial_interval);
187 187
         
188
-        $description    = wp_sprintf( __( '%s Then %s', 'invoicing' ), $initial, $recurring );
188
+        $description    = wp_sprintf(__('%s Then %s', 'invoicing'), $initial, $recurring);
189 189
     } else {
190 190
         $description    = $recurring;
191 191
     }
192 192
     
193
-    return apply_filters( 'wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency );
193
+    return apply_filters('wpinv_get_billing_cycle', $description, $initial, $recurring, $period, $interval, $bill_times, $trial_period, $trial_interval, $currency);
194 194
 }
195 195
 
196
-function wpinv_recurring_send_payment_failed( $invoice ) {
197
-    if ( !empty( $invoice->ID ) ) {
198
-        wpinv_failed_invoice_notification( $invoice->ID );
196
+function wpinv_recurring_send_payment_failed($invoice) {
197
+    if (!empty($invoice->ID)) {
198
+        wpinv_failed_invoice_notification($invoice->ID);
199 199
     }
200 200
 }
201
-add_action( 'wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1 );
202 201
\ No newline at end of file
202
+add_action('wpinv_recurring_payment_failed', 'wpinv_recurring_send_payment_failed', 10, 1);
203 203
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Spacing   +133 added lines, -133 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_Item {
6 6
     public $ID = 0;
@@ -49,26 +49,26 @@  discard block
 block discarded – undo
49 49
     public $filter;
50 50
 
51 51
 
52
-    public function __construct( $_id = false, $_args = array() ) {
53
-        $item = WP_Post::get_instance( $_id );
54
-        return $this->setup_item( $item );
52
+    public function __construct($_id = false, $_args = array()) {
53
+        $item = WP_Post::get_instance($_id);
54
+        return $this->setup_item($item);
55 55
     }
56 56
 
57
-    private function setup_item( $item ) {
58
-        if( ! is_object( $item ) ) {
57
+    private function setup_item($item) {
58
+        if (!is_object($item)) {
59 59
             return false;
60 60
         }
61 61
 
62
-        if( ! is_a( $item, 'WP_Post' ) ) {
62
+        if (!is_a($item, 'WP_Post')) {
63 63
             return false;
64 64
         }
65 65
 
66
-        if( 'wpi_item' !== $item->post_type ) {
66
+        if ('wpi_item' !== $item->post_type) {
67 67
             return false;
68 68
         }
69 69
 
70
-        foreach ( $item as $key => $value ) {
71
-            switch ( $key ) {
70
+        foreach ($item as $key => $value) {
71
+            switch ($key) {
72 72
                 default:
73 73
                     $this->$key = $value;
74 74
                     break;
@@ -78,38 +78,38 @@  discard block
 block discarded – undo
78 78
         return true;
79 79
     }
80 80
 
81
-    public function __get( $key ) {
82
-        if ( method_exists( $this, 'get_' . $key ) ) {
83
-            return call_user_func( array( $this, 'get_' . $key ) );
81
+    public function __get($key) {
82
+        if (method_exists($this, 'get_' . $key)) {
83
+            return call_user_func(array($this, 'get_' . $key));
84 84
         } else {
85
-            return new WP_Error( 'wpinv-item-invalid-property', sprintf( __( 'Can\'t get property %s', 'invoicing' ), $key ) );
85
+            return new WP_Error('wpinv-item-invalid-property', sprintf(__('Can\'t get property %s', 'invoicing'), $key));
86 86
         }
87 87
     }
88 88
 
89
-    public function create( $data = array(), $wp_error = false ) {
90
-        if ( $this->ID != 0 ) {
89
+    public function create($data = array(), $wp_error = false) {
90
+        if ($this->ID != 0) {
91 91
             return false;
92 92
         }
93 93
 
94 94
         $defaults = array(
95 95
             'post_type'   => 'wpi_item',
96 96
             'post_status' => 'draft',
97
-            'post_title'  => __( 'New Invoice Item', 'invoicing' )
97
+            'post_title'  => __('New Invoice Item', 'invoicing')
98 98
         );
99 99
 
100
-        $args = wp_parse_args( $data, $defaults );
100
+        $args = wp_parse_args($data, $defaults);
101 101
 
102
-        do_action( 'wpinv_item_pre_create', $args );
102
+        do_action('wpinv_item_pre_create', $args);
103 103
 
104
-        $id = wp_insert_post( $args, $wp_error );
104
+        $id = wp_insert_post($args, $wp_error);
105 105
         if ($wp_error && is_wp_error($id)) {
106 106
             return $id;
107 107
         }
108
-        if ( !$id ) {
108
+        if (!$id) {
109 109
             return false;
110 110
         }
111 111
         
112
-        $item = WP_Post::get_instance( $id );
112
+        $item = WP_Post::get_instance($id);
113 113
         
114 114
         if (!empty($item) && !empty($data['meta'])) {
115 115
             $this->ID = $item->ID;
@@ -117,47 +117,47 @@  discard block
 block discarded – undo
117 117
         }
118 118
         
119 119
         // Set custom id if not set.
120
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
121
-            $this->save_metas( array( 'custom_id' => $id ) );
120
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
121
+            $this->save_metas(array('custom_id' => $id));
122 122
         }
123 123
 
124
-        do_action( 'wpinv_item_create', $id, $args );
124
+        do_action('wpinv_item_create', $id, $args);
125 125
 
126
-        return $this->setup_item( $item );
126
+        return $this->setup_item($item);
127 127
     }
128 128
     
129
-    public function update( $data = array(), $wp_error = false ) {
130
-        if ( !$this->ID > 0 ) {
129
+    public function update($data = array(), $wp_error = false) {
130
+        if (!$this->ID > 0) {
131 131
             return false;
132 132
         }
133 133
         
134 134
         $data['ID'] = $this->ID;
135 135
 
136
-        do_action( 'wpinv_item_pre_update', $data );
136
+        do_action('wpinv_item_pre_update', $data);
137 137
         
138
-        $id = wp_update_post( $data, $wp_error );
138
+        $id = wp_update_post($data, $wp_error);
139 139
         if ($wp_error && is_wp_error($id)) {
140 140
             return $id;
141 141
         }
142 142
         
143
-        if ( !$id ) {
143
+        if (!$id) {
144 144
             return false;
145 145
         }
146 146
 
147
-        $item = WP_Post::get_instance( $id );
147
+        $item = WP_Post::get_instance($id);
148 148
         if (!empty($item) && !empty($data['meta'])) {
149 149
             $this->ID = $item->ID;
150 150
             $this->save_metas($data['meta']);
151 151
         }
152 152
 
153 153
         // Set custom id if not set.
154
-        if ( empty( $data['meta']['custom_id'] ) && !$this->get_custom_id() ) {
155
-            $this->save_metas( array( 'custom_id' => $id ) );
154
+        if (empty($data['meta']['custom_id']) && !$this->get_custom_id()) {
155
+            $this->save_metas(array('custom_id' => $id));
156 156
         }
157 157
 
158
-        do_action( 'wpinv_item_update', $id, $data );
158
+        do_action('wpinv_item_update', $id, $data);
159 159
 
160
-        return $this->setup_item( $item );
160
+        return $this->setup_item($item);
161 161
     }
162 162
 
163 163
     public function get_ID() {
@@ -165,111 +165,111 @@  discard block
 block discarded – undo
165 165
     }
166 166
 
167 167
     public function get_name() {
168
-        return get_the_title( $this->ID );
168
+        return get_the_title($this->ID);
169 169
     }
170 170
     
171 171
     public function get_title() {
172
-        return get_the_title( $this->ID );
172
+        return get_the_title($this->ID);
173 173
     }
174 174
     
175 175
     public function get_status() {
176
-        return get_post_status( $this->ID );
176
+        return get_post_status($this->ID);
177 177
     }
178 178
     
179 179
     public function get_summary() {
180
-        $post = get_post( $this->ID );
181
-        return !empty( $post->post_excerpt ) ? $post->post_excerpt : '';
180
+        $post = get_post($this->ID);
181
+        return !empty($post->post_excerpt) ? $post->post_excerpt : '';
182 182
     }
183 183
 
184 184
     public function get_price() {
185
-        if ( ! isset( $this->price ) ) {
186
-            $this->price = get_post_meta( $this->ID, '_wpinv_price', true );
185
+        if (!isset($this->price)) {
186
+            $this->price = get_post_meta($this->ID, '_wpinv_price', true);
187 187
             
188
-            if ( $this->price ) {
189
-                $this->price = wpinv_sanitize_amount( $this->price );
188
+            if ($this->price) {
189
+                $this->price = wpinv_sanitize_amount($this->price);
190 190
             } else {
191 191
                 $this->price = 0;
192 192
             }
193 193
         }
194 194
         
195
-        return apply_filters( 'wpinv_get_item_price', $this->price, $this->ID );
195
+        return apply_filters('wpinv_get_item_price', $this->price, $this->ID);
196 196
     }
197 197
     
198 198
     public function get_vat_rule() {
199 199
         global $wpinv_euvat;
200 200
         
201
-        if( !isset( $this->vat_rule ) ) {
202
-            $this->vat_rule = get_post_meta( $this->ID, '_wpinv_vat_rule', true );
201
+        if (!isset($this->vat_rule)) {
202
+            $this->vat_rule = get_post_meta($this->ID, '_wpinv_vat_rule', true);
203 203
 
204
-            if ( empty( $this->vat_rule ) ) {        
204
+            if (empty($this->vat_rule)) {        
205 205
                 $this->vat_rule = $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
206 206
             }
207 207
         }
208 208
         
209
-        return apply_filters( 'wpinv_get_item_vat_rule', $this->vat_rule, $this->ID );
209
+        return apply_filters('wpinv_get_item_vat_rule', $this->vat_rule, $this->ID);
210 210
     }
211 211
     
212 212
     public function get_vat_class() {
213
-        if( !isset( $this->vat_class ) ) {
214
-            $this->vat_class = get_post_meta( $this->ID, '_wpinv_vat_class', true );
213
+        if (!isset($this->vat_class)) {
214
+            $this->vat_class = get_post_meta($this->ID, '_wpinv_vat_class', true);
215 215
 
216
-            if ( empty( $this->vat_class ) ) {        
216
+            if (empty($this->vat_class)) {        
217 217
                 $this->vat_class = '_standard';
218 218
             }
219 219
         }
220 220
         
221
-        return apply_filters( 'wpinv_get_item_vat_class', $this->vat_class, $this->ID );
221
+        return apply_filters('wpinv_get_item_vat_class', $this->vat_class, $this->ID);
222 222
     }
223 223
 
224 224
     public function get_type() {
225
-        if( ! isset( $this->type ) ) {
226
-            $this->type = get_post_meta( $this->ID, '_wpinv_type', true );
225
+        if (!isset($this->type)) {
226
+            $this->type = get_post_meta($this->ID, '_wpinv_type', true);
227 227
 
228
-            if ( empty( $this->type ) ) {
228
+            if (empty($this->type)) {
229 229
                 $this->type = 'custom';
230 230
             }
231 231
         }
232 232
 
233
-        return apply_filters( 'wpinv_get_item_type', $this->type, $this->ID );
233
+        return apply_filters('wpinv_get_item_type', $this->type, $this->ID);
234 234
     }
235 235
     
236 236
     public function get_custom_id() {
237
-        $custom_id = get_post_meta( $this->ID, '_wpinv_custom_id', true );
237
+        $custom_id = get_post_meta($this->ID, '_wpinv_custom_id', true);
238 238
 
239
-        return apply_filters( 'wpinv_get_item_custom_id', $custom_id, $this->ID );
239
+        return apply_filters('wpinv_get_item_custom_id', $custom_id, $this->ID);
240 240
     }
241 241
     
242 242
     public function get_custom_name() {
243
-        $custom_name = get_post_meta( $this->ID, '_wpinv_custom_name', true );
243
+        $custom_name = get_post_meta($this->ID, '_wpinv_custom_name', true);
244 244
 
245
-        return apply_filters( 'wpinv_get_item_custom_name', $custom_name, $this->ID );
245
+        return apply_filters('wpinv_get_item_custom_name', $custom_name, $this->ID);
246 246
     }
247 247
     
248 248
     public function get_custom_singular_name() {
249
-        $custom_singular_name = get_post_meta( $this->ID, '_wpinv_custom_singular_name', true );
249
+        $custom_singular_name = get_post_meta($this->ID, '_wpinv_custom_singular_name', true);
250 250
 
251
-        return apply_filters( 'wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID );
251
+        return apply_filters('wpinv_get_item_custom_singular_name', $custom_singular_name, $this->ID);
252 252
     }
253 253
     
254 254
     public function get_editable() {
255
-        $editable = get_post_meta( $this->ID, '_wpinv_editable', true );
255
+        $editable = get_post_meta($this->ID, '_wpinv_editable', true);
256 256
 
257
-        return apply_filters( 'wpinv_item_get_editable', $editable, $this->ID );
257
+        return apply_filters('wpinv_item_get_editable', $editable, $this->ID);
258 258
     }
259 259
     
260 260
     public function get_excerpt() {
261
-        $excerpt = get_the_excerpt( $this->ID );
261
+        $excerpt = get_the_excerpt($this->ID);
262 262
         
263
-        return apply_filters( 'wpinv_item_get_excerpt', $excerpt, $this->ID );
263
+        return apply_filters('wpinv_item_get_excerpt', $excerpt, $this->ID);
264 264
     }
265 265
     
266 266
     /**
267 267
      * Checks whether the item allows a user to set their own price
268 268
      */
269 269
     public function get_is_dynamic_pricing() {
270
-        $is_dynamic_pricing = get_post_meta( $this->ID, '_wpinv_dynamic_pricing', true );
270
+        $is_dynamic_pricing = get_post_meta($this->ID, '_wpinv_dynamic_pricing', true);
271 271
 
272
-        return (int) apply_filters( 'wpinv_item_get_is_dynamic_pricing', $is_dynamic_pricing, $this->ID );
272
+        return (int) apply_filters('wpinv_item_get_is_dynamic_pricing', $is_dynamic_pricing, $this->ID);
273 273
 
274 274
     }
275 275
 
@@ -279,32 +279,32 @@  discard block
 block discarded – undo
279 279
     public function get_minimum_price() {
280 280
 
281 281
         //Fetch the minimum price and cast it to a float
282
-        $price = (float) get_post_meta( $this->ID, '_minimum_price', true );
282
+        $price = (float) get_post_meta($this->ID, '_minimum_price', true);
283 283
             
284 284
         //Sanitize it
285
-        $price = wpinv_sanitize_amount( $price );
285
+        $price = wpinv_sanitize_amount($price);
286 286
 
287 287
         //Filter then return it
288
-        return apply_filters( 'wpinv_item_get_minimum_price', $price, $this->ID );
288
+        return apply_filters('wpinv_item_get_minimum_price', $price, $this->ID);
289 289
 
290 290
     }
291 291
 
292 292
     public function get_is_recurring() {
293
-        $is_recurring = get_post_meta( $this->ID, '_wpinv_is_recurring', true );
293
+        $is_recurring = get_post_meta($this->ID, '_wpinv_is_recurring', true);
294 294
 
295
-        return apply_filters( 'wpinv_item_get_is_recurring', $is_recurring, $this->ID );
295
+        return apply_filters('wpinv_item_get_is_recurring', $is_recurring, $this->ID);
296 296
 
297 297
     }
298 298
     
299
-    public function get_recurring_period( $full = false ) {
300
-        $period = get_post_meta( $this->ID, '_wpinv_recurring_period', true );
299
+    public function get_recurring_period($full = false) {
300
+        $period = get_post_meta($this->ID, '_wpinv_recurring_period', true);
301 301
         
302
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
302
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
303 303
             $period = 'D';
304 304
         }
305 305
         
306
-        if ( $full ) {
307
-            switch( $period ) {
306
+        if ($full) {
307
+            switch ($period) {
308 308
                 case 'D':
309 309
                     $period = 'day';
310 310
                 break;
@@ -320,40 +320,40 @@  discard block
 block discarded – undo
320 320
             }
321 321
         }
322 322
 
323
-        return apply_filters( 'wpinv_item_recurring_period', $period, $full, $this->ID );
323
+        return apply_filters('wpinv_item_recurring_period', $period, $full, $this->ID);
324 324
     }
325 325
     
326 326
     public function get_recurring_interval() {
327
-        $interval = (int)get_post_meta( $this->ID, '_wpinv_recurring_interval', true );
327
+        $interval = (int) get_post_meta($this->ID, '_wpinv_recurring_interval', true);
328 328
         
329
-        if ( !$interval > 0 ) {
329
+        if (!$interval > 0) {
330 330
             $interval = 1;
331 331
         }
332 332
 
333
-        return apply_filters( 'wpinv_item_recurring_interval', $interval, $this->ID );
333
+        return apply_filters('wpinv_item_recurring_interval', $interval, $this->ID);
334 334
     }
335 335
     
336 336
     public function get_recurring_limit() {
337
-        $limit = get_post_meta( $this->ID, '_wpinv_recurring_limit', true );
337
+        $limit = get_post_meta($this->ID, '_wpinv_recurring_limit', true);
338 338
 
339
-        return (int)apply_filters( 'wpinv_item_recurring_limit', $limit, $this->ID );
339
+        return (int) apply_filters('wpinv_item_recurring_limit', $limit, $this->ID);
340 340
     }
341 341
     
342 342
     public function get_free_trial() {
343
-        $free_trial = get_post_meta( $this->ID, '_wpinv_free_trial', true );
343
+        $free_trial = get_post_meta($this->ID, '_wpinv_free_trial', true);
344 344
 
345
-        return apply_filters( 'wpinv_item_get_free_trial', $free_trial, $this->ID );
345
+        return apply_filters('wpinv_item_get_free_trial', $free_trial, $this->ID);
346 346
     }
347 347
     
348
-    public function get_trial_period( $full = false ) {
349
-        $period = get_post_meta( $this->ID, '_wpinv_trial_period', true );
348
+    public function get_trial_period($full = false) {
349
+        $period = get_post_meta($this->ID, '_wpinv_trial_period', true);
350 350
         
351
-        if ( !in_array( $period, array( 'D', 'W', 'M', 'Y' ) ) ) {
351
+        if (!in_array($period, array('D', 'W', 'M', 'Y'))) {
352 352
             $period = 'D';
353 353
         }
354 354
         
355
-        if ( $full ) {
356
-            switch( $period ) {
355
+        if ($full) {
356
+            switch ($period) {
357 357
                 case 'D':
358 358
                     $period = 'day';
359 359
                 break;
@@ -369,47 +369,47 @@  discard block
 block discarded – undo
369 369
             }
370 370
         }
371 371
 
372
-        return apply_filters( 'wpinv_item_trial_period', $period, $full, $this->ID );
372
+        return apply_filters('wpinv_item_trial_period', $period, $full, $this->ID);
373 373
     }
374 374
     
375 375
     public function get_trial_interval() {
376
-        $interval = absint( get_post_meta( $this->ID, '_wpinv_trial_interval', true ) );
376
+        $interval = absint(get_post_meta($this->ID, '_wpinv_trial_interval', true));
377 377
         
378
-        if ( !$interval > 0 ) {
378
+        if (!$interval > 0) {
379 379
             $interval = 1;
380 380
         }
381 381
 
382
-        return apply_filters( 'wpinv_item_trial_interval', $interval, $this->ID );
382
+        return apply_filters('wpinv_item_trial_interval', $interval, $this->ID);
383 383
     }
384 384
     
385 385
     public function get_the_price() {
386
-        $item_price = wpinv_price( wpinv_format_amount( $this->get_price() ) );
386
+        $item_price = wpinv_price(wpinv_format_amount($this->get_price()));
387 387
         
388
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
388
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
389 389
     }
390 390
     
391 391
     public function is_recurring() {
392 392
         $is_recurring = $this->get_is_recurring();
393 393
 
394
-        return (bool)apply_filters( 'wpinv_is_recurring_item', $is_recurring, $this->ID );
394
+        return (bool) apply_filters('wpinv_is_recurring_item', $is_recurring, $this->ID);
395 395
     }
396 396
     
397 397
     public function has_free_trial() {
398 398
         $free_trial = $this->is_recurring() && $this->get_free_trial() ? true : false;
399 399
 
400
-        return (bool)apply_filters( 'wpinv_item_has_free_trial', $free_trial, $this->ID );
400
+        return (bool) apply_filters('wpinv_item_has_free_trial', $free_trial, $this->ID);
401 401
     }
402 402
 
403 403
     public function is_free() {
404 404
         $is_free = false;
405 405
         
406
-        $price = get_post_meta( $this->ID, '_wpinv_price', true );
406
+        $price = get_post_meta($this->ID, '_wpinv_price', true);
407 407
 
408
-        if ( (float)$price == 0 ) {
408
+        if ((float) $price == 0) {
409 409
             $is_free = true;
410 410
         }
411 411
 
412
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
412
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID);
413 413
 
414 414
     }
415 415
     
@@ -418,15 +418,15 @@  discard block
 block discarded – undo
418 418
 
419 419
         $is_editable = $editable === 0 || $editable === '0' ? false : true;
420 420
 
421
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
421
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID);
422 422
     }
423 423
     
424
-    public function save_metas( $metas = array() ) {
425
-        if ( empty( $metas ) ) {
424
+    public function save_metas($metas = array()) {
425
+        if (empty($metas)) {
426 426
             return false;
427 427
         }
428 428
         
429
-        foreach ( $metas as $meta_key => $meta_value ) {
429
+        foreach ($metas as $meta_key => $meta_value) {
430 430
             $meta_key = strpos($meta_key, '_wpinv_') !== 0 ? '_wpinv_' . $meta_key : $meta_key;
431 431
             
432 432
             $this->update_meta($meta_key, $meta_value);
@@ -435,77 +435,77 @@  discard block
 block discarded – undo
435 435
         return true;
436 436
     }
437 437
 
438
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
439
-        if ( empty( $meta_key ) ) {
438
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
439
+        if (empty($meta_key)) {
440 440
             return false;
441 441
         }
442 442
         
443
-        if( '_wpinv_minimum_price' === $meta_key ) {
443
+        if ('_wpinv_minimum_price' === $meta_key) {
444 444
             $meta_key = '_minimum_price';
445 445
         }
446 446
 
447
-        $meta_value = apply_filters( 'wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID );
447
+        $meta_value = apply_filters('wpinv_update_item_meta_' . $meta_key, $meta_value, $this->ID);
448 448
 
449
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
449
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
450 450
     }
451 451
     
452
-    public function get_fees( $type = 'fee', $item_id = 0 ) {
452
+    public function get_fees($type = 'fee', $item_id = 0) {
453 453
         global $wpi_session;
454 454
         
455
-        $fees = $wpi_session->get( 'wpi_cart_fees' );
455
+        $fees = $wpi_session->get('wpi_cart_fees');
456 456
 
457
-        if ( ! wpinv_get_cart_contents() ) {
457
+        if (!wpinv_get_cart_contents()) {
458 458
             // We can only get item type fees when the cart is empty
459 459
             $type = 'custom';
460 460
         }
461 461
 
462
-        if ( ! empty( $fees ) && ! empty( $type ) && 'all' !== $type ) {
463
-            foreach( $fees as $key => $fee ) {
464
-                if( ! empty( $fee['type'] ) && $type != $fee['type'] ) {
465
-                    unset( $fees[ $key ] );
462
+        if (!empty($fees) && !empty($type) && 'all' !== $type) {
463
+            foreach ($fees as $key => $fee) {
464
+                if (!empty($fee['type']) && $type != $fee['type']) {
465
+                    unset($fees[$key]);
466 466
                 }
467 467
             }
468 468
         }
469 469
 
470
-        if ( ! empty( $fees ) && ! empty( $item_id ) ) {
470
+        if (!empty($fees) && !empty($item_id)) {
471 471
             // Remove fees that don't belong to the specified Item
472
-            foreach ( $fees as $key => $fee ) {
473
-                if ( (int) $item_id !== (int)$fee['custom_id'] ) {
474
-                    unset( $fees[ $key ] );
472
+            foreach ($fees as $key => $fee) {
473
+                if ((int) $item_id !== (int) $fee['custom_id']) {
474
+                    unset($fees[$key]);
475 475
                 }
476 476
             }
477 477
         }
478 478
 
479
-        if ( ! empty( $fees ) ) {
479
+        if (!empty($fees)) {
480 480
             // Remove fees that belong to a specific item but are not in the cart
481
-            foreach( $fees as $key => $fee ) {
482
-                if( empty( $fee['custom_id'] ) ) {
481
+            foreach ($fees as $key => $fee) {
482
+                if (empty($fee['custom_id'])) {
483 483
                     continue;
484 484
                 }
485 485
 
486
-                if ( !wpinv_item_in_cart( $fee['custom_id'] ) ) {
487
-                    unset( $fees[ $key ] );
486
+                if (!wpinv_item_in_cart($fee['custom_id'])) {
487
+                    unset($fees[$key]);
488 488
                 }
489 489
             }
490 490
         }
491 491
 
492
-        return ! empty( $fees ) ? $fees : array();
492
+        return !empty($fees) ? $fees : array();
493 493
     }
494 494
     
495 495
     public function can_purchase() {
496 496
         $can_purchase = true;
497 497
 
498
-        if ( !current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
498
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
499 499
             $can_purchase = false;
500 500
         }
501 501
 
502
-        return (bool)apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
502
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
503 503
     }
504 504
 
505 505
     /**
506 506
      * Checks whether this item supports dynamic pricing or not
507 507
      */
508 508
     public function supports_dynamic_pricing() {
509
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
509
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
510 510
     }
511 511
 }
Please login to merge, or discard this patch.
includes/wpinv-user-functions.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) {
6
-    if ( empty( $user ) ) {
5
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC') {
6
+    if (empty($user)) {
7 7
         $user = get_current_user_id();
8 8
     }
9 9
 
10
-    if ( empty( $user ) ) {
10
+    if (empty($user)) {
11 11
         return false;
12 12
     }
13 13
 
14
-    $args = apply_filters( 'wpinv_get_users_invoices_args', array( 'user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order ) );
14
+    $args = apply_filters('wpinv_get_users_invoices_args', array('user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order));
15 15
     
16
-    return wpinv_get_invoices( $args );
16
+    return wpinv_get_invoices($args);
17 17
 }
18 18
 
19
-function wpinv_dropdown_users( $args = '' ) {
19
+function wpinv_dropdown_users($args = '') {
20 20
     $defaults = array(
21 21
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
22 22
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
         'option_none_value' => -1
28 28
     );
29 29
 
30
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
30
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
31 31
 
32
-    $r = wp_parse_args( $args, $defaults );
32
+    $r = wp_parse_args($args, $defaults);
33 33
 
34
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
34
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
35 35
 
36
-    $fields = array( 'ID', 'user_login', 'user_email' );
36
+    $fields = array('ID', 'user_login', 'user_email');
37 37
 
38
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
39
-    if ( 'display_name_with_login' === $show ) {
38
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
39
+    if ('display_name_with_login' === $show) {
40 40
         $fields[] = 'display_name';
41
-    } else if ( 'display_name_with_email' === $show ) {
41
+    } else if ('display_name_with_email' === $show) {
42 42
         $fields[] = 'display_name';
43 43
     } else {
44 44
         $fields[] = $show;
@@ -50,99 +50,99 @@  discard block
 block discarded – undo
50 50
     $show_option_none = $r['show_option_none'];
51 51
     $option_none_value = $r['option_none_value'];
52 52
 
53
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
53
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
54 54
 
55
-    $users = get_users( $query_args );
55
+    $users = get_users($query_args);
56 56
 
57 57
     $output = '';
58
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
59
-        $name = esc_attr( $r['name'] );
60
-        if ( $r['multi'] && ! $r['id'] ) {
58
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
59
+        $name = esc_attr($r['name']);
60
+        if ($r['multi'] && !$r['id']) {
61 61
             $id = '';
62 62
         } else {
63
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
63
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
64 64
         }
65 65
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
66 66
 
67
-        if ( $show_option_all ) {
67
+        if ($show_option_all) {
68 68
             $output .= "\t<option value='0'>$show_option_all</option>\n";
69 69
         }
70 70
 
71
-        if ( $show_option_none ) {
72
-            $_selected = selected( $option_none_value, $r['selected'], false );
73
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
71
+        if ($show_option_none) {
72
+            $_selected = selected($option_none_value, $r['selected'], false);
73
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
74 74
         }
75 75
 
76
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
76
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
77 77
             $found_selected = false;
78 78
             $r['selected'] = (int) $r['selected'];
79
-            foreach ( (array) $users as $user ) {
79
+            foreach ((array) $users as $user) {
80 80
                 $user->ID = (int) $user->ID;
81
-                if ( $user->ID === $r['selected'] ) {
81
+                if ($user->ID === $r['selected']) {
82 82
                     $found_selected = true;
83 83
                 }
84 84
             }
85 85
 
86
-            if ( ! $found_selected ) {
87
-                $users[] = get_userdata( $r['selected'] );
86
+            if (!$found_selected) {
87
+                $users[] = get_userdata($r['selected']);
88 88
             }
89 89
         }
90 90
 
91
-        foreach ( (array) $users as $user ) {
92
-            if ( 'display_name_with_login' === $show ) {
91
+        foreach ((array) $users as $user) {
92
+            if ('display_name_with_login' === $show) {
93 93
                 /* translators: 1: display name, 2: user_login */
94
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
95
-            } elseif ( 'display_name_with_email' === $show ) {
94
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
95
+            } elseif ('display_name_with_email' === $show) {
96 96
                 /* translators: 1: display name, 2: user_email */
97
-                if ( $user->display_name == $user->user_email ) {
97
+                if ($user->display_name == $user->user_email) {
98 98
                     $display = $user->display_name;
99 99
                 } else {
100
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
100
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
101 101
                 }
102
-            } elseif ( ! empty( $user->$show ) ) {
102
+            } elseif (!empty($user->$show)) {
103 103
                 $display = $user->$show;
104 104
             } else {
105 105
                 $display = '(' . $user->user_login . ')';
106 106
             }
107 107
 
108
-            $_selected = selected( $user->ID, $r['selected'], false );
109
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
108
+            $_selected = selected($user->ID, $r['selected'], false);
109
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
110 110
         }
111 111
 
112 112
         $output .= "</select>";
113 113
     }
114 114
 
115
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
115
+    $html = apply_filters('wpinv_dropdown_users', $output);
116 116
 
117
-    if ( $r['echo'] ) {
117
+    if ($r['echo']) {
118 118
         echo $html;
119 119
     }
120 120
     return $html;
121 121
 }
122 122
 
123
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
124
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
125
-        wpinv_login_user( $user_id );
123
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
124
+    if ((int) wpinv_get_option('guest_checkout') && $user_id > 0) {
125
+        wpinv_login_user($user_id);
126 126
     } else {
127
-        $redirect_to = wp_login_url( $redirect_to );
127
+        $redirect_to = wp_login_url($redirect_to);
128 128
     }
129 129
     
130
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
130
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
131 131
     
132
-    wp_redirect( $redirect_to );
132
+    wp_redirect($redirect_to);
133 133
 }
134 134
 
135
-function wpinv_login_user( $user_id ) {
136
-    if ( is_user_logged_in() ) {
135
+function wpinv_login_user($user_id) {
136
+    if (is_user_logged_in()) {
137 137
         return true;
138 138
     }
139 139
     
140
-    $user = get_user_by( 'id', $user_id );
140
+    $user = get_user_by('id', $user_id);
141 141
     
142
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
143
-        wp_set_current_user( $user_id, $user->user_login );
144
-        wp_set_auth_cookie( $user_id );
145
-        do_action( 'wp_login', $user->user_login );
142
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
143
+        wp_set_current_user($user_id, $user->user_login);
144
+        wp_set_auth_cookie($user_id);
145
+        do_action('wp_login', $user->user_login);
146 146
         
147 147
         return true;
148 148
     }
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
  * @return string capability to check against
158 158
  * @param string $capalibilty Optional. The alternative capability to check against.
159 159
  */
160
-function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
160
+function wpinv_get_capability($capalibilty = 'manage_invoicing') {
161 161
 
162
-	if ( current_user_can( 'manage_options' ) ) {
162
+	if (current_user_can('manage_options')) {
163 163
 		return 'manage_options';
164 164
 	};
165 165
 
@@ -173,5 +173,5 @@  discard block
 block discarded – undo
173 173
  * @return bool
174 174
  */
175 175
 function wpinv_current_user_can_manage_invoicing() {
176
-    return current_user_can( wpinv_get_capability() );
176
+    return current_user_can(wpinv_get_capability());
177 177
 }
178 178
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 1 patch
Spacing   +166 added lines, -166 removed lines patch added patch discarded remove patch
@@ -1,121 +1,121 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_use_taxes() {
8
-    $ret = wpinv_get_option( 'enable_taxes', false );
8
+    $ret = wpinv_get_option('enable_taxes', false);
9 9
     
10
-    return (bool) apply_filters( 'wpinv_use_taxes', $ret );
10
+    return (bool) apply_filters('wpinv_use_taxes', $ret);
11 11
 }
12 12
 
13 13
 function wpinv_get_tax_rates() {
14
-    $rates = get_option( 'wpinv_tax_rates', array() );
14
+    $rates = get_option('wpinv_tax_rates', array());
15 15
     
16
-    return apply_filters( 'wpinv_get_tax_rates', $rates );
16
+    return apply_filters('wpinv_get_tax_rates', $rates);
17 17
 }
18 18
 
19
-function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) {
19
+function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) {
20 20
     global $wpinv_euvat, $wpi_tax_rates, $wpi_userID;
21
-    $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array();
21
+    $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array();
22 22
     
23
-    if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) {
23
+    if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) {
24 24
         return $wpi_tax_rates[$item_id];
25 25
     }
26 26
     
27
-    if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) {
27
+    if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) {
28 28
         $wpi_tax_rates[$item_id] = 0;
29 29
         return 0;
30 30
     }
31 31
     
32 32
     $is_global = false;
33
-    if ( $item_id == 'global' ) {
33
+    if ($item_id == 'global') {
34 34
         $is_global = true;
35 35
         $item_id = 0;
36 36
     }
37 37
     
38
-    $rate           = (float)wpinv_get_option( 'tax_rate', 0 );
39
-    $user_address   = wpinv_get_user_address( $wpi_userID );
38
+    $rate           = (float) wpinv_get_option('tax_rate', 0);
39
+    $user_address   = wpinv_get_user_address($wpi_userID);
40 40
     
41
-    if( empty( $country ) ) {
42
-        if( !empty( $_POST['wpinv_country'] ) ) {
41
+    if (empty($country)) {
42
+        if (!empty($_POST['wpinv_country'])) {
43 43
             $country = $_POST['wpinv_country'];
44
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
44
+        } elseif (!empty($_POST['wpinv_country'])) {
45 45
             $country = $_POST['wpinv_country'];
46
-        } elseif( !empty( $_POST['country'] ) ) {
46
+        } elseif (!empty($_POST['country'])) {
47 47
             $country = $_POST['country'];
48
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
48
+        } elseif (is_user_logged_in() && !empty($user_address)) {
49 49
             $country = $user_address['country'];
50 50
         }
51
-        $country = !empty( $country ) ? $country : wpinv_get_default_country();
51
+        $country = !empty($country) ? $country : wpinv_get_default_country();
52 52
     }
53 53
 
54
-    if( empty( $state ) ) {
55
-        if( !empty( $_POST['wpinv_state'] ) ) {
54
+    if (empty($state)) {
55
+        if (!empty($_POST['wpinv_state'])) {
56 56
             $state = $_POST['wpinv_state'];
57
-        } elseif( !empty( $_POST['wpinv_state'] ) ) {
57
+        } elseif (!empty($_POST['wpinv_state'])) {
58 58
             $state = $_POST['wpinv_state'];
59
-        } elseif( !empty( $_POST['state'] ) ) {
59
+        } elseif (!empty($_POST['state'])) {
60 60
             $state = $_POST['state'];
61
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
61
+        } elseif (is_user_logged_in() && !empty($user_address)) {
62 62
             $state = $user_address['state'];
63 63
         }
64
-        $state = !empty( $state ) ? $state : wpinv_get_default_state();
64
+        $state = !empty($state) ? $state : wpinv_get_default_state();
65 65
     }
66 66
     
67
-    if( !empty( $country ) ) {
68
-        $tax_rates   = wpinv_get_tax_rates();
67
+    if (!empty($country)) {
68
+        $tax_rates = wpinv_get_tax_rates();
69 69
 
70
-        if( !empty( $tax_rates ) ) {
70
+        if (!empty($tax_rates)) {
71 71
             // Locate the tax rate for this country / state, if it exists
72
-            foreach( $tax_rates as $key => $tax_rate ) {
73
-                if( $country != $tax_rate['country'] )
72
+            foreach ($tax_rates as $key => $tax_rate) {
73
+                if ($country != $tax_rate['country'])
74 74
                     continue;
75 75
 
76
-                if( !empty( $tax_rate['global'] ) ) {
77
-                    if( !empty( $tax_rate['rate'] ) ) {
78
-                        $rate = number_format( $tax_rate['rate'], 4 );
76
+                if (!empty($tax_rate['global'])) {
77
+                    if (!empty($tax_rate['rate'])) {
78
+                        $rate = number_format($tax_rate['rate'], 4);
79 79
                     }
80 80
                 } else {
81 81
 
82
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
82
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
83 83
                         continue;
84 84
 
85 85
                     $state_rate = $tax_rate['rate'];
86
-                    if( 0 !== $state_rate || !empty( $state_rate ) ) {
87
-                        $rate = number_format( $state_rate, 4 );
86
+                    if (0 !== $state_rate || !empty($state_rate)) {
87
+                        $rate = number_format($state_rate, 4);
88 88
                     }
89 89
                 }
90 90
             }
91 91
         }
92 92
     }
93 93
     
94
-    $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id );
94
+    $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id);
95 95
     
96
-    if ( !empty( $item_id ) ) {
96
+    if (!empty($item_id)) {
97 97
         $wpi_tax_rates[$item_id] = $rate;
98
-    } else if ( $is_global ) {
98
+    } else if ($is_global) {
99 99
         $wpi_tax_rates['global'] = $rate;
100 100
     }
101 101
     
102 102
     return $rate;
103 103
 }
104 104
 
105
-function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) {
106
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
107
-    $rate = round( $rate, 4 );
105
+function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) {
106
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
107
+    $rate = round($rate, 4);
108 108
     $formatted = $rate .= '%';
109
-    return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id );
109
+    return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id);
110 110
 }
111 111
 
112
-function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) {
113
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
112
+function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) {
113
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
114 114
     $tax  = 0.00;
115 115
 
116
-    if ( wpinv_use_taxes() ) {        
117
-        if ( wpinv_prices_include_tax() ) {
118
-            $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) );
116
+    if (wpinv_use_taxes()) {        
117
+        if (wpinv_prices_include_tax()) {
118
+            $pre_tax = ($amount / ((1 + $rate) * 0.01));
119 119
             $tax     = $amount - $pre_tax;
120 120
         } else {
121 121
             $tax = $amount * $rate * 0.01;
@@ -123,46 +123,46 @@  discard block
 block discarded – undo
123 123
 
124 124
     }
125 125
 
126
-    return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id );
126
+    return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id);
127 127
 }
128 128
 
129 129
 function wpinv_prices_include_tax() {
130 130
     return false; // TODO
131
-    $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() );
131
+    $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes());
132 132
 
133
-    return apply_filters( 'wpinv_prices_include_tax', $ret );
133
+    return apply_filters('wpinv_prices_include_tax', $ret);
134 134
 }
135 135
 
136
-function wpinv_sales_tax_for_year( $year = null ) {
137
-    return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) );
136
+function wpinv_sales_tax_for_year($year = null) {
137
+    return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year)));
138 138
 }
139 139
 
140
-function wpinv_get_sales_tax_for_year( $year = null ) {
140
+function wpinv_get_sales_tax_for_year($year = null) {
141 141
     global $wpdb;
142 142
 
143 143
     // Start at zero
144 144
     $tax = 0;
145 145
 
146
-    if ( ! empty( $year ) ) {
146
+    if (!empty($year)) {
147 147
         $args = array(
148 148
             'post_type'      => 'wpi_invoice',
149
-            'post_status'    => array( 'publish' ),
149
+            'post_status'    => array('publish'),
150 150
             'posts_per_page' => -1,
151 151
             'year'           => $year,
152 152
             'fields'         => 'ids'
153 153
         );
154 154
 
155
-        $payments    = get_posts( $args );
156
-        $payment_ids = implode( ',', $payments );
155
+        $payments    = get_posts($args);
156
+        $payment_ids = implode(',', $payments);
157 157
 
158
-        if ( count( $payments ) > 0 ) {
158
+        if (count($payments) > 0) {
159 159
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
160
-            $tax = $wpdb->get_var( $sql );
160
+            $tax = $wpdb->get_var($sql);
161 161
         }
162 162
 
163 163
     }
164 164
 
165
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
165
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
166 166
 }
167 167
 
168 168
 function wpinv_is_cart_taxed() {
@@ -171,33 +171,33 @@  discard block
 block discarded – undo
171 171
 
172 172
 function wpinv_prices_show_tax_on_checkout() {
173 173
     return false; // TODO
174
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
174
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
175 175
 
176
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
176
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
177 177
 }
178 178
 
179 179
 function wpinv_display_tax_rate() {
180
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
180
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
181 181
 
182
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
182
+    return apply_filters('wpinv_display_tax_rate', $ret);
183 183
 }
184 184
 
185 185
 function wpinv_cart_needs_tax_address_fields() {
186
-    if( !wpinv_is_cart_taxed() )
186
+    if (!wpinv_is_cart_taxed())
187 187
         return false;
188 188
 
189
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
189
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
190 190
 }
191 191
 
192
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
193
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
194
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
192
+function wpinv_item_is_tax_exclusive($item_id = 0) {
193
+    $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false);
194
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
195 195
 }
196 196
 
197
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
197
+function wpinv_currency_decimal_filter($decimals = 2) {
198 198
     $currency = wpinv_get_currency();
199 199
 
200
-    switch ( $currency ) {
200
+    switch ($currency) {
201 201
         case 'RIAL' :
202 202
         case 'JPY' :
203 203
         case 'TWD' :
@@ -206,48 +206,48 @@  discard block
 block discarded – undo
206 206
             break;
207 207
     }
208 208
 
209
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
209
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
210 210
 }
211 211
 
212 212
 function wpinv_tax_amount() {
213 213
     $output = 0.00;
214 214
     
215
-    return apply_filters( 'wpinv_tax_amount', $output );
215
+    return apply_filters('wpinv_tax_amount', $output);
216 216
 }
217 217
 
218 218
 function wpinv_recalculated_tax() {
219
-    define( 'WPINV_RECALCTAX', true );
219
+    define('WPINV_RECALCTAX', true);
220 220
 }
221
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 );
221
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1);
222 222
 
223
-function wpinv_recalculate_tax( $return = false ) {
224
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
225
-    if ( empty( $invoice_id ) ) {
223
+function wpinv_recalculate_tax($return = false) {
224
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
225
+    if (empty($invoice_id)) {
226 226
         return false;
227 227
     }
228 228
     
229
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
229
+    $invoice = wpinv_get_invoice_cart($invoice_id);
230 230
 
231
-    if ( empty( $invoice ) ) {
231
+    if (empty($invoice)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    if ( empty( $_POST['country'] ) ) {
235
+    if (empty($_POST['country'])) {
236 236
         $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
237 237
     }
238 238
         
239 239
     $invoice->country = sanitize_text_field($_POST['country']);
240
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
+    $invoice->set('country', sanitize_text_field($_POST['country']));
241 241
     if (isset($_POST['state'])) {
242 242
         $invoice->state = sanitize_text_field($_POST['state']);
243
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
243
+        $invoice->set('state', sanitize_text_field($_POST['state']));
244 244
     }
245 245
 
246 246
     $invoice->cart_details  = wpinv_get_cart_content_details();
247 247
     
248
-    $subtotal               = wpinv_get_cart_subtotal( $invoice->cart_details );
249
-    $tax                    = wpinv_get_cart_tax( $invoice->cart_details );
250
-    $total                  = wpinv_get_cart_total( $invoice->cart_details );
248
+    $subtotal               = wpinv_get_cart_subtotal($invoice->cart_details);
249
+    $tax                    = wpinv_get_cart_tax($invoice->cart_details);
250
+    $total                  = wpinv_get_cart_total($invoice->cart_details);
251 251
 
252 252
     $invoice->tax           = $tax;
253 253
     $invoice->subtotal      = $subtotal;
@@ -255,61 +255,61 @@  discard block
 block discarded – undo
255 255
 
256 256
     $invoice->save();
257 257
     
258
-    if ( $invoice->is_free_trial() ) {
258
+    if ($invoice->is_free_trial()) {
259 259
         $total = 0;
260 260
     }
261 261
     
262 262
     $response = array(
263
-        'total'        => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ),
263
+        'total'        => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'),
264 264
         'total_raw'    => $total,
265
-        'free'         => !( (float)$total > 0 ) && $invoice->is_free() ? true : false,
266
-        'html'         => wpinv_checkout_cart( $invoice->cart_details, false ),
265
+        'free'         => !((float) $total > 0) && $invoice->is_free() ? true : false,
266
+        'html'         => wpinv_checkout_cart($invoice->cart_details, false),
267 267
     );
268 268
     
269
-    if ( $return ) {
269
+    if ($return) {
270 270
         return $response;
271 271
     }
272 272
 
273
-    wp_send_json( $response );
273
+    wp_send_json($response);
274 274
 }
275
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
276
-add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
275
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
276
+add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
277 277
 
278 278
 // VAT Settings
279
-function wpinv_vat_rate_add_callback( $args ) {
279
+function wpinv_vat_rate_add_callback($args) {
280 280
     ?>
281
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
281
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
282 282
     <?php
283 283
 }
284 284
 
285
-function wpinv_vat_rate_delete_callback( $args ) {
285
+function wpinv_vat_rate_delete_callback($args) {
286 286
     global $wpinv_euvat;
287 287
     
288 288
     $vat_classes = $wpinv_euvat->get_rate_classes();
289
-    $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '';
290
-    if ( isset( $vat_classes[$vat_class] ) ) {
289
+    $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '';
290
+    if (isset($vat_classes[$vat_class])) {
291 291
     ?>
292
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
292
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
293 293
     <?php
294 294
     }
295 295
 }
296 296
 
297
-function wpinv_vat_rates_callback( $args ) {
297
+function wpinv_vat_rates_callback($args) {
298 298
     global $wpinv_euvat;
299 299
     
300 300
     $vat_classes    = $wpinv_euvat->get_rate_classes();
301
-    $vat_class      = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard';
301
+    $vat_class      = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard';
302 302
     
303 303
     $eu_states      = $wpinv_euvat->get_eu_states();
304 304
     $countries      = wpinv_get_country_list();
305 305
     $vat_groups     = $wpinv_euvat->get_vat_groups();
306
-    $rates          = $wpinv_euvat->get_vat_rates( $vat_class );
306
+    $rates          = $wpinv_euvat->get_vat_rates($vat_class);
307 307
     ob_start();
308 308
 ?>
309 309
 </td><tr>
310 310
     <td colspan="2" class="wpinv_vat_tdbox">
311
-    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" />
312
-    <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p>
311
+    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" />
312
+    <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p>
313 313
     <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts">
314 314
         <colgroup>
315 315
             <col width="50px" />
@@ -321,43 +321,43 @@  discard block
 block discarded – undo
321 321
         </colgroup>
322 322
         <thead>
323 323
             <tr>
324
-                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th>
325
-                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
326
-                <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
327
-                <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th>
328
-                <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th>
324
+                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th>
325
+                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
326
+                <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
327
+                <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th>
328
+                <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th>
329 329
             </tr>
330 330
         </thead>
331 331
         <tbody>
332
-        <?php if( !empty( $eu_states ) ) { ?>
332
+        <?php if (!empty($eu_states)) { ?>
333 333
         <?php 
334
-        foreach ( $eu_states as $state ) { 
335
-            $country_name = isset( $countries[$state] ) ? $countries[$state] : '';
334
+        foreach ($eu_states as $state) { 
335
+            $country_name = isset($countries[$state]) ? $countries[$state] : '';
336 336
             
337 337
             // Filter the rate for each country
338
-            $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } );
338
+            $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } );
339 339
             
340 340
             // If one does not exist create a default
341
-            $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array();
341
+            $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array();
342 342
             
343
-            $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true;
344
-            $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : '';
345
-            $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : '';
346
-            $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' );
343
+            $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true;
344
+            $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : '';
345
+            $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : '';
346
+            $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced');
347 347
         ?>
348 348
         <tr>
349 349
             <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td>
350 350
             <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td>
351 351
             <td class="wpinv_vat_global">
352
-                <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" />
353
-                <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
354
-                <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" />
352
+                <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" />
353
+                <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
354
+                <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" />
355 355
             </td>
356
-            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
-            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td>
356
+            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
+            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td>
358 358
             <td class="wpinv_vat_group">
359 359
             <?php
360
-            echo wpinv_html_select( array(
360
+            echo wpinv_html_select(array(
361 361
                                         'name'             => 'vat_rates[' . $state . '][group]',
362 362
                                         'selected'         => $vat_group,
363 363
                                         'id'               => 'vat_rates[' . $state . '][group]',
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
                                         'multiple'         => false,
367 367
                                         'show_option_all'  => false,
368 368
                                         'show_option_none' => false
369
-                                    ) );
369
+                                    ));
370 370
             ?>
371 371
             </td>
372 372
         </tr>
373 373
         <?php } ?>
374 374
         <tr>
375 375
             <td colspan="6" style="background-color:#fafafa;">
376
-                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
376
+                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
377 377
             </td>
378 378
         </tr>
379 379
         <?php } ?>
@@ -385,35 +385,35 @@  discard block
 block discarded – undo
385 385
     echo $content;
386 386
 }
387 387
 
388
-function wpinv_vat_number_callback( $args ) {
388
+function wpinv_vat_number_callback($args) {
389 389
     global $wpinv_euvat;
390 390
     
391 391
     $vat_number     = $wpinv_euvat->get_vat_number();
392 392
     $vat_valid      = $wpinv_euvat->is_vat_validated();
393 393
 
394
-    $size           = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular';
395
-    $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' );
394
+    $size           = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
395
+    $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing');
396 396
     $disabled       = $vat_valid ? 'disabled="disabled"' : " ";
397 397
     
398
-    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>';
399
-    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>';
400
-    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
401
-    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>';
402
-    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">';
398
+    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>';
399
+    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>';
400
+    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
401
+    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>';
402
+    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">';
403 403
 
404 404
     echo $html;
405 405
 }
406 406
 
407
-function wpinv_eu_fallback_rate_callback( $args ) {
407
+function wpinv_eu_fallback_rate_callback($args) {
408 408
     global $wpinv_options;
409 409
 
410
-    $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' );
411
-    $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small';
410
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : '');
411
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small';
412 412
     
413
-    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />';
414
-    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>';
415
-    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>';
416
-    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
413
+    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />';
414
+    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>';
415
+    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>';
416
+    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
417 417
     $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>';
418 418
     echo $html;
419 419
     ?>
@@ -421,36 +421,36 @@  discard block
 block discarded – undo
421 421
     <?php
422 422
 }
423 423
 
424
-function wpinv_vat_ip_lookup_callback( $args ) {
424
+function wpinv_vat_ip_lookup_callback($args) {
425 425
     global $wpinv_options, $wpinv_euvat;
426 426
 
427
-    $value =  isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ]  : ( isset( $args['std'] ) ? $args['std'] : 'default' );
427
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default');
428 428
     
429 429
     $options = array();
430
-    if ( function_exists( 'geoip_country_code_by_name' ) ) {
431
-        $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' );
430
+    if (function_exists('geoip_country_code_by_name')) {
431
+        $options['geoip'] = __('PHP GeoIP extension', 'invoicing');
432 432
     }
433 433
     
434 434
     $geoip2_database = $wpinv_euvat->geoip2_country_dbfile();
435 435
     
436
-    if ( !function_exists( 'bcadd' ) ) {
437
-        $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' );
436
+    if (!function_exists('bcadd')) {
437
+        $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing');
438 438
     } else {
439
-        $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : '';
439
+        $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : '';
440 440
     }
441 441
     
442
-    if ( $geoip2_database !== false && empty( $geoip2_message ) ) {
443
-        $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' );
442
+    if ($geoip2_database !== false && empty($geoip2_message)) {
443
+        $options['geoip2'] = __('GeoIP2 Database', 'invoicing');
444 444
     }
445 445
     
446
-    if ( function_exists( 'simplexml_load_file' ) ) {
447
-        $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' );
446
+    if (function_exists('simplexml_load_file')) {
447
+        $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing');
448 448
     }
449 449
     
450
-    $options['site']    = __( 'Use default country', 'invoicing' );
451
-    $options['default'] = __( 'Auto', 'invoicing' );
450
+    $options['site']    = __('Use default country', 'invoicing');
451
+    $options['default'] = __('Auto', 'invoicing');
452 452
 
453
-    $html = wpinv_html_select( array(
453
+    $html = wpinv_html_select(array(
454 454
         'name'             => "wpinv_settings[{$args['id']}]",
455 455
         'selected'         => $value,
456 456
         'id'               => "wpinv_settings[{$args['id']}]",
@@ -462,23 +462,23 @@  discard block
 block discarded – undo
462 462
     ));
463 463
     
464 464
     $desc = '<label for="wpinv_settings[' . $args['id'] . ']">';
465
-    $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' );
465
+    $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing');
466 466
     $desc .= '<p>';
467
-    if ( empty( $geoip2_message ) ) {
468
-        if ( $geoip2_database ) {
467
+    if (empty($geoip2_message)) {
468
+        if ($geoip2_database) {
469 469
             $last_updated = '';
470
-            if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) {
471
-                $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated );
472
-                $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated );
470
+            if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) {
471
+                $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated);
472
+                $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated);
473 473
             }
474
-            $desc .= __(  'GeoIP2 database exists:', 'invoicing' ) . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~55MB)', 'invoicing' ) . '"></input>';
474
+            $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~55MB)', 'invoicing') . '"></input>';
475 475
         } else {
476
-            $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~53MB)"></input><br>' . __(  'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' );
476
+            $desc .= __('GeoIP2 database does not exist:', 'invoicing') . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~53MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing');
477 477
         }
478 478
     } else {
479 479
         $desc .= $geoip2_message;
480 480
     }
481
-    $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
481
+    $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
482 482
     $desc .= '</label>';
483 483
     
484 484
     $html .= $desc;
Please login to merge, or discard this patch.
templates/wpinv-subscriptions-history.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 global $wpdb;
14 14
 
15 15
 $db = new WPInv_Subscriptions_DB;
16
-$page = isset($_GET['cpage']) ? abs((int)$_GET['cpage']) : 1;
16
+$page = isset($_GET['cpage']) ? abs((int) $_GET['cpage']) : 1;
17 17
 $items_per_page = get_option('posts_per_page');
18 18
 $offset = ($page * $items_per_page) - $items_per_page;
19 19
 $args = array('customer_id' => $user_id, 'offset' => $offset);
@@ -29,16 +29,16 @@  discard block
 block discarded – undo
29 29
     <table class="table table-bordered table-hover table-responsive wpi-user-subscriptions">
30 30
         <thead>
31 31
         <tr>
32
-            <th class="sub-no"><span class="nobr"><?php _e( 'No.', 'invoicing' ); ?></span></th>
33
-            <th class="sub-amount"><span class="nobr"><?php _e( 'Initial Amount', 'invoicing' ); ?></span></th>
34
-            <th class="sub-cycle"><span class="nobr"><?php _e( 'Billing Cycle', 'invoicing' ); ?></span></th>
35
-            <th class="sub-billed"><span class="nobr"><?php _e( 'Times Billed', 'invoicing' ); ?></span></th>
36
-            <th class="sub-status"><span class="nobr"><?php _e( 'Status', 'invoicing' ); ?></span></th>
37
-            <th class="sub-invoice"><span class="nobr"><?php _e( 'Invoice', 'invoicing' ); ?></span></th>
38
-            <th class="sub-item"><span class="nobr"><?php _e( 'Item', 'invoicing' ); ?></span></th>
39
-            <th class="sub-gateway"><span class="nobr"><?php _e( 'Gateway', 'invoicing' ); ?></span></th>
40
-            <th class="sub-expiry"><span class="nobr"><?php _e( 'Expires On', 'invoicing' ); ?></span></th>
41
-            <th class="sub-actions"><span class="nobr"><?php _e( 'Actions', 'invoicing' ); ?></span></th>
32
+            <th class="sub-no"><span class="nobr"><?php _e('No.', 'invoicing'); ?></span></th>
33
+            <th class="sub-amount"><span class="nobr"><?php _e('Initial Amount', 'invoicing'); ?></span></th>
34
+            <th class="sub-cycle"><span class="nobr"><?php _e('Billing Cycle', 'invoicing'); ?></span></th>
35
+            <th class="sub-billed"><span class="nobr"><?php _e('Times Billed', 'invoicing'); ?></span></th>
36
+            <th class="sub-status"><span class="nobr"><?php _e('Status', 'invoicing'); ?></span></th>
37
+            <th class="sub-invoice"><span class="nobr"><?php _e('Invoice', 'invoicing'); ?></span></th>
38
+            <th class="sub-item"><span class="nobr"><?php _e('Item', 'invoicing'); ?></span></th>
39
+            <th class="sub-gateway"><span class="nobr"><?php _e('Gateway', 'invoicing'); ?></span></th>
40
+            <th class="sub-expiry"><span class="nobr"><?php _e('Expires On', 'invoicing'); ?></span></th>
41
+            <th class="sub-actions"><span class="nobr"><?php _e('Actions', 'invoicing'); ?></span></th>
42 42
         </tr>
43 43
         </thead>
44 44
 
Please login to merge, or discard this patch.
templates/emails/wpinv-email-invoice-items.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 global $wpinv_euvat, $ajax_cart_details;
@@ -10,153 +10,153 @@  discard block
 block discarded – undo
10 10
 $invoice_id         = $invoice->ID;
11 11
 $quantities_enabled = wpinv_item_quantities_enabled();
12 12
 $use_taxes          = wpinv_use_taxes();
13
-$zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
14
-$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
15
-$tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
13
+$zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
14
+$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
15
+$tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
16 16
 
17
-do_action( 'wpinv_before_email_items', $invoice ); ?>
17
+do_action('wpinv_before_email_items', $invoice); ?>
18 18
 <div id="wpinv-email-items">
19
-    <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3>
19
+    <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3>
20 20
     <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
21 21
         <thead>
22 22
             <tr class="wpinv_cart_header_row">
23
-                <?php do_action( 'wpinv_email_items_table_header_first' ); ?>
24
-                <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
25
-                <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
26
-                <?php if ( $quantities_enabled ) { ?>
27
-                <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
23
+                <?php do_action('wpinv_email_items_table_header_first'); ?>
24
+                <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
25
+                <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
26
+                <?php if ($quantities_enabled) { ?>
27
+                <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
28 28
                 <?php } ?>
29
-                <?php if ( !$zero_tax && $use_taxes ) { ?>
29
+                <?php if (!$zero_tax && $use_taxes) { ?>
30 30
                 <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
31 31
                 <?php } ?>
32
-                <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
-                <?php do_action( 'wpinv_email_items_table_header_last' ); ?>
32
+                <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
+                <?php do_action('wpinv_email_items_table_header_last'); ?>
34 34
             </tr>
35 35
         </thead>
36 36
         <tbody>
37 37
             <?php
38
-                do_action( 'wpinv_email_items_before' );
39
-                if ( $cart_items ) {
40
-                    foreach ( $cart_items as $key => $item ) {
41
-                        $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL;
38
+                do_action('wpinv_email_items_before');
39
+                if ($cart_items) {
40
+                    foreach ($cart_items as $key => $item) {
41
+                        $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL;
42 42
                     ?>
43
-                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
44
-                        <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?>
43
+                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
44
+                        <?php do_action('wpinv_email_items_table_body_first', $item); ?>
45 45
                         <td class="wpinv_cart_item_name text-left">
46 46
                             <?php
47
-                                if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
47
+                                if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
48 48
                                     echo '<div class="wpinv_cart_item_image">';
49
-                                        echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
49
+                                        echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
50 50
                                     echo '</div>';
51 51
                                 }
52
-                                $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
52
+                                $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
53 53
                                 echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>';
54 54
                                 
55
-                                $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice );
56
-                                if ( !empty( $summary ) ) {
55
+                                $summary = apply_filters('wpinv_email_invoice_line_item_summary', '', $item, $wpi_item, $invoice);
56
+                                if (!empty($summary)) {
57 57
                                     echo '<p class="small">' . $summary . '</p>';
58 58
                                 }
59 59
     
60
-                                do_action( 'wpinv_email_cart_item_title_after', $item, $key );
60
+                                do_action('wpinv_email_cart_item_title_after', $item, $key);
61 61
                             ?>
62 62
                         </td>
63 63
                         <td class="wpinv_cart_item_price text-right">
64 64
                             <?php 
65
-                            echo wpinv_cart_item_price( $item );
66
-                            do_action( 'wpinv_email_cart_item_price_after', $item, $key );
65
+                            echo wpinv_cart_item_price($item);
66
+                            do_action('wpinv_email_cart_item_price_after', $item, $key);
67 67
                             ?>
68 68
                         </td>
69
-                        <?php if ( $quantities_enabled ) { ?>
69
+                        <?php if ($quantities_enabled) { ?>
70 70
                         <td class="wpinv_cart_item_qty text-right">
71 71
                             <?php
72
-                            echo wpinv_get_cart_item_quantity( $item );
73
-                            do_action( 'wpinv_email_item_quantitiy', $item, $key );
72
+                            echo wpinv_get_cart_item_quantity($item);
73
+                            do_action('wpinv_email_item_quantitiy', $item, $key);
74 74
                             ?>
75 75
                         </td>
76 76
                         <?php } ?>
77
-                        <?php if ( !$zero_tax && $use_taxes ) { ?>
77
+                        <?php if (!$zero_tax && $use_taxes) { ?>
78 78
                         <td class="wpinv_cart_item_tax text-right">
79 79
                             <?php
80
-                            echo wpinv_cart_item_tax( $item );
81
-                            do_action( 'wpinv_email_item_tax', $item, $key );
80
+                            echo wpinv_cart_item_tax($item);
81
+                            do_action('wpinv_email_item_tax', $item, $key);
82 82
                             ?>
83 83
                         </td>
84 84
                         <?php } ?>
85 85
                         <td class="wpinv_cart_item_subtotal text-right">
86 86
                             <?php
87
-                            echo wpinv_cart_item_subtotal( $item );
88
-                            do_action( 'wpinv_email_item_subtotal', $item, $key );
87
+                            echo wpinv_cart_item_subtotal($item);
88
+                            do_action('wpinv_email_item_subtotal', $item, $key);
89 89
                             ?>
90 90
                         </td>
91
-                        <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?>
91
+                        <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?>
92 92
                     </tr>
93 93
                 <?php } ?>
94 94
             <?php } ?>
95
-            <?php do_action( 'wpinv_email_items_middle' ); ?>
96
-            <?php do_action( 'wpinv_email_items_after' ); ?>
95
+            <?php do_action('wpinv_email_items_middle'); ?>
96
+            <?php do_action('wpinv_email_items_after'); ?>
97 97
         </tbody>
98 98
         <tfoot>
99
-            <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?>
100
-            <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?>
99
+            <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?>
100
+            <?php if (has_action('wpinv_email_footer_buttons')) { ?>
101 101
                 <tr class="wpinv_cart_footer_row">
102
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
103
-                    <td colspan="<?php echo ( $cart_columns ); ?>">
104
-                        <?php do_action( 'wpinv_email_footer_buttons' ); ?>
102
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
103
+                    <td colspan="<?php echo ($cart_columns); ?>">
104
+                        <?php do_action('wpinv_email_footer_buttons'); ?>
105 105
                     </td>
106
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
106
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
107 107
                 </tr>
108 108
             <?php } ?>
109 109
 
110
-            <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?>
110
+            <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?>
111 111
                 <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row">
112
-                    <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?>
113
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
114
-                        <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
112
+                    <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?>
113
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
114
+                        <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
115 115
                     </td>
116 116
                     <td class="wpinv_cart_subtotal text-right">
117
-                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span>
117
+                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span>
118 118
                     </td>
119
-                    <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?>
119
+                    <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?>
120 120
                 </tr>
121 121
             <?php } ?>
122 122
             
123
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
123
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
124 124
                 <tr class="wpinv_cart_footer_row wpinv_cart_discount_row">
125
-                    <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?>
126
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right">
127
-                        <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong>
125
+                    <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?>
126
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right">
127
+                        <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong>
128 128
                     </td>
129 129
                     <td class="wpinv_cart_discount text-right">
130
-                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span>
130
+                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span>
131 131
                     </td>
132
-                    <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?>
132
+                    <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?>
133 133
                 </tr>
134 134
             <?php } ?>
135 135
 
136
-            <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?>
136
+            <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?>
137 137
                 <tr class="wpinv_cart_footer_row wpinv_cart_tax_row">
138
-                    <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?>
139
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
138
+                    <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?>
139
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
140 140
                         <strong><?php echo $tax_label; ?>:</strong>
141 141
                     </td>
142 142
                     <td class="wpinv_cart_tax text-right">
143
-                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span>
143
+                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span>
144 144
                     </td>
145
-                    <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?>
145
+                    <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?>
146 146
                 </tr>
147 147
             <?php } ?>
148 148
 
149 149
             <tr class="wpinv_cart_footer_row">
150
-                <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?>
151
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
152
-                    <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
150
+                <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?>
151
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
152
+                    <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
153 153
                 </td>
154 154
                 <td class="wpinv_cart_total text-right">
155
-                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span>
155
+                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span>
156 156
                 </td>
157
-                <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?>
157
+                <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?>
158 158
             </tr>
159 159
         </tfoot>
160 160
     </table>
161 161
 </div>
162
-<?php do_action( 'wpinv_after_email_items', $invoice ); ?>
163 162
\ No newline at end of file
163
+<?php do_action('wpinv_after_email_items', $invoice); ?>
164 164
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-invoice-receipt.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -4,17 +4,17 @@  discard block
 block discarded – undo
4 4
  */
5 5
 global $wpinv_receipt_args;
6 6
 
7
-$invoice   = get_post( $wpinv_receipt_args['id'] );
7
+$invoice = get_post($wpinv_receipt_args['id']);
8 8
 
9
-if( empty( $invoice ) ) {
9
+if (empty($invoice)) {
10 10
     ?>
11 11
     <div class="wpinv_errors alert wpi-alert-error">
12
-        <?php _e( 'The specified receipt ID appears to be invalid', 'invoicing' ); ?>
12
+        <?php _e('The specified receipt ID appears to be invalid', 'invoicing'); ?>
13 13
     </div>
14 14
     <?php
15 15
     return;
16 16
 }
17
-$invoice = wpinv_get_invoice( $invoice->ID );
17
+$invoice = wpinv_get_invoice($invoice->ID);
18 18
 
19 19
 global $ajax_cart_details;
20 20
 $ajax_cart_details = $invoice->get_cart_details();
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
23 23
 $invoice_id         = $invoice->ID;
24 24
 $quantities_enabled = wpinv_item_quantities_enabled();
25 25
 $use_taxes          = wpinv_use_taxes();
26
-$zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
27
-$tax_label          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? __( '(Tax Incl.)', 'invoicing' ) : __( '(Tax Excl.)', 'invoicing' ) ) : '';
26
+$zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
27
+$tax_label          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? __('(Tax Incl.)', 'invoicing') : __('(Tax Excl.)', 'invoicing')) : '';
28 28
 ?>
29
-<?php do_action( 'wpinv_before_receipt', $invoice ); ?>
29
+<?php do_action('wpinv_before_receipt', $invoice); ?>
30 30
 <div class="wpinv-receipt">
31
-    <?php do_action( 'wpinv_receipt_start', $invoice ); ?>
32
-    <div class="wpinv-receipt-message"><?php _e( 'Thank you for your payment!', 'invoicing' ); ?></div>
33
-    <?php do_action( 'wpinv_before_receipt_details', $invoice ); ?>
31
+    <?php do_action('wpinv_receipt_start', $invoice); ?>
32
+    <div class="wpinv-receipt-message"><?php _e('Thank you for your payment!', 'invoicing'); ?></div>
33
+    <?php do_action('wpinv_before_receipt_details', $invoice); ?>
34 34
     <div class="wpinv-receipt-details">
35
-        <h3 class="wpinv-details-t"><?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ) ); ?></h3>
36
-        <?php wpinv_display_invoice_details( $invoice ); ?>
35
+        <h3 class="wpinv-details-t"><?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing')); ?></h3>
36
+        <?php wpinv_display_invoice_details($invoice); ?>
37 37
     </div>
38
-    <?php do_action( 'wpinv_after_receipt_details', $invoice ); ?>
39
-    <?php do_action( 'wpinv_receipt_end', $invoice ); ?>
38
+    <?php do_action('wpinv_after_receipt_details', $invoice); ?>
39
+    <?php do_action('wpinv_receipt_end', $invoice); ?>
40 40
 </div>
41
-<?php do_action( 'wpinv_after_receipt', $invoice ); ?>
42 41
\ No newline at end of file
42
+<?php do_action('wpinv_after_receipt', $invoice); ?>
43 43
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +480 added lines, -480 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@  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( ! wpinv_current_user_can_manage_invoicing() ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!wpinv_current_user_can_manage_invoicing()) {
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( ! wpinv_current_user_can_manage_invoicing() ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!wpinv_current_user_can_manage_invoicing()) {
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( ! wpinv_current_user_can_manage_invoicing() ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!wpinv_current_user_can_manage_invoicing()) {
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']     = '_wpi_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
 
97 97
     return false;
98 98
 }
99 99
 
100
-function wpinv_get_all_discounts( $args = array() ) {
100
+function wpinv_get_all_discounts($args = array()) {
101 101
 
102
-    $args = wp_parse_args( $args, array(
103
-        'status'         => array( 'publish' ),
104
-        'limit'          => get_option( 'posts_per_page' ),
102
+    $args = wp_parse_args($args, array(
103
+        'status'         => array('publish'),
104
+        'limit'          => get_option('posts_per_page'),
105 105
         'page'           => 1,
106 106
         'exclude'        => array(),
107 107
         'orderby'        => 'date',
108 108
         'order'          => 'DESC',
109
-        'type'           => array_keys( wpinv_get_discount_types() ),
109
+        'type'           => array_keys(wpinv_get_discount_types()),
110 110
         'meta_query'     => array(),
111 111
         'return'         => 'objects',
112 112
         'paginate'       => false,
113
-    ) );
113
+    ));
114 114
 
115 115
     $wp_query_args = array(
116 116
         'post_type'      => 'wpi_discount',
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
         'fields'         => 'ids',
121 121
         'orderby'        => $args['orderby'],
122 122
         'order'          => $args['order'],
123
-        'paged'          => absint( $args['page'] ),
123
+        'paged'          => absint($args['page']),
124 124
     );
125 125
 
126
-    if ( ! empty( $args['exclude'] ) ) {
127
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
126
+    if (!empty($args['exclude'])) {
127
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
128 128
     }
129 129
 
130
-    if ( ! $args['paginate' ] ) {
130
+    if (!$args['paginate']) {
131 131
         $wp_query_args['no_found_rows'] = true;
132 132
     }
133 133
 
134
-    if ( ! empty( $args['search'] ) ) {
134
+    if (!empty($args['search'])) {
135 135
 
136 136
         $wp_query_args['meta_query'][] = array(
137 137
             'key'     => '_wpi_discount_code',
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 
142 142
     }
143 143
     
144
-    if ( ! empty( $args['type'] ) ) {
145
-        $types = wpinv_parse_list( $args['type'] );
144
+    if (!empty($args['type'])) {
145
+        $types = wpinv_parse_list($args['type']);
146 146
         $wp_query_args['meta_query'][] = array(
147 147
             'key'     => '_wpi_discount_type',
148
-            'value'   => implode( ',', $types ),
148
+            'value'   => implode(',', $types),
149 149
             'compare' => 'IN',
150 150
         );
151 151
     }
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
     $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args);
154 154
 
155 155
     // Get results.
156
-    $discounts = new WP_Query( $wp_query_args );
156
+    $discounts = new WP_Query($wp_query_args);
157 157
 
158
-    if ( 'objects' === $args['return'] ) {
159
-        $return = array_map( 'get_post', $discounts->posts );
160
-    } elseif ( 'self' === $args['return'] ) {
158
+    if ('objects' === $args['return']) {
159
+        $return = array_map('get_post', $discounts->posts);
160
+    } elseif ('self' === $args['return']) {
161 161
         return $discounts;
162 162
     } else {
163 163
         $return = $discounts->posts;
164 164
     }
165 165
 
166
-    if ( $args['paginate' ] ) {
166
+    if ($args['paginate']) {
167 167
         return (object) array(
168 168
             'discounts'      => $return,
169 169
             'total'         => $discounts->found_posts,
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 
181 181
     $discounts  = wpinv_get_discounts();
182 182
 
183
-    if ( $discounts) {
184
-        foreach ( $discounts as $discount ) {
185
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
183
+    if ($discounts) {
184
+        foreach ($discounts as $discount) {
185
+            if (wpinv_is_discount_active($discount->ID)) {
186 186
                 $has_active = true;
187 187
                 break;
188 188
             }
@@ -191,38 +191,38 @@  discard block
 block discarded – undo
191 191
     return $has_active;
192 192
 }
193 193
 
194
-function wpinv_get_discount( $discount_id = 0 ) {
195
-    if( empty( $discount_id ) ) {
194
+function wpinv_get_discount($discount_id = 0) {
195
+    if (empty($discount_id)) {
196 196
         return false;
197 197
     }
198 198
     
199
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
199
+    if (get_post_type($discount_id) != 'wpi_discount') {
200 200
         return false;
201 201
     }
202 202
 
203
-    $discount = get_post( $discount_id );
203
+    $discount = get_post($discount_id);
204 204
 
205 205
     return $discount;
206 206
 }
207 207
 
208
-function wpinv_get_discount_by_code( $code = '' ) {
209
-    if( empty( $code ) || ! is_string( $code ) ) {
208
+function wpinv_get_discount_by_code($code = '') {
209
+    if (empty($code) || !is_string($code)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    return wpinv_get_discount_by( 'code', $code );
213
+    return wpinv_get_discount_by('code', $code);
214 214
 }
215 215
 
216
-function wpinv_get_discount_by( $field = '', $value = '' ) {
217
-    if( empty( $field ) || empty( $value ) ) {
216
+function wpinv_get_discount_by($field = '', $value = '') {
217
+    if (empty($field) || empty($value)) {
218 218
         return false;
219 219
     }
220 220
 
221
-    if( ! is_string( $field ) ) {
221
+    if (!is_string($field)) {
222 222
         return false;
223 223
     }
224 224
 
225
-    switch( strtolower( $field ) ) {
225
+    switch (strtolower($field)) {
226 226
 
227 227
         case 'code':
228 228
             $meta_query     = array();
@@ -232,32 +232,32 @@  discard block
 block discarded – undo
232 232
                 'compare' => '='
233 233
             );
234 234
             
235
-            $discount = wpinv_get_discounts( array(
235
+            $discount = wpinv_get_discounts(array(
236 236
                 'posts_per_page' => 1,
237 237
                 'post_status'    => 'any',
238 238
                 'meta_query'     => $meta_query,
239
-            ) );
239
+            ));
240 240
             
241
-            if( $discount ) {
241
+            if ($discount) {
242 242
                 $discount = $discount[0];
243 243
             }
244 244
 
245 245
             break;
246 246
 
247 247
         case 'id':
248
-            $discount = wpinv_get_discount( $value );
248
+            $discount = wpinv_get_discount($value);
249 249
 
250 250
             break;
251 251
 
252 252
         case 'name':
253
-            $discount = get_posts( array(
253
+            $discount = get_posts(array(
254 254
                 'post_type'      => 'wpi_discount',
255 255
                 'name'           => $value,
256 256
                 'posts_per_page' => 1,
257 257
                 'post_status'    => 'any'
258
-            ) );
258
+            ));
259 259
 
260
-            if( $discount ) {
260
+            if ($discount) {
261 261
                 $discount = $discount[0];
262 262
             }
263 263
 
@@ -267,96 +267,96 @@  discard block
 block discarded – undo
267 267
             return false;
268 268
     }
269 269
 
270
-    if( ! empty( $discount ) ) {
270
+    if (!empty($discount)) {
271 271
         return $discount;
272 272
     }
273 273
 
274 274
     return false;
275 275
 }
276 276
 
277
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
277
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
278 278
     $meta = array(
279
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
280
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
281
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
282
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
283
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
284
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
285
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
286
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
287
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
288
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
289
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
290
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
291
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
279
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
280
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
281
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
282
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
283
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
284
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
285
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
286
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
287
+        'items'             => isset($data['items']) ? $data['items'] : array(),
288
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
289
+        'is_recurring'      => isset($data['recurring']) ? (bool) $data['recurring'] : false,
290
+        'is_single_use'     => isset($data['single_use']) ? (bool) $data['single_use'] : false,
291
+        'uses'              => isset($data['uses']) ? (int) $data['uses'] : false,
292 292
     );
293 293
 
294
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
294
+    if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) {
295 295
         $meta['amount'] = 100;
296 296
     }
297 297
 
298
-    if ( !empty( $meta['start'] ) ) {
299
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
298
+    if (!empty($meta['start'])) {
299
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
300 300
     }
301 301
 
302
-    if ( !empty( $meta['expiration'] ) ) {
303
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
302
+    if (!empty($meta['expiration'])) {
303
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
304 304
 
305
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
305
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
306 306
             $meta['expiration'] = $meta['start'];
307 307
         }
308 308
     }
309 309
     
310
-    if ( $meta['uses'] === false ) {
311
-        unset( $meta['uses'] );
310
+    if ($meta['uses'] === false) {
311
+        unset($meta['uses']);
312 312
     }
313 313
     
314
-    if ( ! empty( $meta['items'] ) ) {
315
-        foreach ( $meta['items'] as $key => $item ) {
316
-            if ( 0 === intval( $item ) ) {
317
-                unset( $meta['items'][ $key ] );
314
+    if (!empty($meta['items'])) {
315
+        foreach ($meta['items'] as $key => $item) {
316
+            if (0 === intval($item)) {
317
+                unset($meta['items'][$key]);
318 318
             }
319 319
         }
320 320
     }
321 321
     
322
-    if ( ! empty( $meta['excluded_items'] ) ) {
323
-        foreach ( $meta['excluded_items'] as $key => $item ) {
324
-            if ( 0 === intval( $item ) ) {
325
-                unset( $meta['excluded_items'][ $key ] );
322
+    if (!empty($meta['excluded_items'])) {
323
+        foreach ($meta['excluded_items'] as $key => $item) {
324
+            if (0 === intval($item)) {
325
+                unset($meta['excluded_items'][$key]);
326 326
             }
327 327
         }
328 328
     }
329 329
     
330
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
330
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
331 331
     
332
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
332
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
333 333
     
334
-    foreach( $meta as $key => $value ) {
335
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
334
+    foreach ($meta as $key => $value) {
335
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
336 336
     }
337 337
     
338
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
338
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
339 339
     
340 340
     return $post_id;
341 341
 }
342 342
 
343
-function wpinv_remove_discount( $discount_id = 0 ) {
344
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
343
+function wpinv_remove_discount($discount_id = 0) {
344
+    do_action('wpinv_pre_delete_discount', $discount_id);
345 345
 
346
-    wp_delete_post( $discount_id, true );
346
+    wp_delete_post($discount_id, true);
347 347
 
348
-    do_action( 'wpinv_post_delete_discount', $discount_id );
348
+    do_action('wpinv_post_delete_discount', $discount_id);
349 349
 }
350 350
 
351
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
352
-    $discount = wpinv_get_discount(  $code_id );
351
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
352
+    $discount = wpinv_get_discount($code_id);
353 353
 
354
-    if ( $discount ) {
355
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
354
+    if ($discount) {
355
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
356 356
 
357
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
357
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
358 358
 
359
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
359
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
360 360
 
361 361
         return true;
362 362
     }
@@ -364,173 +364,173 @@  discard block
 block discarded – undo
364 364
     return false;
365 365
 }
366 366
 
367
-function wpinv_discount_exists( $code_id ) {
368
-    if ( wpinv_get_discount(  $code_id ) ) {
367
+function wpinv_discount_exists($code_id) {
368
+    if (wpinv_get_discount($code_id)) {
369 369
         return true;
370 370
     }
371 371
 
372 372
     return false;
373 373
 }
374 374
 
375
-function wpinv_is_discount_active( $code_id = null ) {
376
-    $discount = wpinv_get_discount(  $code_id );
375
+function wpinv_is_discount_active($code_id = null) {
376
+    $discount = wpinv_get_discount($code_id);
377 377
     $return   = false;
378 378
 
379
-    if ( $discount ) {
380
-        if ( wpinv_is_discount_expired( $code_id ) ) {
381
-            if( defined( 'DOING_AJAX' ) ) {
382
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
379
+    if ($discount) {
380
+        if (wpinv_is_discount_expired($code_id)) {
381
+            if (defined('DOING_AJAX')) {
382
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
383 383
             }
384
-        } elseif ( $discount->post_status == 'publish' ) {
384
+        } elseif ($discount->post_status == 'publish') {
385 385
             $return = true;
386 386
         } else {
387
-            if( defined( 'DOING_AJAX' ) ) {
388
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
387
+            if (defined('DOING_AJAX')) {
388
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
389 389
             }
390 390
         }
391 391
     }
392 392
 
393
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
393
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
394 394
 }
395 395
 
396
-function wpinv_get_discount_code( $code_id = null ) {
397
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
396
+function wpinv_get_discount_code($code_id = null) {
397
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
398 398
 
399
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
399
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
400 400
 }
401 401
 
402
-function wpinv_get_discount_start_date( $code_id = null ) {
403
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
402
+function wpinv_get_discount_start_date($code_id = null) {
403
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
404 404
 
405
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
405
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
406 406
 }
407 407
 
408
-function wpinv_get_discount_expiration( $code_id = null ) {
409
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
408
+function wpinv_get_discount_expiration($code_id = null) {
409
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
410 410
 
411
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
411
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_max_uses( $code_id = null ) {
415
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
414
+function wpinv_get_discount_max_uses($code_id = null) {
415
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
416 416
 
417
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
417
+    return (int) apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
418 418
 }
419 419
 
420
-function wpinv_get_discount_uses( $code_id = null ) {
421
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
420
+function wpinv_get_discount_uses($code_id = null) {
421
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
422 422
 
423
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
423
+    return (int) apply_filters('wpinv_get_discount_uses', $uses, $code_id);
424 424
 }
425 425
 
426
-function wpinv_get_discount_min_total( $code_id = null ) {
427
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
426
+function wpinv_get_discount_min_total($code_id = null) {
427
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
428 428
 
429
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
429
+    return (float) apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
430 430
 }
431 431
 
432
-function wpinv_get_discount_max_total( $code_id = null ) {
433
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
432
+function wpinv_get_discount_max_total($code_id = null) {
433
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
434 434
 
435
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
435
+    return (float) apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
436 436
 }
437 437
 
438
-function wpinv_get_discount_amount( $code_id = null ) {
439
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
438
+function wpinv_get_discount_amount($code_id = null) {
439
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
440 440
 
441
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
441
+    return (float) apply_filters('wpinv_get_discount_amount', $amount, $code_id);
442 442
 }
443 443
 
444
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
445
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
444
+function wpinv_get_discount_type($code_id = null, $name = false) {
445
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
446 446
     
447
-    if ( $name ) {
448
-        $name = wpinv_get_discount_type_name( $type );
447
+    if ($name) {
448
+        $name = wpinv_get_discount_type_name($type);
449 449
         
450
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
450
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
451 451
     }
452 452
 
453
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
453
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
454 454
 }
455 455
 
456
-function wpinv_discount_status( $status ) {
457
-    switch( $status ){
456
+function wpinv_discount_status($status) {
457
+    switch ($status) {
458 458
         case 'expired' :
459
-            $name = __( 'Expired', 'invoicing' );
459
+            $name = __('Expired', 'invoicing');
460 460
             break;
461 461
         case 'publish' :
462 462
         case 'active' :
463
-            $name = __( 'Active', 'invoicing' );
463
+            $name = __('Active', 'invoicing');
464 464
             break;
465 465
         default :
466
-            $name = __( 'Inactive', 'invoicing' );
466
+            $name = __('Inactive', 'invoicing');
467 467
             break;
468 468
     }
469 469
     return $name;
470 470
 }
471 471
 
472
-function wpinv_get_discount_excluded_items( $code_id = null ) {
473
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
472
+function wpinv_get_discount_excluded_items($code_id = null) {
473
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
474 474
 
475
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
475
+    if (empty($excluded_items) || !is_array($excluded_items)) {
476 476
         $excluded_items = array();
477 477
     }
478 478
 
479
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
479
+    return (array) apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
480 480
 }
481 481
 
482
-function wpinv_get_discount_item_reqs( $code_id = null ) {
483
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
482
+function wpinv_get_discount_item_reqs($code_id = null) {
483
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
484 484
 
485
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
485
+    if (empty($item_reqs) || !is_array($item_reqs)) {
486 486
         $item_reqs = array();
487 487
     }
488 488
 
489
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
489
+    return (array) apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
490 490
 }
491 491
 
492
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
493
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
492
+function wpinv_get_discount_item_condition($code_id = 0) {
493
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
494 494
 }
495 495
 
496
-function wpinv_is_discount_not_global( $code_id = 0 ) {
497
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
496
+function wpinv_is_discount_not_global($code_id = 0) {
497
+    return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true);
498 498
 }
499 499
 
500
-function wpinv_is_discount_expired( $code_id = null ) {
501
-    $discount = wpinv_get_discount(  $code_id );
500
+function wpinv_is_discount_expired($code_id = null) {
501
+    $discount = wpinv_get_discount($code_id);
502 502
     $return   = false;
503 503
 
504
-    if ( $discount ) {
505
-        $expiration = wpinv_get_discount_expiration( $code_id );
506
-        if ( $expiration ) {
507
-            $expiration = strtotime( $expiration );
508
-            if ( $expiration < current_time( 'timestamp' ) ) {
504
+    if ($discount) {
505
+        $expiration = wpinv_get_discount_expiration($code_id);
506
+        if ($expiration) {
507
+            $expiration = strtotime($expiration);
508
+            if ($expiration < current_time('timestamp')) {
509 509
                 // Discount is expired
510
-                wpinv_update_discount_status( $code_id, 'pending' );
510
+                wpinv_update_discount_status($code_id, 'pending');
511 511
                 $return = true;
512 512
             }
513 513
         }
514 514
     }
515 515
 
516
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
516
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
517 517
 }
518 518
 
519
-function wpinv_is_discount_started( $code_id = null ) {
520
-    $discount = wpinv_get_discount(  $code_id );
519
+function wpinv_is_discount_started($code_id = null) {
520
+    $discount = wpinv_get_discount($code_id);
521 521
     $return   = false;
522 522
 
523
-    if ( $discount ) {
524
-        $start_date = wpinv_get_discount_start_date( $code_id );
523
+    if ($discount) {
524
+        $start_date = wpinv_get_discount_start_date($code_id);
525 525
 
526
-        if ( $start_date ) {
527
-            $start_date = strtotime( $start_date );
526
+        if ($start_date) {
527
+            $start_date = strtotime($start_date);
528 528
 
529
-            if ( $start_date < current_time( 'timestamp' ) ) {
529
+            if ($start_date < current_time('timestamp')) {
530 530
                 // Discount has past the start date
531 531
                 $return = true;
532 532
             } else {
533
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
533
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
534 534
             }
535 535
         } else {
536 536
             // No start date for this discount, so has to be true
@@ -538,159 +538,159 @@  discard block
 block discarded – undo
538 538
         }
539 539
     }
540 540
 
541
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
541
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
542 542
 }
543 543
 
544
-function wpinv_check_discount_dates( $code_id = null ) {
545
-    $discount = wpinv_get_discount(  $code_id );
544
+function wpinv_check_discount_dates($code_id = null) {
545
+    $discount = wpinv_get_discount($code_id);
546 546
     $return   = false;
547 547
 
548
-    if ( $discount ) {
549
-        $start_date = wpinv_get_discount_start_date( $code_id );
548
+    if ($discount) {
549
+        $start_date = wpinv_get_discount_start_date($code_id);
550 550
 
551
-        if ( $start_date ) {
552
-            $start_date = strtotime( $start_date );
551
+        if ($start_date) {
552
+            $start_date = strtotime($start_date);
553 553
 
554
-            if ( $start_date < current_time( 'timestamp' ) ) {
554
+            if ($start_date < current_time('timestamp')) {
555 555
                 // Discount has past the start date
556 556
                 $return = true;
557 557
             } else {
558
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
558
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
559 559
             }
560 560
         } else {
561 561
             // No start date for this discount, so has to be true
562 562
             $return = true;
563 563
         }
564 564
         
565
-        if ( $return ) {
566
-            $expiration = wpinv_get_discount_expiration( $code_id );
565
+        if ($return) {
566
+            $expiration = wpinv_get_discount_expiration($code_id);
567 567
             
568
-            if ( $expiration ) {
569
-                $expiration = strtotime( $expiration );
570
-                if ( $expiration < current_time( 'timestamp' ) ) {
568
+            if ($expiration) {
569
+                $expiration = strtotime($expiration);
570
+                if ($expiration < current_time('timestamp')) {
571 571
                     // Discount is expired
572
-                    wpinv_update_discount_status( $code_id, 'pending' );
572
+                    wpinv_update_discount_status($code_id, 'pending');
573 573
                     $return = true;
574 574
                 }
575 575
             }
576 576
         }
577 577
     }
578 578
     
579
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
579
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
580 580
 }
581 581
 
582
-function wpinv_is_discount_maxed_out( $code_id = null ) {
583
-    $discount = wpinv_get_discount(  $code_id );
582
+function wpinv_is_discount_maxed_out($code_id = null) {
583
+    $discount = wpinv_get_discount($code_id);
584 584
     $return   = false;
585 585
 
586
-    if ( $discount ) {
587
-        $uses = wpinv_get_discount_uses( $code_id );
586
+    if ($discount) {
587
+        $uses = wpinv_get_discount_uses($code_id);
588 588
         // Large number that will never be reached
589
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
589
+        $max_uses = wpinv_get_discount_max_uses($code_id);
590 590
         // Should never be greater than, but just in case
591
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
591
+        if ($uses >= $max_uses && !empty($max_uses)) {
592 592
             // Discount is maxed out
593
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
593
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
594 594
             $return = true;
595 595
         }
596 596
     }
597 597
 
598
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
598
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
599 599
 }
600 600
 
601
-function wpinv_discount_is_min_met( $code_id = null ) {
602
-    $discount = wpinv_get_discount( $code_id );
601
+function wpinv_discount_is_min_met($code_id = null) {
602
+    $discount = wpinv_get_discount($code_id);
603 603
     $return   = false;
604 604
 
605
-    if ( $discount ) {
606
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
607
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
605
+    if ($discount) {
606
+        $min         = (float) wpinv_get_discount_min_total($code_id);
607
+        $cart_amount = (float) wpinv_get_cart_discountable_subtotal($code_id);
608 608
 
609
-        if ( !$min > 0 || $cart_amount >= $min ) {
609
+        if (!$min > 0 || $cart_amount >= $min) {
610 610
             // Minimum has been met
611 611
             $return = true;
612 612
         } else {
613
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
613
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
614 614
         }
615 615
     }
616 616
 
617
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
617
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
618 618
 }
619 619
 
620
-function wpinv_discount_is_max_met( $code_id = null ) {
621
-    $discount = wpinv_get_discount( $code_id );
620
+function wpinv_discount_is_max_met($code_id = null) {
621
+    $discount = wpinv_get_discount($code_id);
622 622
     $return   = false;
623 623
 
624
-    if ( $discount ) {
625
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
626
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
624
+    if ($discount) {
625
+        $max         = (float) wpinv_get_discount_max_total($code_id);
626
+        $cart_amount = (float) wpinv_get_cart_discountable_subtotal($code_id);
627 627
 
628
-        if ( !$max > 0 || $cart_amount <= $max ) {
628
+        if (!$max > 0 || $cart_amount <= $max) {
629 629
             // Minimum has been met
630 630
             $return = true;
631 631
         } else {
632
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
632
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
633 633
         }
634 634
     }
635 635
 
636
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
636
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
637 637
 }
638 638
 
639
-function wpinv_discount_is_single_use( $code_id = 0 ) {
640
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
641
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
639
+function wpinv_discount_is_single_use($code_id = 0) {
640
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
641
+    return (bool) apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
642 642
 }
643 643
 
644
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
645
-    if ( $code ) {
646
-        $discount = wpinv_get_discount_by_code( $code_id );
644
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
645
+    if ($code) {
646
+        $discount = wpinv_get_discount_by_code($code_id);
647 647
         
648
-        if ( !empty( $discount ) ) {
648
+        if (!empty($discount)) {
649 649
             $code_id = $discount->ID;
650 650
         }
651 651
     }
652 652
     
653
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
653
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
654 654
     
655
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
655
+    return (bool) apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
656 656
 }
657 657
 
658
-function wpinv_discount_item_reqs_met( $code_id = null ) {
659
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
660
-    $condition    = wpinv_get_discount_item_condition( $code_id );
661
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
658
+function wpinv_discount_item_reqs_met($code_id = null) {
659
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
660
+    $condition    = wpinv_get_discount_item_condition($code_id);
661
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
662 662
     $cart_items   = wpinv_get_cart_contents();
663
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
663
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
664 664
     $ret          = false;
665 665
 
666
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
666
+    if (empty($item_reqs) && empty($excluded_ps)) {
667 667
         $ret = true;
668 668
     }
669 669
 
670 670
     // Normalize our data for item requirements, exclusions and cart data
671 671
     // First absint the items, then sort, and reset the array keys
672
-    $item_reqs = array_map( 'absint', $item_reqs );
673
-    asort( $item_reqs );
674
-    $item_reqs = array_values( $item_reqs );
672
+    $item_reqs = array_map('absint', $item_reqs);
673
+    asort($item_reqs);
674
+    $item_reqs = array_values($item_reqs);
675 675
 
676
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
677
-    asort( $excluded_ps );
678
-    $excluded_ps  = array_values( $excluded_ps );
676
+    $excluded_ps  = array_map('absint', $excluded_ps);
677
+    asort($excluded_ps);
678
+    $excluded_ps  = array_values($excluded_ps);
679 679
 
680
-    $cart_ids     = array_map( 'absint', $cart_ids );
681
-    asort( $cart_ids );
682
-    $cart_ids     = array_values( $cart_ids );
680
+    $cart_ids     = array_map('absint', $cart_ids);
681
+    asort($cart_ids);
682
+    $cart_ids     = array_values($cart_ids);
683 683
 
684 684
     // Ensure we have requirements before proceeding
685
-    if ( !$ret && ! empty( $item_reqs ) ) {
686
-        switch( $condition ) {
685
+    if (!$ret && !empty($item_reqs)) {
686
+        switch ($condition) {
687 687
             case 'all' :
688 688
                 // Default back to true
689 689
                 $ret = true;
690 690
 
691
-                foreach ( $item_reqs as $item_id ) {
692
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
693
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
691
+                foreach ($item_reqs as $item_id) {
692
+                    if (!wpinv_item_in_cart($item_id)) {
693
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
694 694
                         $ret = false;
695 695
                         break;
696 696
                     }
@@ -699,15 +699,15 @@  discard block
 block discarded – undo
699 699
                 break;
700 700
 
701 701
             default : // Any
702
-                foreach ( $item_reqs as $item_id ) {
703
-                    if ( wpinv_item_in_cart( $item_id ) ) {
702
+                foreach ($item_reqs as $item_id) {
703
+                    if (wpinv_item_in_cart($item_id)) {
704 704
                         $ret = true;
705 705
                         break;
706 706
                     }
707 707
                 }
708 708
 
709
-                if( ! $ret ) {
710
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
709
+                if (!$ret) {
710
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
711 711
                 }
712 712
 
713 713
                 break;
@@ -716,70 +716,70 @@  discard block
 block discarded – undo
716 716
         $ret = true;
717 717
     }
718 718
 
719
-    if( ! empty( $excluded_ps ) ) {
719
+    if (!empty($excluded_ps)) {
720 720
         // Check that there are items other than excluded ones in the cart
721
-        if( $cart_ids == $excluded_ps ) {
722
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
721
+        if ($cart_ids == $excluded_ps) {
722
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
723 723
             $ret = false;
724 724
         }
725 725
     }
726 726
 
727
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
727
+    return (bool) apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
728 728
 }
729 729
 
730
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
730
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
731 731
     global $wpi_checkout_id;
732 732
     
733 733
     $return = false;
734 734
 
735
-    if ( empty( $code_id ) ) {
736
-        $code_id = wpinv_get_discount_id_by_code( $code );
735
+    if (empty($code_id)) {
736
+        $code_id = wpinv_get_discount_id_by_code($code);
737 737
         
738
-        if( empty( $code_id ) ) {
738
+        if (empty($code_id)) {
739 739
             return false; // No discount was found
740 740
         }
741 741
     }
742 742
 
743
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
743
+    if (wpinv_discount_is_single_use($code_id)) {
744 744
         $payments = array();
745 745
 
746 746
         $user_id = 0;
747
-        if ( is_int( $user ) ) {
748
-            $user_id = absint( $user );
749
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
747
+        if (is_int($user)) {
748
+            $user_id = absint($user);
749
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
750 750
             $user_id = $user_data->ID;
751
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
751
+        } else if ($user_data = get_user_by('login', $user)) {
752 752
             $user_id = $user_data->ID;
753
-        } else if ( absint( $user ) > 0 ) {
754
-            $user_id = absint( $user );
753
+        } else if (absint($user) > 0) {
754
+            $user_id = absint($user);
755 755
         }
756 756
 
757
-        if ( !empty( $user_id ) ) {
758
-            $query    = array( 'user' => $user_id, 'limit' => false );
759
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
757
+        if (!empty($user_id)) {
758
+            $query    = array('user' => $user_id, 'limit' => false);
759
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
760 760
         }
761 761
 
762
-        if ( $payments ) {
763
-            foreach ( $payments as $payment ) {
762
+        if ($payments) {
763
+            foreach ($payments as $payment) {
764 764
                 // Don't count discount used for current invoice chekcout.
765
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
765
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
766 766
                     continue;
767 767
                 }
768 768
                 
769
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
769
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
770 770
                     continue;
771 771
                 }
772 772
 
773
-                $discounts = $payment->get_discounts( true );
774
-                if ( empty( $discounts ) ) {
773
+                $discounts = $payment->get_discounts(true);
774
+                if (empty($discounts)) {
775 775
                     continue;
776 776
                 }
777 777
 
778
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
778
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
779 779
 
780
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
781
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
782
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
780
+                if (!empty($discounts) && is_array($discounts)) {
781
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
782
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
783 783
                         $return = true;
784 784
                         break;
785 785
                     }
@@ -788,61 +788,61 @@  discard block
 block discarded – undo
788 788
         }
789 789
     }
790 790
 
791
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
791
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
792 792
 }
793 793
 
794
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
794
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
795 795
     $return      = false;
796
-    $discount_id = wpinv_get_discount_id_by_code( $code );
797
-    $user        = trim( $user );
796
+    $discount_id = wpinv_get_discount_id_by_code($code);
797
+    $user        = trim($user);
798 798
 
799
-    if ( wpinv_get_cart_contents() ) {
800
-        if ( $discount_id ) {
799
+    if (wpinv_get_cart_contents()) {
800
+        if ($discount_id) {
801 801
             if (
802
-                wpinv_is_discount_active( $discount_id ) &&
803
-                wpinv_check_discount_dates( $discount_id ) &&
804
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
805
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
806
-                wpinv_discount_is_min_met( $discount_id ) &&
807
-                wpinv_discount_is_max_met( $discount_id ) &&
808
-                wpinv_discount_item_reqs_met( $discount_id )
802
+                wpinv_is_discount_active($discount_id) &&
803
+                wpinv_check_discount_dates($discount_id) &&
804
+                !wpinv_is_discount_maxed_out($discount_id) &&
805
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
806
+                wpinv_discount_is_min_met($discount_id) &&
807
+                wpinv_discount_is_max_met($discount_id) &&
808
+                wpinv_discount_item_reqs_met($discount_id)
809 809
             ) {
810 810
                 $return = true;
811 811
             }
812
-        } elseif( $set_error ) {
813
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
812
+        } elseif ($set_error) {
813
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
814 814
         }
815 815
     }
816 816
 
817
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
817
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
818 818
 }
819 819
 
820
-function wpinv_get_discount_id_by_code( $code ) {
821
-    $discount = wpinv_get_discount_by_code( $code );
822
-    if( $discount ) {
820
+function wpinv_get_discount_id_by_code($code) {
821
+    $discount = wpinv_get_discount_by_code($code);
822
+    if ($discount) {
823 823
         return $discount->ID;
824 824
     }
825 825
     return false;
826 826
 }
827 827
 
828
-function wpinv_get_discounted_amount( $code, $base_price ) {
828
+function wpinv_get_discounted_amount($code, $base_price) {
829 829
     $amount      = $base_price;
830
-    $discount_id = wpinv_get_discount_id_by_code( $code );
830
+    $discount_id = wpinv_get_discount_id_by_code($code);
831 831
 
832
-    if( $discount_id ) {
833
-        $type        = wpinv_get_discount_type( $discount_id );
834
-        $rate        = wpinv_get_discount_amount( $discount_id );
832
+    if ($discount_id) {
833
+        $type        = wpinv_get_discount_type($discount_id);
834
+        $rate        = wpinv_get_discount_amount($discount_id);
835 835
 
836
-        if ( $type == 'flat' ) {
836
+        if ($type == 'flat') {
837 837
             // Set amount
838 838
             $amount = $base_price - $rate;
839
-            if ( $amount < 0 ) {
839
+            if ($amount < 0) {
840 840
                 $amount = 0;
841 841
             }
842 842
 
843 843
         } else {
844 844
             // Percentage discount
845
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
845
+            $amount = $base_price - ($base_price * ($rate / 100));
846 846
         }
847 847
 
848 848
     } else {
@@ -851,108 +851,108 @@  discard block
 block discarded – undo
851 851
 
852 852
     }
853 853
 
854
-    return apply_filters( 'wpinv_discounted_amount', $amount );
854
+    return apply_filters('wpinv_discounted_amount', $amount);
855 855
 }
856 856
 
857
-function wpinv_increase_discount_usage( $code ) {
857
+function wpinv_increase_discount_usage($code) {
858 858
 
859
-    $id   = wpinv_get_discount_id_by_code( $code );
860
-    $uses = wpinv_get_discount_uses( $id );
859
+    $id   = wpinv_get_discount_id_by_code($code);
860
+    $uses = wpinv_get_discount_uses($id);
861 861
 
862
-    if ( $uses ) {
862
+    if ($uses) {
863 863
         $uses++;
864 864
     } else {
865 865
         $uses = 1;
866 866
     }
867 867
 
868
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
868
+    update_post_meta($id, '_wpi_discount_uses', $uses);
869 869
 
870
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
870
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
871 871
 
872 872
     return $uses;
873 873
 
874 874
 }
875 875
 
876
-function wpinv_decrease_discount_usage( $code ) {
876
+function wpinv_decrease_discount_usage($code) {
877 877
 
878
-    $id   = wpinv_get_discount_id_by_code( $code );
879
-    $uses = wpinv_get_discount_uses( $id );
878
+    $id   = wpinv_get_discount_id_by_code($code);
879
+    $uses = wpinv_get_discount_uses($id);
880 880
 
881
-    if ( $uses ) {
881
+    if ($uses) {
882 882
         $uses--;
883 883
     }
884 884
 
885
-    if ( $uses < 0 ) {
885
+    if ($uses < 0) {
886 886
         $uses = 0;
887 887
     }
888 888
 
889
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
889
+    update_post_meta($id, '_wpi_discount_uses', $uses);
890 890
 
891
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
891
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
892 892
 
893 893
     return $uses;
894 894
 
895 895
 }
896 896
 
897
-function wpinv_format_discount_rate( $type, $amount ) {
898
-    if ( $type == 'flat' ) {
899
-        return wpinv_price( wpinv_format_amount( $amount ) );
897
+function wpinv_format_discount_rate($type, $amount) {
898
+    if ($type == 'flat') {
899
+        return wpinv_price(wpinv_format_amount($amount));
900 900
     } else {
901 901
         return $amount . '%';
902 902
     }
903 903
 }
904 904
 
905
-function wpinv_set_cart_discount( $code = '' ) {    
906
-    if ( wpinv_multiple_discounts_allowed() ) {
905
+function wpinv_set_cart_discount($code = '') {    
906
+    if (wpinv_multiple_discounts_allowed()) {
907 907
         // Get all active cart discounts
908 908
         $discounts = wpinv_get_cart_discounts();
909 909
     } else {
910 910
         $discounts = false; // Only one discount allowed per purchase, so override any existing
911 911
     }
912 912
 
913
-    if ( $discounts ) {
914
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
915
-        if( false !== $key ) {
916
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
913
+    if ($discounts) {
914
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
915
+        if (false !== $key) {
916
+            unset($discounts[$key]); // Can't set the same discount more than once
917 917
         }
918 918
         $discounts[] = $code;
919 919
     } else {
920 920
         $discounts = array();
921 921
         $discounts[] = $code;
922 922
     }
923
-    $discounts = array_values( $discounts );
923
+    $discounts = array_values($discounts);
924 924
     
925 925
     $data = wpinv_get_checkout_session();
926
-    if ( empty( $data ) ) {
926
+    if (empty($data)) {
927 927
         $data = array();
928 928
     } else {
929
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
930
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
931
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
929
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
930
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
931
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
932 932
         }
933 933
     }
934 934
     $data['cart_discounts'] = $discounts;
935 935
     
936
-    wpinv_set_checkout_session( $data );
936
+    wpinv_set_checkout_session($data);
937 937
     
938 938
     return $discounts;
939 939
 }
940 940
 
941
-function wpinv_unset_cart_discount( $code = '' ) {    
941
+function wpinv_unset_cart_discount($code = '') {    
942 942
     $discounts = wpinv_get_cart_discounts();
943 943
 
944
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
945
-        $key = array_search( $code, $discounts );
946
-        unset( $discounts[ $key ] );
944
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
945
+        $key = array_search($code, $discounts);
946
+        unset($discounts[$key]);
947 947
             
948 948
         $data = wpinv_get_checkout_session();
949 949
         $data['cart_discounts'] = $discounts;
950
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
951
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
952
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
950
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
951
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
952
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
953 953
         }
954 954
         
955
-        wpinv_set_checkout_session( $data );
955
+        wpinv_set_checkout_session($data);
956 956
     }
957 957
 
958 958
     return $discounts;
@@ -961,27 +961,27 @@  discard block
 block discarded – undo
961 961
 function wpinv_unset_all_cart_discounts() {
962 962
     $data = wpinv_get_checkout_session();
963 963
     
964
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
965
-        unset( $data['cart_discounts'] );
964
+    if (!empty($data) && isset($data['cart_discounts'])) {
965
+        unset($data['cart_discounts']);
966 966
         
967
-         wpinv_set_checkout_session( $data );
967
+         wpinv_set_checkout_session($data);
968 968
          return true;
969 969
     }
970 970
     
971 971
     return false;
972 972
 }
973 973
 
974
-function wpinv_get_cart_discounts( $items = array() ) {
974
+function wpinv_get_cart_discounts($items = array()) {
975 975
     $session = wpinv_get_checkout_session();
976 976
     
977
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
977
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
978 978
     return $discounts;
979 979
 }
980 980
 
981
-function wpinv_cart_has_discounts( $items = array() ) {
981
+function wpinv_cart_has_discounts($items = array()) {
982 982
     $ret = false;
983 983
 
984
-    if ( wpinv_get_cart_discounts( $items ) ) {
984
+    if (wpinv_get_cart_discounts($items)) {
985 985
         $ret = true;
986 986
     }
987 987
     
@@ -992,131 +992,131 @@  discard block
 block discarded – undo
992 992
     }
993 993
     */
994 994
 
995
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
995
+    return apply_filters('wpinv_cart_has_discounts', $ret);
996 996
 }
997 997
 
998
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
998
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
999 999
     $amount = 0.00;
1000
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1000
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
1001 1001
 
1002
-    if ( $items ) {
1003
-        $discounts = wp_list_pluck( $items, 'discount' );
1002
+    if ($items) {
1003
+        $discounts = wp_list_pluck($items, 'discount');
1004 1004
 
1005
-        if ( is_array( $discounts ) ) {
1006
-            $discounts = array_map( 'floatval', $discounts );
1007
-            $amount    = array_sum( $discounts );
1005
+        if (is_array($discounts)) {
1006
+            $discounts = array_map('floatval', $discounts);
1007
+            $amount    = array_sum($discounts);
1008 1008
         }
1009 1009
     }
1010 1010
 
1011
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
1011
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
1012 1012
 }
1013 1013
 
1014
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
1015
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1014
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
1015
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1016 1016
     
1017
-    if ( empty( $discount ) || empty( $items ) ) {
1017
+    if (empty($discount) || empty($items)) {
1018 1018
         return 0;
1019 1019
     }
1020 1020
 
1021 1021
     $amount = 0;
1022 1022
     
1023
-    foreach ( $items as $item ) {
1024
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
1023
+    foreach ($items as $item) {
1024
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
1025 1025
     }
1026 1026
     
1027
-    $amount = wpinv_round_amount( $amount );
1027
+    $amount = wpinv_round_amount($amount);
1028 1028
 
1029 1029
     return $amount;
1030 1030
 }
1031 1031
 
1032
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
1032
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
1033 1033
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
1034 1034
     
1035 1035
     $amount = 0;
1036 1036
 
1037
-    if ( empty( $item ) || empty( $item['id'] ) ) {
1037
+    if (empty($item) || empty($item['id'])) {
1038 1038
         return $amount;
1039 1039
     }
1040 1040
 
1041
-    if ( empty( $item['quantity'] ) ) {
1041
+    if (empty($item['quantity'])) {
1042 1042
         return $amount;
1043 1043
     }
1044 1044
 
1045
-    if ( empty( $item['options'] ) ) {
1045
+    if (empty($item['options'])) {
1046 1046
         $item['options'] = array();
1047 1047
     }
1048 1048
 
1049
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
1049
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
1050 1050
     $discounted_price = $price;
1051 1051
 
1052 1052
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
1053
-    if ( empty( $discounts ) ) {
1053
+    if (empty($discounts)) {
1054 1054
         return $amount;
1055 1055
     }
1056 1056
 
1057
-    if ( $discounts ) {
1058
-        if ( is_array( $discounts ) ) {
1059
-            $discounts = array_values( $discounts );
1057
+    if ($discounts) {
1058
+        if (is_array($discounts)) {
1059
+            $discounts = array_values($discounts);
1060 1060
         } else {
1061
-            $discounts = explode( ',', $discounts );
1061
+            $discounts = explode(',', $discounts);
1062 1062
         }
1063 1063
     }
1064 1064
 
1065
-    if( $discounts ) {
1066
-        foreach ( $discounts as $discount ) {
1067
-            $code_id = wpinv_get_discount_id_by_code( $discount );
1065
+    if ($discounts) {
1066
+        foreach ($discounts as $discount) {
1067
+            $code_id = wpinv_get_discount_id_by_code($discount);
1068 1068
 
1069 1069
             // Check discount exists
1070
-            if( ! $code_id ) {
1070
+            if (!$code_id) {
1071 1071
                 continue;
1072 1072
             }
1073 1073
 
1074
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
1075
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
1074
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
1075
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
1076 1076
 
1077 1077
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1078
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1079
-                foreach ( $reqs as $item_id ) {
1080
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1081
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1078
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1079
+                foreach ($reqs as $item_id) {
1080
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1081
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1082 1082
                     }
1083 1083
                 }
1084 1084
             } else {
1085 1085
                 // This is a global cart discount
1086
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1087
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1086
+                if (!in_array($item['id'], $excluded_items)) {
1087
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1088 1088
                         $items_subtotal    = 0.00;
1089 1089
                         $cart_items        = wpinv_get_cart_contents();
1090 1090
                         
1091
-                        foreach ( $cart_items as $cart_item ) {
1092
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1093
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1094
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1091
+                        foreach ($cart_items as $cart_item) {
1092
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1093
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1094
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1095 1095
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1096 1096
                             }
1097 1097
                         }
1098 1098
 
1099
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1100
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1099
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1100
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1101 1101
                         $discounted_amount = $code_amount * $subtotal_percent;
1102 1102
                         $discounted_price -= $discounted_amount;
1103 1103
 
1104
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1104
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1105 1105
 
1106
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1106
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1107 1107
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1108 1108
                             $discounted_price -= $adjustment;
1109 1109
                         }
1110 1110
                     } else {
1111
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1111
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1112 1112
                     }
1113 1113
                 }
1114 1114
             }
1115 1115
         }
1116 1116
 
1117
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1117
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1118 1118
 
1119
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1119
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1120 1120
             $amount = $amount * $item['quantity'];
1121 1121
         }
1122 1122
     }
@@ -1124,59 +1124,59 @@  discard block
 block discarded – undo
1124 1124
     return $amount;
1125 1125
 }
1126 1126
 
1127
-function wpinv_cart_discounts_html( $items = array() ) {
1128
-    echo wpinv_get_cart_discounts_html( $items );
1127
+function wpinv_cart_discounts_html($items = array()) {
1128
+    echo wpinv_get_cart_discounts_html($items);
1129 1129
 }
1130 1130
 
1131
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1131
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1132 1132
     global $wpi_cart_columns;
1133 1133
     
1134
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1134
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1135 1135
     
1136
-    if ( !$discounts ) {
1137
-        $discounts = wpinv_get_cart_discounts( $items );
1136
+    if (!$discounts) {
1137
+        $discounts = wpinv_get_cart_discounts($items);
1138 1138
     }
1139 1139
 
1140
-    if ( !$discounts ) {
1140
+    if (!$discounts) {
1141 1141
         return;
1142 1142
     }
1143 1143
     
1144
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1144
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1145 1145
     
1146 1146
     $html = '';
1147 1147
 
1148
-    foreach ( $discounts as $discount ) {
1149
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1150
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1151
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1152
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1153
-        $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> ';
1148
+    foreach ($discounts as $discount) {
1149
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1150
+        $discount_value = wpinv_get_discount_amount($discount_id);
1151
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1152
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1153
+        $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> ';
1154 1154
         
1155 1155
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1156 1156
         ob_start();
1157
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1157
+        do_action('wpinv_checkout_table_discount_first', $items);
1158 1158
         $html .= ob_get_clean();
1159
-        $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>';
1159
+        $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>';
1160 1160
         ob_start();
1161
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1161
+        do_action('wpinv_checkout_table_discount_last', $items);
1162 1162
         $html .= ob_get_clean();
1163 1163
         $html .= '</tr>';
1164 1164
     }
1165 1165
 
1166
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1166
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1167 1167
 }
1168 1168
 
1169
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1169
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1170 1170
     $discounts = wpinv_get_cart_discounts();
1171 1171
 
1172
-    if ( empty( $discounts ) ) {
1172
+    if (empty($discounts)) {
1173 1173
         return false;
1174 1174
     }
1175 1175
 
1176
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1177
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1176
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1177
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1178 1178
 
1179
-    if ( $echo ) {
1179
+    if ($echo) {
1180 1180
         echo $amount;
1181 1181
     }
1182 1182
 
@@ -1184,101 +1184,101 @@  discard block
 block discarded – undo
1184 1184
 }
1185 1185
 
1186 1186
 function wpinv_remove_cart_discount() {
1187
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1187
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1188 1188
         return;
1189 1189
     }
1190 1190
 
1191
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1191
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1192 1192
 
1193
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1193
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1194 1194
 
1195
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1195
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1196 1196
 
1197
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1197
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1198 1198
 }
1199
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1199
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1200 1200
 
1201
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1201
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1202 1202
     $discounts = wpinv_get_cart_discounts();
1203 1203
 
1204
-    if ( !$discounts ) {
1204
+    if (!$discounts) {
1205 1205
         return;
1206 1206
     }
1207 1207
 
1208
-    foreach ( $discounts as $discount ) {
1209
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1210
-            wpinv_unset_cart_discount( $discount );
1208
+    foreach ($discounts as $discount) {
1209
+        if (!wpinv_is_discount_valid($discount)) {
1210
+            wpinv_unset_cart_discount($discount);
1211 1211
         }
1212 1212
     }
1213 1213
 }
1214
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1214
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1215 1215
 
1216 1216
 function wpinv_multiple_discounts_allowed() {
1217
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1218
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1217
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1218
+    return (bool) apply_filters('wpinv_multiple_discounts_allowed', $ret);
1219 1219
 }
1220 1220
 
1221
-function wpinv_get_discount_label( $code, $echo = true ) {
1222
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1223
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1221
+function wpinv_get_discount_label($code, $echo = true) {
1222
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1223
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1224 1224
 
1225
-    if ( $echo ) {
1225
+    if ($echo) {
1226 1226
         echo $label;
1227 1227
     } else {
1228 1228
         return $label;
1229 1229
     }
1230 1230
 }
1231 1231
 
1232
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1233
-    $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code );
1234
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1232
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1233
+    $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code);
1234
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1235 1235
 
1236
-    if ( $echo ) {
1236
+    if ($echo) {
1237 1237
         echo $label;
1238 1238
     } else {
1239 1239
         return $label;
1240 1240
     }
1241 1241
 }
1242 1242
 
1243
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1244
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1243
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1244
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1245 1245
         return true;
1246 1246
     }
1247 1247
     
1248 1248
     return $check;
1249 1249
 }
1250
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1250
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1251 1251
 
1252 1252
 function wpinv_checkout_form_validate_discounts() {
1253 1253
     global $wpi_checkout_id;
1254 1254
     
1255 1255
     $discounts = wpinv_get_cart_discounts();
1256 1256
     
1257
-    if ( !empty( $discounts ) ) {
1257
+    if (!empty($discounts)) {
1258 1258
         $invalid = false;
1259 1259
         
1260
-        foreach ( $discounts as $key => $code ) {
1261
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1260
+        foreach ($discounts as $key => $code) {
1261
+            if (!wpinv_is_discount_valid($code, (int) wpinv_get_user_id($wpi_checkout_id))) {
1262 1262
                 $invalid = true;
1263 1263
                 
1264
-                wpinv_unset_cart_discount( $code );
1264
+                wpinv_unset_cart_discount($code);
1265 1265
             }
1266 1266
         }
1267 1267
         
1268
-        if ( $invalid ) {
1268
+        if ($invalid) {
1269 1269
             $errors = wpinv_get_errors();
1270
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1271
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1272
-            wpinv_set_error( 'wpinv-discount-error', $error );
1270
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1271
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1272
+            wpinv_set_error('wpinv-discount-error', $error);
1273 1273
             
1274
-            wpinv_recalculate_tax( true );
1274
+            wpinv_recalculate_tax(true);
1275 1275
         }
1276 1276
     }
1277 1277
 }
1278
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1278
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1279 1279
 
1280 1280
 function wpinv_discount_amount() {
1281 1281
     $output = 0.00;
1282 1282
     
1283
-    return apply_filters( 'wpinv_discount_amount', $output );
1283
+    return apply_filters('wpinv_discount_amount', $output);
1284 1284
 }
1285 1285
\ No newline at end of file
Please login to merge, or discard this patch.