Passed
Push — master ( 1c83fa...651b7e )
by Brian
09:48 queued 04:43
created
includes/wpinv-discount-functions.php 1 patch
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns an array of discount type.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
     return apply_filters(
18 18
         'wpinv_discount_types',
19 19
         array(
20
-            'percent'   => __( 'Percentage', 'invoicing' ),
21
-            'flat'     => __( 'Flat Amount', 'invoicing' ),
20
+            'percent'   => __('Percentage', 'invoicing'),
21
+            'flat'     => __('Flat Amount', 'invoicing'),
22 22
         )
23 23
     );
24 24
 }
@@ -28,9 +28,9 @@  discard block
 block discarded – undo
28 28
  * 
29 29
  * @return string
30 30
  */
31
-function wpinv_get_discount_type_name( $type = '' ) {
31
+function wpinv_get_discount_type_name($type = '') {
32 32
     $types = wpinv_get_discount_types();
33
-    return isset( $types[ $type ] ) ? $types[ $type ] : $type;
33
+    return isset($types[$type]) ? $types[$type] : $type;
34 34
 }
35 35
 
36 36
 /**
@@ -38,94 +38,94 @@  discard block
 block discarded – undo
38 38
  * 
39 39
  * @return string
40 40
  */
41
-function wpinv_delete_discount( $data ) {
41
+function wpinv_delete_discount($data) {
42 42
 
43
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
44 44
         exit;
45 45
     }
46 46
 
47
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
48
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
47
+    if (!wpinv_current_user_can_manage_invoicing()) {
48
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
49 49
     }
50 50
 
51 51
     $discount_id = $data['discount'];
52
-    wpinv_remove_discount( $discount_id );
52
+    wpinv_remove_discount($discount_id);
53 53
 }
54
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
54
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
55 55
 
56
-function wpinv_activate_discount( $data ) {
57
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
58
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
56
+function wpinv_activate_discount($data) {
57
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
58
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
59 59
     }
60 60
 
61
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
62
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
61
+    if (!wpinv_current_user_can_manage_invoicing()) {
62
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
63 63
     }
64 64
 
65
-    $id = absint( $data['discount'] );
66
-    wpinv_update_discount_status( $id, 'publish' );
65
+    $id = absint($data['discount']);
66
+    wpinv_update_discount_status($id, 'publish');
67 67
 }
68
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
68
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
69 69
 
70
-function wpinv_deactivate_discount( $data ) {
71
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
72
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
70
+function wpinv_deactivate_discount($data) {
71
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
72
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
73 73
     }
74 74
 
75
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
76
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
75
+    if (!wpinv_current_user_can_manage_invoicing()) {
76
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
77 77
     }
78 78
 
79
-    $id = absint( $data['discount'] );
80
-    wpinv_update_discount_status( $id, 'pending' );
79
+    $id = absint($data['discount']);
80
+    wpinv_update_discount_status($id, 'pending');
81 81
 }
82
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
82
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
83 83
 
84
-function wpinv_get_discounts( $args = array() ) {
84
+function wpinv_get_discounts($args = array()) {
85 85
     $defaults = array(
86 86
         'post_type'      => 'wpi_discount',
87 87
         'posts_per_page' => 20,
88 88
         'paged'          => null,
89
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
89
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
90 90
     );
91 91
 
92
-    $args = wp_parse_args( $args, $defaults );
92
+    $args = wp_parse_args($args, $defaults);
93 93
 
94
-    $discounts = get_posts( $args );
94
+    $discounts = get_posts($args);
95 95
 
96
-    if ( $discounts ) {
96
+    if ($discounts) {
97 97
         return $discounts;
98 98
     }
99 99
 
100
-    if( ! $discounts && ! empty( $args['s'] ) ) {
100
+    if (!$discounts && !empty($args['s'])) {
101 101
         $args['meta_key']     = '_wpi_discount_code';
102 102
         $args['meta_value']   = $args['s'];
103 103
         $args['meta_compare'] = 'LIKE';
104
-        unset( $args['s'] );
105
-        $discounts = get_posts( $args );
104
+        unset($args['s']);
105
+        $discounts = get_posts($args);
106 106
     }
107 107
 
108
-    if( $discounts ) {
108
+    if ($discounts) {
109 109
         return $discounts;
110 110
     }
111 111
 
112 112
     return false;
113 113
 }
114 114
 
115
-function wpinv_get_all_discounts( $args = array() ) {
115
+function wpinv_get_all_discounts($args = array()) {
116 116
 
117
-    $args = wp_parse_args( $args, array(
118
-        'status'         => array( 'publish' ),
119
-        'limit'          => get_option( 'posts_per_page' ),
117
+    $args = wp_parse_args($args, array(
118
+        'status'         => array('publish'),
119
+        'limit'          => get_option('posts_per_page'),
120 120
         'page'           => 1,
121 121
         'exclude'        => array(),
122 122
         'orderby'        => 'date',
123 123
         'order'          => 'DESC',
124
-        'type'           => array_keys( wpinv_get_discount_types() ),
124
+        'type'           => array_keys(wpinv_get_discount_types()),
125 125
         'meta_query'     => array(),
126 126
         'return'         => 'objects',
127 127
         'paginate'       => false,
128
-    ) );
128
+    ));
129 129
 
130 130
     $wp_query_args = array(
131 131
         'post_type'      => 'wpi_discount',
@@ -135,18 +135,18 @@  discard block
 block discarded – undo
135 135
         'fields'         => 'ids',
136 136
         'orderby'        => $args['orderby'],
137 137
         'order'          => $args['order'],
138
-        'paged'          => absint( $args['page'] ),
138
+        'paged'          => absint($args['page']),
139 139
     );
140 140
 
141
-    if ( ! empty( $args['exclude'] ) ) {
142
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
141
+    if (!empty($args['exclude'])) {
142
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
143 143
     }
144 144
 
145
-    if ( ! $args['paginate' ] ) {
145
+    if (!$args['paginate']) {
146 146
         $wp_query_args['no_found_rows'] = true;
147 147
     }
148 148
 
149
-    if ( ! empty( $args['search'] ) ) {
149
+    if (!empty($args['search'])) {
150 150
 
151 151
         $wp_query_args['meta_query'][] = array(
152 152
             'key'     => '_wpi_discount_code',
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 
157 157
     }
158 158
 
159
-    if ( ! empty( $args['type'] ) ) {
160
-        $types = wpinv_parse_list( $args['type'] );
159
+    if (!empty($args['type'])) {
160
+        $types = wpinv_parse_list($args['type']);
161 161
         $wp_query_args['meta_query'][] = array(
162 162
             'key'     => '_wpi_discount_type',
163
-            'value'   => implode( ',', $types ),
163
+            'value'   => implode(',', $types),
164 164
             'compare' => 'IN',
165 165
         );
166 166
     }
@@ -168,17 +168,17 @@  discard block
 block discarded – undo
168 168
     $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args);
169 169
 
170 170
     // Get results.
171
-    $discounts = new WP_Query( $wp_query_args );
171
+    $discounts = new WP_Query($wp_query_args);
172 172
 
173
-    if ( 'objects' === $args['return'] ) {
174
-        $return = array_map( 'get_post', $discounts->posts );
175
-    } elseif ( 'self' === $args['return'] ) {
173
+    if ('objects' === $args['return']) {
174
+        $return = array_map('get_post', $discounts->posts);
175
+    } elseif ('self' === $args['return']) {
176 176
         return $discounts;
177 177
     } else {
178 178
         $return = $discounts->posts;
179 179
     }
180 180
 
181
-    if ( $args['paginate' ] ) {
181
+    if ($args['paginate']) {
182 182
         return (object) array(
183 183
             'discounts'      => $return,
184 184
             'total'         => $discounts->found_posts,
@@ -195,9 +195,9 @@  discard block
 block discarded – undo
195 195
 
196 196
     $discounts  = wpinv_get_discounts();
197 197
 
198
-    if ( $discounts) {
199
-        foreach ( $discounts as $discount ) {
200
-            if ( wpinv_is_discount_active( $discount->ID, true ) ) {
198
+    if ($discounts) {
199
+        foreach ($discounts as $discount) {
200
+            if (wpinv_is_discount_active($discount->ID, true)) {
201 201
                 $has_active = true;
202 202
                 break;
203 203
             }
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
     return $has_active;
207 207
 }
208 208
 
209
-function wpinv_get_discount( $discount_id = 0 ) {
210
-    if( empty( $discount_id ) ) {
209
+function wpinv_get_discount($discount_id = 0) {
210
+    if (empty($discount_id)) {
211 211
         return false;
212 212
     }
213 213
 
214
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
214
+    if (get_post_type($discount_id) != 'wpi_discount') {
215 215
         return false;
216 216
     }
217 217
 
218
-    $discount = get_post( $discount_id );
218
+    $discount = get_post($discount_id);
219 219
 
220 220
     return $discount;
221 221
 }
@@ -227,8 +227,8 @@  discard block
 block discarded – undo
227 227
  * @since 1.0.15
228 228
  * @return WPInv_Discount
229 229
  */
230
-function wpinv_get_discount_obj( $discount = 0 ) {
231
-    return new WPInv_Discount( $discount );
230
+function wpinv_get_discount_obj($discount = 0) {
231
+    return new WPInv_Discount($discount);
232 232
 }
233 233
 
234 234
 /**
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
  * @param string $code The discount code.
238 238
  * @return bool|WPInv_Discount
239 239
  */
240
-function wpinv_get_discount_by_code( $code = '' ) {
241
-    return wpinv_get_discount_by( null, $code );
240
+function wpinv_get_discount_by_code($code = '') {
241
+    return wpinv_get_discount_by(null, $code);
242 242
 }
243 243
 
244 244
 /**
@@ -248,10 +248,10 @@  discard block
 block discarded – undo
248 248
  * @param string|int $value The field value
249 249
  * @return bool|WPInv_Discount
250 250
  */
251
-function wpinv_get_discount_by( $deprecated = null, $value = '' ) {
252
-    $discount = new WPInv_Discount( $value );
251
+function wpinv_get_discount_by($deprecated = null, $value = '') {
252
+    $discount = new WPInv_Discount($value);
253 253
 
254
-    if ( $discount->get_id() != 0 ) {
254
+    if ($discount->get_id() != 0) {
255 255
         return $discount;
256 256
     }
257 257
 
@@ -265,68 +265,68 @@  discard block
 block discarded – undo
265 265
  * @param array $data The discount's properties.
266 266
  * @return bool
267 267
  */
268
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
268
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
269 269
     $meta = array(
270
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
271
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
272
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
273
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
274
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
275
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
276
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
277
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
278
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
279
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
280
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
281
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
282
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
270
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
271
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
272
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
273
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
274
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
275
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
276
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
277
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
278
+        'items'             => isset($data['items']) ? $data['items'] : array(),
279
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
280
+        'is_recurring'      => isset($data['recurring']) ? (bool) $data['recurring'] : false,
281
+        'is_single_use'     => isset($data['single_use']) ? (bool) $data['single_use'] : false,
282
+        'uses'              => isset($data['uses']) ? (int) $data['uses'] : false,
283 283
     );
284 284
 
285
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
285
+    if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) {
286 286
         $meta['amount'] = 100;
287 287
     }
288 288
 
289
-    if ( !empty( $meta['start'] ) ) {
290
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
289
+    if (!empty($meta['start'])) {
290
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
291 291
     }
292 292
 
293
-    if ( !empty( $meta['expiration'] ) ) {
294
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
293
+    if (!empty($meta['expiration'])) {
294
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
295 295
 
296
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
296
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
297 297
             $meta['expiration'] = $meta['start'];
298 298
         }
299 299
     }
300 300
 
301
-    if ( $meta['uses'] === false ) {
302
-        unset( $meta['uses'] );
301
+    if ($meta['uses'] === false) {
302
+        unset($meta['uses']);
303 303
     }
304 304
 
305
-    if ( ! empty( $meta['items'] ) ) {
306
-        foreach ( $meta['items'] as $key => $item ) {
307
-            if ( 0 === intval( $item ) ) {
308
-                unset( $meta['items'][ $key ] );
305
+    if (!empty($meta['items'])) {
306
+        foreach ($meta['items'] as $key => $item) {
307
+            if (0 === intval($item)) {
308
+                unset($meta['items'][$key]);
309 309
             }
310 310
         }
311 311
     }
312 312
 
313
-    if ( ! empty( $meta['excluded_items'] ) ) {
314
-        foreach ( $meta['excluded_items'] as $key => $item ) {
315
-            if ( 0 === intval( $item ) ) {
316
-                unset( $meta['excluded_items'][ $key ] );
313
+    if (!empty($meta['excluded_items'])) {
314
+        foreach ($meta['excluded_items'] as $key => $item) {
315
+            if (0 === intval($item)) {
316
+                unset($meta['excluded_items'][$key]);
317 317
             }
318 318
         }
319 319
     }
320 320
 
321
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
321
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
322 322
 
323
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
323
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
324 324
 
325
-    foreach( $meta as $key => $value ) {
326
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
325
+    foreach ($meta as $key => $value) {
326
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
327 327
     }
328 328
 
329
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
329
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
330 330
 
331 331
     return $post_id;
332 332
 }
@@ -337,10 +337,10 @@  discard block
 block discarded – undo
337 337
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
338 338
  * @return bool
339 339
  */
340
-function wpinv_remove_discount( $discount = 0 ) {
340
+function wpinv_remove_discount($discount = 0) {
341 341
 
342
-    $discount = wpinv_get_discount_obj( $discount );
343
-    if( ! $discount->exists() ) {
342
+    $discount = wpinv_get_discount_obj($discount);
343
+    if (!$discount->exists()) {
344 344
         return false;
345 345
     }
346 346
 
@@ -355,9 +355,9 @@  discard block
 block discarded – undo
355 355
  * @param string $new_status
356 356
  * @return bool
357 357
  */
358
-function wpinv_update_discount_status( $discount = 0, $new_status = 'publish' ) {
359
-    $discount = wpinv_get_discount_obj( $discount );
360
-    return $discount->update_status( $new_status );
358
+function wpinv_update_discount_status($discount = 0, $new_status = 'publish') {
359
+    $discount = wpinv_get_discount_obj($discount);
360
+    return $discount->update_status($new_status);
361 361
 }
362 362
 
363 363
 /**
@@ -366,48 +366,48 @@  discard block
 block discarded – undo
366 366
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
367 367
  * @return bool
368 368
  */
369
-function wpinv_discount_exists( $discount ) {
370
-    $discount = wpinv_get_discount_obj( $discount );
369
+function wpinv_discount_exists($discount) {
370
+    $discount = wpinv_get_discount_obj($discount);
371 371
     return $discount->exists();
372 372
 }
373 373
 
374
-function wpinv_is_discount_active( $code_id = null, $silent = false ) {
375
-    $discount = wpinv_get_discount(  $code_id );
374
+function wpinv_is_discount_active($code_id = null, $silent = false) {
375
+    $discount = wpinv_get_discount($code_id);
376 376
     $return   = false;
377 377
 
378
-    if ( $discount ) {
379
-        if ( wpinv_is_discount_expired( $code_id, $silent ) ) {
380
-            if( defined( 'DOING_AJAX' ) && ! $silent ) {
381
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
378
+    if ($discount) {
379
+        if (wpinv_is_discount_expired($code_id, $silent)) {
380
+            if (defined('DOING_AJAX') && !$silent) {
381
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
382 382
             }
383
-        } elseif ( $discount->post_status == 'publish' ) {
383
+        } elseif ($discount->post_status == 'publish') {
384 384
             $return = true;
385 385
         } else {
386
-            if( defined( 'DOING_AJAX' ) && ! $silent ) {
387
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
386
+            if (defined('DOING_AJAX') && !$silent) {
387
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
388 388
             }
389 389
         }
390 390
     }
391 391
 
392
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
392
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
393 393
 }
394 394
 
395
-function wpinv_get_discount_code( $code_id = null ) {
396
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
395
+function wpinv_get_discount_code($code_id = null) {
396
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
397 397
 
398
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
398
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
399 399
 }
400 400
 
401
-function wpinv_get_discount_start_date( $code_id = null ) {
402
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
401
+function wpinv_get_discount_start_date($code_id = null) {
402
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
403 403
 
404
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
404
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
405 405
 }
406 406
 
407
-function wpinv_get_discount_expiration( $code_id = null ) {
408
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
407
+function wpinv_get_discount_expiration($code_id = null) {
408
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
409 409
 
410
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
410
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
411 411
 }
412 412
 
413 413
 /**
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
417 417
  * @return int
418 418
  */
419
-function wpinv_get_discount_max_uses( $discount = array() ) {
420
-    $discount = wpinv_get_discount_obj( $discount );
419
+function wpinv_get_discount_max_uses($discount = array()) {
420
+    $discount = wpinv_get_discount_obj($discount);
421 421
     return (int) $discount->max_uses;
422 422
 }
423 423
 
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
428 428
  * @return int
429 429
  */
430
-function wpinv_get_discount_uses( $discount = array() ) {
431
-    $discount = wpinv_get_discount_obj( $discount );
430
+function wpinv_get_discount_uses($discount = array()) {
431
+    $discount = wpinv_get_discount_obj($discount);
432 432
     return (int) $discount->uses;
433 433
 }
434 434
 
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
439 439
  * @return float
440 440
  */
441
-function wpinv_get_discount_min_total( $discount = array() ) {
442
-    $discount = wpinv_get_discount_obj( $discount );
441
+function wpinv_get_discount_min_total($discount = array()) {
442
+    $discount = wpinv_get_discount_obj($discount);
443 443
     return (float) $discount->min_total;
444 444
 }
445 445
 
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
450 450
  * @return float
451 451
  */
452
-function wpinv_get_discount_max_total( $discount = array() ) {
453
-    $discount = wpinv_get_discount_obj( $discount );
452
+function wpinv_get_discount_max_total($discount = array()) {
453
+    $discount = wpinv_get_discount_obj($discount);
454 454
     return (float) $discount->max_total;
455 455
 }
456 456
 
@@ -460,8 +460,8 @@  discard block
 block discarded – undo
460 460
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
461 461
  * @return float
462 462
  */
463
-function wpinv_get_discount_amount( $discount = array() ) {
464
-    $discount = wpinv_get_discount_obj( $discount );
463
+function wpinv_get_discount_amount($discount = array()) {
464
+    $discount = wpinv_get_discount_obj($discount);
465 465
     return (float) $discount->amount;
466 466
 }
467 467
 
@@ -472,28 +472,28 @@  discard block
 block discarded – undo
472 472
  * @param bool $name
473 473
  * @return string
474 474
  */
475
-function wpinv_get_discount_type( $discount = array(), $name = false ) {
476
-    $discount = wpinv_get_discount_obj( $discount );
475
+function wpinv_get_discount_type($discount = array(), $name = false) {
476
+    $discount = wpinv_get_discount_obj($discount);
477 477
 
478 478
     // Are we returning the name or just the type.
479
-    if( $name ) {
479
+    if ($name) {
480 480
         return $discount->type_name;
481 481
     }
482 482
 
483 483
     return $discount->type;
484 484
 }
485 485
 
486
-function wpinv_discount_status( $status ) {
487
-    switch( $status ){
486
+function wpinv_discount_status($status) {
487
+    switch ($status) {
488 488
         case 'expired' :
489
-            $name = __( 'Expired', 'invoicing' );
489
+            $name = __('Expired', 'invoicing');
490 490
             break;
491 491
         case 'publish' :
492 492
         case 'active' :
493
-            $name = __( 'Active', 'invoicing' );
493
+            $name = __('Active', 'invoicing');
494 494
             break;
495 495
         default :
496
-            $name = __( 'Inactive', 'invoicing' );
496
+            $name = __('Inactive', 'invoicing');
497 497
             break;
498 498
     }
499 499
     return $name;
@@ -505,8 +505,8 @@  discard block
 block discarded – undo
505 505
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
506 506
  * @return array
507 507
  */
508
-function wpinv_get_discount_excluded_items( $discount = array() ) {
509
-    $discount = wpinv_get_discount_obj( $discount );
508
+function wpinv_get_discount_excluded_items($discount = array()) {
509
+    $discount = wpinv_get_discount_obj($discount);
510 510
     return $discount->excluded_items;
511 511
 }
512 512
 
@@ -516,17 +516,17 @@  discard block
 block discarded – undo
516 516
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
517 517
  * @return array
518 518
  */
519
-function wpinv_get_discount_item_reqs( $discount = array() ) {
520
-    $discount = wpinv_get_discount_obj( $discount );
519
+function wpinv_get_discount_item_reqs($discount = array()) {
520
+    $discount = wpinv_get_discount_obj($discount);
521 521
     return $discount->items;
522 522
 }
523 523
 
524
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
525
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
524
+function wpinv_get_discount_item_condition($code_id = 0) {
525
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
526 526
 }
527 527
 
528
-function wpinv_is_discount_not_global( $code_id = 0 ) {
529
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
528
+function wpinv_is_discount_not_global($code_id = 0) {
529
+    return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true);
530 530
 }
531 531
 
532 532
 /**
@@ -535,14 +535,14 @@  discard block
 block discarded – undo
535 535
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
536 536
  * @return bool
537 537
  */
538
-function wpinv_is_discount_expired( $discount = array(), $silent = false ) {
539
-    $discount = wpinv_get_discount_obj( $discount );
538
+function wpinv_is_discount_expired($discount = array(), $silent = false) {
539
+    $discount = wpinv_get_discount_obj($discount);
540 540
 
541
-    if ( $discount->is_expired() ) {
542
-        $discount->update_status( 'pending' );
541
+    if ($discount->is_expired()) {
542
+        $discount->update_status('pending');
543 543
 
544
-        if( empty( $silent ) ) {
545
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has expired.', 'invoicing' ) );
544
+        if (empty($silent)) {
545
+            wpinv_set_error('wpinv-discount-error', __('This discount has expired.', 'invoicing'));
546 546
         }
547 547
         return true;
548 548
     }
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
557 557
  * @return bool
558 558
  */
559
-function wpinv_is_discount_started( $discount = array() ) {
560
-    $discount = wpinv_get_discount_obj( $discount );
559
+function wpinv_is_discount_started($discount = array()) {
560
+    $discount = wpinv_get_discount_obj($discount);
561 561
     $started  = $discount->has_started();
562 562
 
563
-    if( empty( $started ) ) {
564
-        wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
563
+    if (empty($started)) {
564
+        wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
565 565
     }
566 566
 
567 567
     return $started;
@@ -573,10 +573,10 @@  discard block
 block discarded – undo
573 573
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
574 574
  * @return bool
575 575
  */
576
-function wpinv_check_discount_dates( $discount ) {
577
-    $discount = wpinv_get_discount_obj( $discount );
578
-    $return   = wpinv_is_discount_started( $discount ) && ! wpinv_is_discount_expired( $discount );
579
-    return apply_filters( 'wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code );
576
+function wpinv_check_discount_dates($discount) {
577
+    $discount = wpinv_get_discount_obj($discount);
578
+    $return   = wpinv_is_discount_started($discount) && !wpinv_is_discount_expired($discount);
579
+    return apply_filters('wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code);
580 580
 }
581 581
 
582 582
 /**
@@ -585,12 +585,12 @@  discard block
 block discarded – undo
585 585
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
586 586
  * @return bool
587 587
  */
588
-function wpinv_is_discount_maxed_out( $discount ) {
589
-    $discount    = wpinv_get_discount_obj( $discount );
588
+function wpinv_is_discount_maxed_out($discount) {
589
+    $discount    = wpinv_get_discount_obj($discount);
590 590
     $maxed_out   = $discount->has_exceeded_limit();
591 591
 
592
-    if ( $maxed_out ) {
593
-        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
592
+    if ($maxed_out) {
593
+        wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
594 594
     }
595 595
 
596 596
     return $maxed_out;
@@ -603,9 +603,9 @@  discard block
 block discarded – undo
603 603
  * @param float $amount The amount to check for.
604 604
  * @return bool
605 605
  */
606
-function wpinv_discount_is_min_met( $discount, $amount = 0 ) {
607
-    $discount = wpinv_get_discount_obj( $discount );
608
-    return $discount->is_minimum_amount_met( $amount );
606
+function wpinv_discount_is_min_met($discount, $amount = 0) {
607
+    $discount = wpinv_get_discount_obj($discount);
608
+    return $discount->is_minimum_amount_met($amount);
609 609
 }
610 610
 
611 611
 /**
@@ -614,13 +614,13 @@  discard block
 block discarded – undo
614 614
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
615 615
  * @return bool
616 616
  */
617
-function wpinv_discount_is_max_met( $discount ) {
618
-    $discount    = wpinv_get_discount_obj( $discount );
619
-    $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID );
620
-    $max_met     = $discount->is_maximum_amount_met( $cart_amount );
617
+function wpinv_discount_is_max_met($discount) {
618
+    $discount    = wpinv_get_discount_obj($discount);
619
+    $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID);
620
+    $max_met     = $discount->is_maximum_amount_met($cart_amount);
621 621
 
622
-    if ( ! $max_met ) {
623
-        wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->max_total ) ) ) );
622
+    if (!$max_met) {
623
+        wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->max_total))));
624 624
     }
625 625
 
626 626
     return $max_met;
@@ -632,8 +632,8 @@  discard block
 block discarded – undo
632 632
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
633 633
  * @return bool
634 634
  */
635
-function wpinv_discount_is_single_use( $discount ) {
636
-    $discount    = wpinv_get_discount_obj( $discount );
635
+function wpinv_discount_is_single_use($discount) {
636
+    $discount = wpinv_get_discount_obj($discount);
637 637
     return $discount->is_single_use;
638 638
 }
639 639
 
@@ -644,53 +644,53 @@  discard block
 block discarded – undo
644 644
  * @param int|array|string|WPInv_Discount $code discount data, object, ID or code.
645 645
  * @return bool
646 646
  */
647
-function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) {
647
+function wpinv_discount_is_recurring($discount = 0, $code = 0) {
648 648
 
649
-    if( ! empty( $discount ) ) {
650
-        $discount    = wpinv_get_discount_obj( $discount );
649
+    if (!empty($discount)) {
650
+        $discount    = wpinv_get_discount_obj($discount);
651 651
     } else {
652
-        $discount    = wpinv_get_discount_obj( $code );
652
+        $discount    = wpinv_get_discount_obj($code);
653 653
     }
654 654
 
655 655
     return $discount->get_is_recurring();
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,15 +716,15 @@  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 730
 /**
@@ -735,54 +735,54 @@  discard block
 block discarded – undo
735 735
  * @param int|array|string|WPInv_Discount $code_id discount data, object, ID or code.
736 736
  * @return bool
737 737
  */
738
-function wpinv_is_discount_used( $discount = array(), $user = '', $code_id = array() ) {
738
+function wpinv_is_discount_used($discount = array(), $user = '', $code_id = array()) {
739 739
 
740
-    if( ! empty( $discount ) ) {
741
-        $discount = wpinv_get_discount_obj( $discount );
740
+    if (!empty($discount)) {
741
+        $discount = wpinv_get_discount_obj($discount);
742 742
     } else {
743
-        $discount = wpinv_get_discount_obj( $code_id );
743
+        $discount = wpinv_get_discount_obj($code_id);
744 744
     }
745 745
 
746
-    $is_used = ! $discount->is_valid_for_user( $user );
747
-    $is_used = apply_filters( 'wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount );
746
+    $is_used = !$discount->is_valid_for_user($user);
747
+    $is_used = apply_filters('wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount);
748 748
 
749
-    if( $is_used ) {
750
-        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
749
+    if ($is_used) {
750
+        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
751 751
     }
752 752
 
753 753
     return $is_used;
754 754
 }
755 755
 
756
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
756
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
757 757
 
758 758
     // Abort early if there is no discount code.
759
-    if ( empty( $code ) ) {
759
+    if (empty($code)) {
760 760
         return false;
761 761
     }
762 762
 
763 763
     $return      = false;
764
-    $discount_id = wpinv_get_discount_id_by_code( $code );
765
-    $user        = trim( $user );
764
+    $discount_id = wpinv_get_discount_id_by_code($code);
765
+    $user        = trim($user);
766 766
 
767
-    if ( wpinv_get_cart_contents() ) {
768
-        if ( $discount_id !== false ) {
767
+    if (wpinv_get_cart_contents()) {
768
+        if ($discount_id !== false) {
769 769
             if (
770
-                wpinv_is_discount_active( $discount_id ) &&
771
-                wpinv_check_discount_dates( $discount_id ) &&
772
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
773
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
774
-                wpinv_discount_is_min_met( $discount_id ) &&
775
-                wpinv_discount_is_max_met( $discount_id ) &&
776
-                wpinv_discount_item_reqs_met( $discount_id )
770
+                wpinv_is_discount_active($discount_id) &&
771
+                wpinv_check_discount_dates($discount_id) &&
772
+                !wpinv_is_discount_maxed_out($discount_id) &&
773
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
774
+                wpinv_discount_is_min_met($discount_id) &&
775
+                wpinv_discount_is_max_met($discount_id) &&
776
+                wpinv_discount_item_reqs_met($discount_id)
777 777
             ) {
778 778
                 $return = true;
779 779
             }
780
-        } elseif( $set_error ) {
781
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
780
+        } elseif ($set_error) {
781
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
782 782
         }
783 783
     }
784 784
 
785
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
785
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
786 786
 }
787 787
 
788 788
 /**
@@ -791,9 +791,9 @@  discard block
 block discarded – undo
791 791
  * @param string $code
792 792
  * @return bool|false
793 793
  */
794
-function wpinv_get_discount_id_by_code( $code ) {
795
-    $discount = wpinv_get_discount_by_code( $code );
796
-    if ( $discount ) {
794
+function wpinv_get_discount_id_by_code($code) {
795
+    $discount = wpinv_get_discount_by_code($code);
796
+    if ($discount) {
797 797
         return $discount->get_id();
798 798
     }
799 799
     return false;
@@ -806,9 +806,9 @@  discard block
 block discarded – undo
806 806
  * @param float $base_price The number of usages to increase by
807 807
  * @return float
808 808
  */
809
-function wpinv_get_discounted_amount( $discount, $base_price ) {
810
-    $discount = wpinv_get_discount_obj( $discount );
811
-    return $discount->get_discounted_amount( $base_price );
809
+function wpinv_get_discounted_amount($discount, $base_price) {
810
+    $discount = wpinv_get_discount_obj($discount);
811
+    return $discount->get_discounted_amount($base_price);
812 812
 }
813 813
 
814 814
 /**
@@ -818,9 +818,9 @@  discard block
 block discarded – undo
818 818
  * @param int $by The number of usages to increase by.
819 819
  * @return int the new number of uses.
820 820
  */
821
-function wpinv_increase_discount_usage( $discount, $by = 1 ) {
822
-    $discount   = wpinv_get_discount_obj( $discount );
823
-    return $discount->increase_usage( $by );
821
+function wpinv_increase_discount_usage($discount, $by = 1) {
822
+    $discount = wpinv_get_discount_obj($discount);
823
+    return $discount->increase_usage($by);
824 824
 }
825 825
 
826 826
 /**
@@ -830,28 +830,28 @@  discard block
 block discarded – undo
830 830
  * @param int $by The number of usages to decrease by.
831 831
  * @return int the new number of uses.
832 832
  */
833
-function wpinv_decrease_discount_usage( $discount, $by = 1 ) {
834
-    $discount   = wpinv_get_discount_obj( $discount );
835
-    return $discount->increase_usage( 0 - $by );
833
+function wpinv_decrease_discount_usage($discount, $by = 1) {
834
+    $discount = wpinv_get_discount_obj($discount);
835
+    return $discount->increase_usage(0 - $by);
836 836
 }
837 837
 
838
-function wpinv_format_discount_rate( $type, $amount ) {
839
-    if ( $type == 'flat' ) {
840
-        $rate = wpinv_price( wpinv_format_amount( $amount ) );
838
+function wpinv_format_discount_rate($type, $amount) {
839
+    if ($type == 'flat') {
840
+        $rate = wpinv_price(wpinv_format_amount($amount));
841 841
     } else {
842 842
         $rate = $amount . '%';
843 843
     }
844 844
 
845
-    return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount );
845
+    return apply_filters('wpinv_format_discount_rate', $rate, $type, $amount);
846 846
 }
847 847
 
848 848
 function wpinv_unset_all_cart_discounts() {
849 849
     $data = wpinv_get_checkout_session();
850 850
 
851
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
852
-        unset( $data['cart_discounts'] );
851
+    if (!empty($data) && isset($data['cart_discounts'])) {
852
+        unset($data['cart_discounts']);
853 853
 
854
-         wpinv_set_checkout_session( $data );
854
+         wpinv_set_checkout_session($data);
855 855
          return true;
856 856
     }
857 857
 
@@ -860,13 +860,13 @@  discard block
 block discarded – undo
860 860
 
861 861
 function wpinv_get_cart_discounts() {
862 862
     $session = wpinv_get_checkout_session();
863
-    return empty( $session['cart_discounts'] ) ? false : $session['cart_discounts'];
863
+    return empty($session['cart_discounts']) ? false : $session['cart_discounts'];
864 864
 }
865 865
 
866
-function wpinv_cart_has_discounts( $items = array() ) {
866
+function wpinv_cart_has_discounts($items = array()) {
867 867
     $ret = false;
868 868
 
869
-    if ( wpinv_get_cart_discounts( $items ) ) {
869
+    if (wpinv_get_cart_discounts($items)) {
870 870
         $ret = true;
871 871
     }
872 872
 
@@ -877,49 +877,49 @@  discard block
 block discarded – undo
877 877
     }
878 878
     */
879 879
 
880
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
880
+    return apply_filters('wpinv_cart_has_discounts', $ret);
881 881
 }
882 882
 
883
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
883
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
884 884
     $amount = 0.00;
885
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
885
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
886 886
 
887
-    if ( $items ) {
888
-        $discounts = wp_list_pluck( $items, 'discount' );
887
+    if ($items) {
888
+        $discounts = wp_list_pluck($items, 'discount');
889 889
 
890
-        if ( is_array( $discounts ) ) {
891
-            $discounts = array_map( 'floatval', $discounts );
892
-            $amount    = array_sum( $discounts );
890
+        if (is_array($discounts)) {
891
+            $discounts = array_map('floatval', $discounts);
892
+            $amount    = array_sum($discounts);
893 893
         }
894 894
     }
895 895
 
896
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
896
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
897 897
 }
898 898
 
899
-function wpinv_get_discount_label( $code, $echo = true ) {
900
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
901
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
899
+function wpinv_get_discount_label($code, $echo = true) {
900
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
901
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
902 902
 
903
-    if ( $echo ) {
903
+    if ($echo) {
904 904
         echo $label;
905 905
     } else {
906 906
         return $label;
907 907
     }
908 908
 }
909 909
 
910
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
911
-    $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code );
912
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
910
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
911
+    $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code);
912
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
913 913
 
914
-    if ( $echo ) {
914
+    if ($echo) {
915 915
         echo $label;
916 916
     } else {
917 917
         return $label;
918 918
     }
919 919
 }
920 920
 
921
-function wpinv_check_delete_discount( $check, $post ) {
922
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
921
+function wpinv_check_delete_discount($check, $post) {
922
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
923 923
         return true;
924 924
     }
925 925
 
@@ -929,5 +929,5 @@  discard block
 block discarded – undo
929 929
 function wpinv_discount_amount() {
930 930
     $output = 0.00;
931 931
 
932
-    return apply_filters( 'wpinv_discount_amount', $output );
932
+    return apply_filters('wpinv_discount_amount', $output);
933 933
 }
Please login to merge, or discard this patch.
includes/deprecated-functions.php 1 patch
Spacing   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * @deprecated
@@ -19,48 +19,48 @@  discard block
 block discarded – undo
19 19
  * @deprecated
20 20
  */
21 21
 function wpinv_get_invoice_cart() {
22
-    return wpinv_get_invoice( getpaid_get_current_invoice_id() );
22
+    return wpinv_get_invoice(getpaid_get_current_invoice_id());
23 23
 }
24 24
 
25 25
 /**
26 26
  * @deprecated
27 27
  */
28
-function wpinv_get_invoice_description( $invoice ) {
29
-    $invoice = new WPInv_Invoice( $invoice );
28
+function wpinv_get_invoice_description($invoice) {
29
+    $invoice = new WPInv_Invoice($invoice);
30 30
     return $invoice->get_description();
31 31
 }
32 32
 
33 33
 /**
34 34
  * @deprecated
35 35
  */
36
-function wpinv_get_invoice_currency_code( $invoice ) {
37
-    $invoice = new WPInv_Invoice( $invoice );
36
+function wpinv_get_invoice_currency_code($invoice) {
37
+    $invoice = new WPInv_Invoice($invoice);
38 38
     return $invoice->get_currency();
39 39
 }
40 40
 
41 41
 /**
42 42
  * @deprecated
43 43
  */
44
-function wpinv_get_payment_user_email( $invoice ) {
45
-    $invoice = new WPInv_Invoice( $invoice );
44
+function wpinv_get_payment_user_email($invoice) {
45
+    $invoice = new WPInv_Invoice($invoice);
46 46
     return $invoice->get_email();
47 47
 }
48 48
 
49 49
 /**
50 50
  * @deprecated
51 51
  */
52
-function wpinv_get_user_id( $invoice ) {
53
-    $invoice = new WPInv_Invoice( $invoice );
52
+function wpinv_get_user_id($invoice) {
53
+    $invoice = new WPInv_Invoice($invoice);
54 54
     return $invoice->get_user_id();
55 55
 }
56 56
 
57 57
 /**
58 58
  * @deprecated
59 59
  */
60
-function wpinv_get_invoice_status( $invoice, $return_label = false ) {
61
-    $invoice = new WPInv_Invoice( $invoice );
60
+function wpinv_get_invoice_status($invoice, $return_label = false) {
61
+    $invoice = new WPInv_Invoice($invoice);
62 62
     
63
-    if ( $return_label ) {
63
+    if ($return_label) {
64 64
         return $invoice->get_status_nicename();
65 65
     }
66 66
 
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 /**
71 71
  * @deprecated
72 72
  */
73
-function wpinv_get_payment_gateway( $invoice, $return_label = false ) {
74
-    $invoice = new WPInv_Invoice( $invoice );
73
+function wpinv_get_payment_gateway($invoice, $return_label = false) {
74
+    $invoice = new WPInv_Invoice($invoice);
75 75
 
76
-    if ( $return_label ) {
76
+    if ($return_label) {
77 77
         return $invoice->get_gateway_title();
78 78
     }
79 79
 
@@ -83,75 +83,75 @@  discard block
 block discarded – undo
83 83
 /**
84 84
  * @deprecated
85 85
  */
86
-function wpinv_get_payment_gateway_name( $invoice ) {
87
-    return wpinv_get_payment_gateway( $invoice, true );
86
+function wpinv_get_payment_gateway_name($invoice) {
87
+    return wpinv_get_payment_gateway($invoice, true);
88 88
 }
89 89
 
90 90
 /**
91 91
  * @deprecated
92 92
  */
93
-function wpinv_get_payment_transaction_id( $invoice ) {
94
-    $invoice = new WPInv_Invoice( $invoice );
93
+function wpinv_get_payment_transaction_id($invoice) {
94
+    $invoice = new WPInv_Invoice($invoice);
95 95
     return $invoice->get_transaction_id();
96 96
 }
97 97
 
98 98
 /**
99 99
  * @deprecated
100 100
  */
101
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
102
-    $invoice = new WPInv_Invoice( $invoice_id );
103
-    return $invoice->get_meta( $meta_key, $single );
101
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
102
+    $invoice = new WPInv_Invoice($invoice_id);
103
+    return $invoice->get_meta($meta_key, $single);
104 104
 }
105 105
 
106 106
 /**
107 107
  * @deprecated
108 108
  */
109
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) {
110
-    $invoice = new WPInv_Invoice( $invoice_id );
111
-    return $invoice->update_meta_data( $meta_key, $meta_value );
109
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') {
110
+    $invoice = new WPInv_Invoice($invoice_id);
111
+    return $invoice->update_meta_data($meta_key, $meta_value);
112 112
 }
113 113
 
114 114
 /**
115 115
  * @deprecated
116 116
  */
117
-function wpinv_get_items( $invoice = 0 ) {
118
-    $invoice = new WPInv_Invoice( $invoice );
117
+function wpinv_get_items($invoice = 0) {
118
+    $invoice = new WPInv_Invoice($invoice);
119 119
     return $invoice->get_items();
120 120
 }
121 121
 
122 122
 /**
123 123
  * @deprecated
124 124
  */
125
-function wpinv_get_fees( $invoice = 0 ) {
126
-    $invoice = new WPInv_Invoice( $invoice );
125
+function wpinv_get_fees($invoice = 0) {
126
+    $invoice = new WPInv_Invoice($invoice);
127 127
     return $invoice->get_fees();
128 128
 }
129 129
 
130 130
 /**
131 131
  * @deprecated
132 132
  */
133
-function wpinv_get_invoice_ip( $invoice ) {
134
-    $invoice = new WPInv_Invoice( $invoice );
133
+function wpinv_get_invoice_ip($invoice) {
134
+    $invoice = new WPInv_Invoice($invoice);
135 135
     return $invoice->get_ip();
136 136
 }
137 137
 
138 138
 /**
139 139
  * @deprecated
140 140
  */
141
-function wpinv_get_invoice_user_info( $invoice ) {
142
-    $invoice = new WPInv_Invoice( $invoice );
141
+function wpinv_get_invoice_user_info($invoice) {
142
+    $invoice = new WPInv_Invoice($invoice);
143 143
     return $invoice->get_user_info();
144 144
 }
145 145
 
146 146
 /**
147 147
  * @deprecated
148 148
  */
149
-function wpinv_subtotal( $invoice = 0, $currency = false ) {
150
-    $invoice  = new WPInv_Invoice( $invoice );
149
+function wpinv_subtotal($invoice = 0, $currency = false) {
150
+    $invoice  = new WPInv_Invoice($invoice);
151 151
     $subtotal = $invoice->get_subtotal();
152 152
 
153
-    if ( $currency ) {
154
-        return wpinv_price( wpinv_format_amount( $subtotal ), $invoice->get_currency() );
153
+    if ($currency) {
154
+        return wpinv_price(wpinv_format_amount($subtotal), $invoice->get_currency());
155 155
     }
156 156
 
157 157
     return $subtotal;
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 /**
161 161
  * @deprecated
162 162
  */
163
-function wpinv_tax( $invoice = 0, $currency = false ) {
164
-    $invoice  = new WPInv_Invoice( $invoice );
163
+function wpinv_tax($invoice = 0, $currency = false) {
164
+    $invoice  = new WPInv_Invoice($invoice);
165 165
     $tax      = $invoice->get_total_tax();
166 166
 
167
-    if ( $currency ) {
168
-        return wpinv_price( wpinv_format_amount( $tax ), $invoice->get_currency() );
167
+    if ($currency) {
168
+        return wpinv_price(wpinv_format_amount($tax), $invoice->get_currency());
169 169
     }
170 170
 
171 171
     return $tax;
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 /**
175 175
  * @deprecated
176 176
  */
177
-function wpinv_discount( $invoice = 0, $currency = false, $deprecated ) {
178
-    $invoice  = new WPInv_Invoice( $invoice );
177
+function wpinv_discount($invoice = 0, $currency = false, $deprecated) {
178
+    $invoice  = new WPInv_Invoice($invoice);
179 179
     $discount = $invoice->get_total_discount();
180 180
 
181
-    if ( $currency ) {
182
-        return wpinv_price( wpinv_format_amount( $discount ), $invoice->get_currency() );
181
+    if ($currency) {
182
+        return wpinv_price(wpinv_format_amount($discount), $invoice->get_currency());
183 183
     }
184 184
 
185 185
     return $discount;
@@ -188,20 +188,20 @@  discard block
 block discarded – undo
188 188
 /**
189 189
  * @deprecated
190 190
  */
191
-function wpinv_discount_code( $invoice = 0 ) {
192
-    $invoice = new WPInv_Invoice( $invoice );
191
+function wpinv_discount_code($invoice = 0) {
192
+    $invoice = new WPInv_Invoice($invoice);
193 193
     return $invoice->get_discount_code();
194 194
 }
195 195
 
196 196
 /**
197 197
  * @deprecated
198 198
  */
199
-function wpinv_payment_total( $invoice = 0, $currency = false ) {
200
-    $invoice  = new WPInv_Invoice( $invoice );
199
+function wpinv_payment_total($invoice = 0, $currency = false) {
200
+    $invoice = new WPInv_Invoice($invoice);
201 201
     $total = $invoice->get_total();
202 202
 
203
-    if ( $currency ) {
204
-        return wpinv_price( wpinv_format_amount( $total ), $invoice->get_currency() );
203
+    if ($currency) {
204
+        return wpinv_price(wpinv_format_amount($total), $invoice->get_currency());
205 205
     }
206 206
 
207 207
     return $total;
@@ -210,51 +210,51 @@  discard block
 block discarded – undo
210 210
 /**
211 211
  * @deprecated
212 212
  */
213
-function wpinv_get_date_created( $invoice = 0, $format = '' ) {
214
-    $invoice = new WPInv_Invoice( $invoice );
213
+function wpinv_get_date_created($invoice = 0, $format = '') {
214
+    $invoice = new WPInv_Invoice($invoice);
215 215
 
216
-    $format         = ! empty( $format ) ? $format : get_option( 'date_format' );
216
+    $format         = !empty($format) ? $format : get_option('date_format');
217 217
     $date_created   = $invoice->get_created_date();
218 218
 
219
-    return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : '';
219
+    return empty($date_created) ? date_i18n($format, strtotime($date_created)) : '';
220 220
 }
221 221
 
222 222
 /**
223 223
  * @deprecated
224 224
  */
225
-function wpinv_get_invoice_date( $invoice = 0, $format = '' ) {
226
-    wpinv_get_date_created( $invoice, $format );
225
+function wpinv_get_invoice_date($invoice = 0, $format = '') {
226
+    wpinv_get_date_created($invoice, $format);
227 227
 }
228 228
 
229 229
 /**
230 230
  * @deprecated
231 231
  */
232
-function wpinv_get_invoice_vat_number( $invoice = 0 ) {
233
-    $invoice = new WPInv_Invoice( $invoice );
232
+function wpinv_get_invoice_vat_number($invoice = 0) {
233
+    $invoice = new WPInv_Invoice($invoice);
234 234
     return $invoice->get_vat_number();
235 235
 }
236 236
 
237 237
 /**
238 238
  * @deprecated
239 239
  */
240
-function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
241
-    $invoice = new WPInv_Invoice( $invoice );
242
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
240
+function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
241
+    $invoice = new WPInv_Invoice($invoice);
242
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
243 243
 }
244 244
 
245 245
 /**
246 246
  * @deprecated
247 247
  */
248
-function wpinv_get_payment_key( $invoice = 0 ) {
249
-	$invoice = new WPInv_Invoice( $invoice );
248
+function wpinv_get_payment_key($invoice = 0) {
249
+	$invoice = new WPInv_Invoice($invoice);
250 250
     return $invoice->get_key();
251 251
 }
252 252
 
253 253
 /**
254 254
  * @deprecated
255 255
  */
256
-function wpinv_get_invoice_number( $invoice = 0 ) {
257
-    $invoice = new WPInv_Invoice( $invoice );
256
+function wpinv_get_invoice_number($invoice = 0) {
257
+    $invoice = new WPInv_Invoice($invoice);
258 258
     return $invoice->get_number();
259 259
 }
260 260
 
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 /**
402 402
  * @deprecated
403 403
  */
404
-function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) {    
405
-    $invoice = new WPInv_Invoice( $invoice );
406
-    return $invoice->update_status( $new_status );
404
+function wpinv_update_payment_status($invoice, $new_status = 'publish') {    
405
+    $invoice = new WPInv_Invoice($invoice);
406
+    return $invoice->update_status($new_status);
407 407
 }
408 408
 
409 409
 /**
@@ -456,22 +456,22 @@  discard block
 block discarded – undo
456 456
 /**
457 457
  * @deprecated
458 458
  */
459
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
459
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
460 460
 
461 461
     // Fetch the invoice.
462
-    $invoice = new WPInv_Invoice( $invoice_id );
462
+    $invoice = new WPInv_Invoice($invoice_id);
463 463
 
464
-    if ( 0 ==  $invoice->get_id() ) {
464
+    if (0 == $invoice->get_id()) {
465 465
         return false;
466 466
     }
467 467
 
468 468
     // Prepare the transaction id.
469
-    if ( empty( $transaction_id ) ) {
469
+    if (empty($transaction_id)) {
470 470
         $transaction_id = $invoice_id;
471 471
     }
472 472
 
473 473
     // Set the transaction id;
474
-    $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) );
474
+    $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice));
475 475
 
476 476
     // Save the invoice.
477 477
     return $invoice->save();
@@ -480,9 +480,9 @@  discard block
 block discarded – undo
480 480
 /**
481 481
  * @deprecated
482 482
  */
483
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
483
+function wpinv_send_to_gateway($gateway, $payment_data) {
484 484
     $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
485
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
485
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
486 486
 }
487 487
 
488 488
 /**
@@ -495,10 +495,10 @@  discard block
 block discarded – undo
495 495
 /**
496 496
  * @deprecated
497 497
  */
498
-function wpinv_die( $message = '', $title = '', $status = 400 ) {
499
-    add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 );
500
-    add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 );
501
-    wp_die( $message, $title, array( 'response' => $status ));
498
+function wpinv_die($message = '', $title = '', $status = 400) {
499
+    add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3);
500
+    add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3);
501
+    wp_die($message, $title, array('response' => $status));
502 502
 }
503 503
 
504 504
 /**
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 1 patch
Spacing   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  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
 /**
@@ -18,8 +18,8 @@  discard block
 block discarded – undo
18 18
  * 
19 19
  * @return bool
20 20
  */
21
-function getpaid_is_eu_state( $country ) {
22
-    return WPInv_EUVat::is_eu_state( $country );
21
+function getpaid_is_eu_state($country) {
22
+    return WPInv_EUVat::is_eu_state($country);
23 23
 }
24 24
 
25 25
 /**
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
  * 
28 28
  * @return bool
29 29
  */
30
-function getpaid_is_gst_country( $country ) {
31
-    return WPInv_EUVat::is_gst_country( $country );
30
+function getpaid_is_gst_country($country) {
31
+    return WPInv_EUVat::is_gst_country($country);
32 32
 }
33 33
 
34 34
 /**
@@ -42,117 +42,117 @@  discard block
 block discarded – undo
42 42
 
43 43
 
44 44
 function wpinv_use_taxes() {
45
-    $ret = wpinv_get_option( 'enable_taxes', false );
45
+    $ret = wpinv_get_option('enable_taxes', false);
46 46
     
47
-    return (bool) apply_filters( 'wpinv_use_taxes', $ret );
47
+    return (bool) apply_filters('wpinv_use_taxes', $ret);
48 48
 }
49 49
 
50 50
 function wpinv_get_tax_rates() {
51
-    $rates = get_option( 'wpinv_tax_rates', array() );
51
+    $rates = get_option('wpinv_tax_rates', array());
52 52
     
53
-    return apply_filters( 'wpinv_get_tax_rates', $rates );
53
+    return apply_filters('wpinv_get_tax_rates', $rates);
54 54
 }
55 55
 
56
-function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) {
56
+function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) {
57 57
     global $wpinv_euvat, $wpi_tax_rates, $wpi_userID;
58
-    $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array();
58
+    $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array();
59 59
     
60
-    if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) {
60
+    if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) {
61 61
         return $wpi_tax_rates[$item_id];
62 62
     }
63 63
     
64
-    if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) {
64
+    if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) {
65 65
         $wpi_tax_rates[$item_id] = 0;
66 66
         return 0;
67 67
     }
68 68
 
69 69
     $is_global = false;
70
-    if ( $item_id == 'global' ) {
70
+    if ($item_id == 'global') {
71 71
         $is_global = true;
72 72
         $item_id = 0;
73 73
     }
74 74
     
75
-    $rate           = (float)wpinv_get_option( 'tax_rate', 0 );
76
-    $user_address   = wpinv_get_user_address( $wpi_userID );
75
+    $rate           = (float) wpinv_get_option('tax_rate', 0);
76
+    $user_address   = wpinv_get_user_address($wpi_userID);
77 77
     
78
-    if( empty( $country ) ) {
79
-        if( !empty( $_POST['wpinv_country'] ) ) {
78
+    if (empty($country)) {
79
+        if (!empty($_POST['wpinv_country'])) {
80 80
             $country = $_POST['wpinv_country'];
81
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
81
+        } elseif (!empty($_POST['wpinv_country'])) {
82 82
             $country = $_POST['wpinv_country'];
83
-        } elseif( !empty( $_POST['country'] ) ) {
83
+        } elseif (!empty($_POST['country'])) {
84 84
             $country = $_POST['country'];
85
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
85
+        } elseif (is_user_logged_in() && !empty($user_address)) {
86 86
             $country = $user_address['country'];
87 87
         }
88
-        $country = !empty( $country ) ? $country : wpinv_get_default_country();
88
+        $country = !empty($country) ? $country : wpinv_get_default_country();
89 89
     }
90 90
 
91
-    if( empty( $state ) ) {
92
-        if( !empty( $_POST['wpinv_state'] ) ) {
91
+    if (empty($state)) {
92
+        if (!empty($_POST['wpinv_state'])) {
93 93
             $state = $_POST['wpinv_state'];
94
-        } elseif( !empty( $_POST['wpinv_state'] ) ) {
94
+        } elseif (!empty($_POST['wpinv_state'])) {
95 95
             $state = $_POST['wpinv_state'];
96
-        } elseif( !empty( $_POST['state'] ) ) {
96
+        } elseif (!empty($_POST['state'])) {
97 97
             $state = $_POST['state'];
98
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
98
+        } elseif (is_user_logged_in() && !empty($user_address)) {
99 99
             $state = $user_address['state'];
100 100
         }
101
-        $state = !empty( $state ) ? $state : wpinv_get_default_state();
101
+        $state = !empty($state) ? $state : wpinv_get_default_state();
102 102
     }
103 103
     
104
-    if( !empty( $country ) ) {
105
-        $tax_rates   = wpinv_get_tax_rates();
104
+    if (!empty($country)) {
105
+        $tax_rates = wpinv_get_tax_rates();
106 106
 
107
-        if( !empty( $tax_rates ) ) {
107
+        if (!empty($tax_rates)) {
108 108
             // Locate the tax rate for this country / state, if it exists
109
-            foreach( $tax_rates as $key => $tax_rate ) {
110
-                if( $country != $tax_rate['country'] )
109
+            foreach ($tax_rates as $key => $tax_rate) {
110
+                if ($country != $tax_rate['country'])
111 111
                     continue;
112 112
 
113
-                if( !empty( $tax_rate['global'] ) ) {
114
-                    if( !empty( $tax_rate['rate'] ) ) {
115
-                        $rate = number_format( $tax_rate['rate'], 4 );
113
+                if (!empty($tax_rate['global'])) {
114
+                    if (!empty($tax_rate['rate'])) {
115
+                        $rate = number_format($tax_rate['rate'], 4);
116 116
                     }
117 117
                 } else {
118 118
 
119
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
119
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
120 120
                         continue;
121 121
 
122 122
                     $state_rate = $tax_rate['rate'];
123
-                    if( 0 !== $state_rate || !empty( $state_rate ) ) {
124
-                        $rate = number_format( $state_rate, 4 );
123
+                    if (0 !== $state_rate || !empty($state_rate)) {
124
+                        $rate = number_format($state_rate, 4);
125 125
                     }
126 126
                 }
127 127
             }
128 128
         }
129 129
     }
130 130
     
131
-    $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id );
131
+    $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id);
132 132
     
133
-    if ( !empty( $item_id ) ) {
133
+    if (!empty($item_id)) {
134 134
         $wpi_tax_rates[$item_id] = $rate;
135
-    } else if ( $is_global ) {
135
+    } else if ($is_global) {
136 136
         $wpi_tax_rates['global'] = $rate;
137 137
     }
138 138
     
139 139
     return $rate;
140 140
 }
141 141
 
142
-function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) {
143
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
144
-    $rate = round( $rate, 4 );
142
+function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) {
143
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
144
+    $rate = round($rate, 4);
145 145
     $formatted = $rate .= '%';
146
-    return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id );
146
+    return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id);
147 147
 }
148 148
 
149
-function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) {
150
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
149
+function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) {
150
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
151 151
     $tax  = 0.00;
152 152
 
153
-    if ( wpinv_use_taxes() ) {        
154
-        if ( wpinv_prices_include_tax() ) {
155
-            $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) );
153
+    if (wpinv_use_taxes()) {        
154
+        if (wpinv_prices_include_tax()) {
155
+            $pre_tax = ($amount / ((1 + $rate) * 0.01));
156 156
             $tax     = $amount - $pre_tax;
157 157
         } else {
158 158
             $tax = $amount * $rate * 0.01;
@@ -160,46 +160,46 @@  discard block
 block discarded – undo
160 160
 
161 161
     }
162 162
 
163
-    return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id );
163
+    return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id);
164 164
 }
165 165
 
166 166
 function wpinv_prices_include_tax() {
167 167
     return false; // TODO
168
-    $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() );
168
+    $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes());
169 169
 
170
-    return apply_filters( 'wpinv_prices_include_tax', $ret );
170
+    return apply_filters('wpinv_prices_include_tax', $ret);
171 171
 }
172 172
 
173
-function wpinv_sales_tax_for_year( $year = null ) {
174
-    return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) );
173
+function wpinv_sales_tax_for_year($year = null) {
174
+    return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year)));
175 175
 }
176 176
 
177
-function wpinv_get_sales_tax_for_year( $year = null ) {
177
+function wpinv_get_sales_tax_for_year($year = null) {
178 178
     global $wpdb;
179 179
 
180 180
     // Start at zero
181 181
     $tax = 0;
182 182
 
183
-    if ( ! empty( $year ) ) {
183
+    if (!empty($year)) {
184 184
         $args = array(
185 185
             'post_type'      => 'wpi_invoice',
186
-            'post_status'    => array( 'publish' ),
186
+            'post_status'    => array('publish'),
187 187
             'posts_per_page' => -1,
188 188
             'year'           => $year,
189 189
             'fields'         => 'ids'
190 190
         );
191 191
 
192
-        $payments    = get_posts( $args );
193
-        $payment_ids = implode( ',', $payments );
192
+        $payments    = get_posts($args);
193
+        $payment_ids = implode(',', $payments);
194 194
 
195
-        if ( count( $payments ) > 0 ) {
195
+        if (count($payments) > 0) {
196 196
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
197
-            $tax = $wpdb->get_var( $sql );
197
+            $tax = $wpdb->get_var($sql);
198 198
         }
199 199
 
200 200
     }
201 201
 
202
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
202
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
203 203
 }
204 204
 
205 205
 function wpinv_is_cart_taxed() {
@@ -208,33 +208,33 @@  discard block
 block discarded – undo
208 208
 
209 209
 function wpinv_prices_show_tax_on_checkout() {
210 210
     return false; // TODO
211
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
211
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
212 212
 
213
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
213
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
214 214
 }
215 215
 
216 216
 function wpinv_display_tax_rate() {
217
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
217
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
218 218
 
219
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
219
+    return apply_filters('wpinv_display_tax_rate', $ret);
220 220
 }
221 221
 
222 222
 function wpinv_cart_needs_tax_address_fields() {
223
-    if( !wpinv_is_cart_taxed() )
223
+    if (!wpinv_is_cart_taxed())
224 224
         return false;
225 225
 
226
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
226
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
227 227
 }
228 228
 
229
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
230
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
231
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
229
+function wpinv_item_is_tax_exclusive($item_id = 0) {
230
+    $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false);
231
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
232 232
 }
233 233
 
234
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
234
+function wpinv_currency_decimal_filter($decimals = 2) {
235 235
     $currency = wpinv_get_currency();
236 236
 
237
-    switch ( $currency ) {
237
+    switch ($currency) {
238 238
         case 'RIAL' :
239 239
         case 'JPY' :
240 240
         case 'TWD' :
@@ -243,50 +243,50 @@  discard block
 block discarded – undo
243 243
             break;
244 244
     }
245 245
 
246
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
246
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
247 247
 }
248 248
 
249 249
 function wpinv_tax_amount() {
250 250
     $output = 0.00;
251 251
     
252
-    return apply_filters( 'wpinv_tax_amount', $output );
252
+    return apply_filters('wpinv_tax_amount', $output);
253 253
 }
254 254
 
255 255
 // VAT Settings
256
-function wpinv_vat_rate_add_callback( $args ) {
256
+function wpinv_vat_rate_add_callback($args) {
257 257
     ?>
258
-    <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>
258
+    <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>
259 259
     <?php
260 260
 }
261 261
 
262
-function wpinv_vat_rate_delete_callback( $args ) {
262
+function wpinv_vat_rate_delete_callback($args) {
263 263
     global $wpinv_euvat;
264 264
     
265 265
     $vat_classes = $wpinv_euvat->get_rate_classes();
266
-    $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '';
267
-    if ( isset( $vat_classes[$vat_class] ) ) {
266
+    $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '';
267
+    if (isset($vat_classes[$vat_class])) {
268 268
     ?>
269
-    <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>
269
+    <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>
270 270
     <?php
271 271
     }
272 272
 }
273 273
 
274
-function wpinv_vat_rates_callback( $args ) {
274
+function wpinv_vat_rates_callback($args) {
275 275
     global $wpinv_euvat;
276 276
     
277 277
     $vat_classes    = $wpinv_euvat->get_rate_classes();
278
-    $vat_class      = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard';
278
+    $vat_class      = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard';
279 279
     
280 280
     $eu_states      = $wpinv_euvat->get_eu_states();
281 281
     $countries      = wpinv_get_country_list();
282 282
     $vat_groups     = $wpinv_euvat->get_vat_groups();
283
-    $rates          = $wpinv_euvat->get_vat_rates( $vat_class );
283
+    $rates          = $wpinv_euvat->get_vat_rates($vat_class);
284 284
     ob_start();
285 285
 ?>
286 286
 </td><tr>
287 287
     <td colspan="2" class="wpinv_vat_tdbox">
288
-    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" />
289
-    <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p>
288
+    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" />
289
+    <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p>
290 290
     <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts">
291 291
         <colgroup>
292 292
             <col width="50px" />
@@ -298,43 +298,43 @@  discard block
 block discarded – undo
298 298
         </colgroup>
299 299
         <thead>
300 300
             <tr>
301
-                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th>
302
-                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
303
-                <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
304
-                <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th>
305
-                <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th>
301
+                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th>
302
+                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
303
+                <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
304
+                <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th>
305
+                <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th>
306 306
             </tr>
307 307
         </thead>
308 308
         <tbody>
309
-        <?php if( !empty( $eu_states ) ) { ?>
309
+        <?php if (!empty($eu_states)) { ?>
310 310
         <?php 
311
-        foreach ( $eu_states as $state ) { 
312
-            $country_name = isset( $countries[$state] ) ? $countries[$state] : '';
311
+        foreach ($eu_states as $state) { 
312
+            $country_name = isset($countries[$state]) ? $countries[$state] : '';
313 313
             
314 314
             // Filter the rate for each country
315
-            $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } );
315
+            $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } );
316 316
             
317 317
             // If one does not exist create a default
318
-            $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array();
318
+            $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array();
319 319
             
320
-            $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true;
321
-            $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : '';
322
-            $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : '';
323
-            $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' );
320
+            $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true;
321
+            $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : '';
322
+            $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : '';
323
+            $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced');
324 324
         ?>
325 325
         <tr>
326 326
             <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>
327 327
             <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td>
328 328
             <td class="wpinv_vat_global">
329
-                <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" />
330
-                <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
331
-                <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" />
329
+                <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" />
330
+                <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
331
+                <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" />
332 332
             </td>
333
-            <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>
334
-            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td>
333
+            <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>
334
+            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td>
335 335
             <td class="wpinv_vat_group">
336 336
             <?php
337
-            echo wpinv_html_select( array(
337
+            echo wpinv_html_select(array(
338 338
                                         'name'             => 'vat_rates[' . $state . '][group]',
339 339
                                         'selected'         => $vat_group,
340 340
                                         'id'               => 'vat_rates[' . $state . '][group]',
@@ -343,14 +343,14 @@  discard block
 block discarded – undo
343 343
                                         'multiple'         => false,
344 344
                                         'show_option_all'  => false,
345 345
                                         'show_option_none' => false
346
-                                    ) );
346
+                                    ));
347 347
             ?>
348 348
             </td>
349 349
         </tr>
350 350
         <?php } ?>
351 351
         <tr>
352 352
             <td colspan="6" style="background-color:#fafafa;">
353
-                <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>
353
+                <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>
354 354
             </td>
355 355
         </tr>
356 356
         <?php } ?>
@@ -362,35 +362,35 @@  discard block
 block discarded – undo
362 362
     echo $content;
363 363
 }
364 364
 
365
-function wpinv_vat_number_callback( $args ) {
365
+function wpinv_vat_number_callback($args) {
366 366
     global $wpinv_euvat;
367 367
     
368 368
     $vat_number     = $wpinv_euvat->get_vat_number();
369 369
     $vat_valid      = $wpinv_euvat->is_vat_validated();
370 370
 
371
-    $size           = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular';
372
-    $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' );
371
+    $size           = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
372
+    $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing');
373 373
     $disabled       = $vat_valid ? 'disabled="disabled"' : " ";
374 374
     
375
-    $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 ) ) . '"/>';
376
-    $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>';
377
-    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
378
-    $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>';
379
-    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">';
375
+    $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)) . '"/>';
376
+    $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>';
377
+    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
378
+    $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>';
379
+    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">';
380 380
 
381 381
     echo $html;
382 382
 }
383 383
 
384
-function wpinv_eu_fallback_rate_callback( $args ) {
384
+function wpinv_eu_fallback_rate_callback($args) {
385 385
     global $wpinv_options;
386 386
 
387
-    $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' );
388
-    $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small';
387
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : '');
388
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small';
389 389
     
390
-    $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 ) ) . '" />';
391
-    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>';
392
-    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>';
393
-    $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>';
390
+    $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)) . '" />';
391
+    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>';
392
+    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>';
393
+    $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>';
394 394
     $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>';
395 395
     echo $html;
396 396
     ?>
@@ -398,36 +398,36 @@  discard block
 block discarded – undo
398 398
     <?php
399 399
 }
400 400
 
401
-function wpinv_vat_ip_lookup_callback( $args ) {
401
+function wpinv_vat_ip_lookup_callback($args) {
402 402
     global $wpinv_options, $wpinv_euvat;
403 403
 
404
-    $value =  isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ]  : ( isset( $args['std'] ) ? $args['std'] : 'default' );
404
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default');
405 405
     
406 406
     $options = array();
407
-    if ( function_exists( 'geoip_country_code_by_name' ) ) {
408
-        $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' );
407
+    if (function_exists('geoip_country_code_by_name')) {
408
+        $options['geoip'] = __('PHP GeoIP extension', 'invoicing');
409 409
     }
410 410
     
411 411
     $geoip2_database = $wpinv_euvat->geoip2_country_dbfile();
412 412
     
413
-    if ( !function_exists( 'bcadd' ) ) {
414
-        $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' );
413
+    if (!function_exists('bcadd')) {
414
+        $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing');
415 415
     } else {
416
-        $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : '';
416
+        $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : '';
417 417
     }
418 418
     
419
-    if ( $geoip2_database !== false && empty( $geoip2_message ) ) {
420
-        $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' );
419
+    if ($geoip2_database !== false && empty($geoip2_message)) {
420
+        $options['geoip2'] = __('GeoIP2 Database', 'invoicing');
421 421
     }
422 422
     
423
-    if ( function_exists( 'simplexml_load_file' ) ) {
424
-        $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' );
423
+    if (function_exists('simplexml_load_file')) {
424
+        $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing');
425 425
     }
426 426
     
427
-    $options['site']    = __( 'Use default country', 'invoicing' );
428
-    $options['default'] = __( 'Auto', 'invoicing' );
427
+    $options['site']    = __('Use default country', 'invoicing');
428
+    $options['default'] = __('Auto', 'invoicing');
429 429
 
430
-    $html = wpinv_html_select( array(
430
+    $html = wpinv_html_select(array(
431 431
         'name'             => "wpinv_settings[{$args['id']}]",
432 432
         'selected'         => $value,
433 433
         'id'               => "wpinv_settings[{$args['id']}]",
@@ -439,23 +439,23 @@  discard block
 block discarded – undo
439 439
     ));
440 440
     
441 441
     $desc = '<label for="wpinv_settings[' . $args['id'] . ']">';
442
-    $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' );
442
+    $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing');
443 443
     $desc .= '<p>';
444
-    if ( empty( $geoip2_message ) ) {
445
-        if ( $geoip2_database ) {
444
+    if (empty($geoip2_message)) {
445
+        if ($geoip2_database) {
446 446
             $last_updated = '';
447
-            if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) {
448
-                $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated );
449
-                $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated );
447
+            if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) {
448
+                $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated);
449
+                $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated);
450 450
             }
451
-            $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 (~30MB)', 'invoicing' ) . '"></input>';
451
+            $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 (~30MB)', 'invoicing') . '"></input>';
452 452
         } else {
453
-            $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' ) . ' (~30MB)"></input><br>' . __(  'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' );
453
+            $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') . ' (~30MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing');
454 454
         }
455 455
     } else {
456 456
         $desc .= $geoip2_message;
457 457
     }
458
-    $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>';
458
+    $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>';
459 459
     $desc .= '</label>';
460 460
     
461 461
     $html .= $desc;
@@ -471,39 +471,39 @@  discard block
 block discarded – undo
471 471
  * 
472 472
  * @param string|bool|null $vat_rule
473 473
  */
474
-function getpaid_filter_vat_rule( $vat_rule ) {
474
+function getpaid_filter_vat_rule($vat_rule) {
475 475
 
476
-    if ( empty( $vat_rule ) ) {        
476
+    if (empty($vat_rule)) {        
477 477
         return getpaid_tax()->allow_vat_rules() ? 'digital' : 'physical';
478 478
     }
479 479
 
480 480
     return $vat_rule;
481 481
 }
482
-add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' );
482
+add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule');
483 483
 
484 484
 /**
485 485
  * Filters the VAT class to ensure that each item has a VAT class.
486 486
  * 
487 487
  * @param string|bool|null $vat_rule
488 488
  */
489
-function getpaid_filter_vat_class( $vat_class ) {
490
-    return empty( $vat_class ) ? '_standard' : $vat_class;
489
+function getpaid_filter_vat_class($vat_class) {
490
+    return empty($vat_class) ? '_standard' : $vat_class;
491 491
 }
492
-add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' );
492
+add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class');
493 493
 
494 494
 /**
495 495
  * Returns the ip address location url.
496 496
  * 
497 497
  */
498
-function getpaid_ip_location_url( $ip_address ) {
498
+function getpaid_ip_location_url($ip_address) {
499 499
 
500 500
     return add_query_arg(
501 501
         array(
502 502
             'action'   => 'wpinv_ip_geolocation',
503 503
             'ip'       => $ip_address,
504
-            '_wpnonce' => wp_create_nonce( 'getpaid-ip-location' )
504
+            '_wpnonce' => wp_create_nonce('getpaid-ip-location')
505 505
         ),
506
-        admin_url( 'admin-ajax.php' )
506
+        admin_url('admin-ajax.php')
507 507
     );
508 508
 
509 509
 }
@@ -513,54 +513,54 @@  discard block
 block discarded – undo
513 513
  * 
514 514
  * @return array|bool
515 515
  */
516
-function getpaid_geolocate_ip_address( $ip_address ) {
516
+function getpaid_geolocate_ip_address($ip_address) {
517 517
 
518 518
     // Do we have an ip address?
519
-    if ( empty( $ip_address ) ) {
519
+    if (empty($ip_address)) {
520 520
         return false;
521 521
     }
522 522
 
523 523
     /**
524 524
      * Retrieve ip address using max mind.
525 525
      */
526
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = getpaid_tax()->geoip2_city_record( $ip_address ) ) {
526
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = getpaid_tax()->geoip2_city_record($ip_address)) {
527 527
 
528 528
         try {
529 529
             $iso        = $geoip2_city->country->isoCode;
530 530
             $country    = $geoip2_city->country->name;
531
-            $region     = ! empty( $geoip2_city->subdivisions ) && ! empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
531
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
532 532
             $city       = $geoip2_city->city->name;
533 533
             $longitude  = $geoip2_city->location->longitude;
534 534
             $latitude   = $geoip2_city->location->latitude;
535
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
536
-        } catch( Exception $e ) { }
535
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
536
+        } catch (Exception $e) { }
537 537
 
538 538
     }
539 539
 
540 540
     // If that fails, GeoLocate using GeoPlugin.
541
-    if ( ( empty( $iso ) || empty( $longitude ) || empty( $latitude ) ) && function_exists( 'simplexml_load_file' ) ) {
541
+    if ((empty($iso) || empty($longitude) || empty($latitude)) && function_exists('simplexml_load_file')) {
542 542
 
543 543
         try {
544
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip_address );
544
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip_address);
545 545
             
546
-            if ( ! empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && ! empty( $load_xml->geoplugin_latitude ) && ! empty( $load_xml->geoplugin_longitude ) ) {
546
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
547 547
                 $iso        = $load_xml->geoplugin_countryCode;
548 548
                 $country    = $load_xml->geoplugin_countryName;
549
-                $region     = ! empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
550
-                $city       = ! empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
549
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
550
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
551 551
                 $longitude  = $load_xml->geoplugin_longitude;
552 552
                 $latitude   = $load_xml->geoplugin_latitude;
553 553
                 $credit     = $load_xml->geoplugin_credit;
554
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
554
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
555 555
             }
556
-        } catch( Exception $e ) { }
556
+        } catch (Exception $e) { }
557 557
 
558 558
     }
559 559
 
560
-   if ( empty( $iso )  ) {
560
+   if (empty($iso)) {
561 561
        return false;
562 562
    }
563 563
 
564
-   return compact( 'iso', 'country', 'region', 'city', 'longitude', 'latitude', 'credit' );
564
+   return compact('iso', 'country', 'region', 'city', 'longitude', 'latitude', 'credit');
565 565
 
566 566
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 2 patches
Indentation   +727 added lines, -727 removed lines patch added patch discarded remove patch
@@ -14,745 +14,745 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Plugin {
16 16
 
17
-	/**
18
-	 * GetPaid version.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	public $version;
23
-
24
-	/**
25
-	 * Data container.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $data = array();
30
-
31
-	/**
32
-	 * Form elements instance.
33
-	 *
34
-	 * @var WPInv_Payment_Form_Elements
35
-	 */
36
-	public $form_elements;
37
-
38
-	/**
39
-	 * Tax instance.
40
-	 *
41
-	 * @var WPInv_EUVat
42
-	 */
43
-	public $tax;
44
-
45
-	/**
46
-	 * @param array An array of payment gateways.
47
-	 */
48
-	public $gateways;
49
-
50
-	/**
51
-	 * Class constructor.
52
-	 */
53
-	public function __construct() {
54
-		$this->define_constants();
55
-		$this->includes();
56
-		$this->init_hooks();
57
-		$this->set_properties();
58
-	}
59
-
60
-	/**
61
-	 * Sets a custom data property.
62
-	 * 
63
-	 * @param string $prop The prop to set.
64
-	 * @param mixed $value The value to retrieve.
65
-	 */
66
-	public function set( $prop, $value ) {
67
-		$this->data[ $prop ] = $value;
68
-	}
69
-
70
-	/**
71
-	 * Gets a custom data property.
72
-	 * 
73
-	 * @param string $prop The prop to set.
74
-	 * @return mixed The value.
75
-	 */
76
-	public function get( $prop ) {
77
-
78
-		if ( isset( $this->data[ $prop ] ) ) {
79
-			return $this->data[ $prop ];
80
-		}
81
-
82
-		return null;
83
-	}
84
-
85
-	/**
86
-	 * Define class properties.
87
-	 */
88
-	public function set_properties() {
89
-
90
-		// Sessions.
91
-		$this->set( 'session', new WPInv_Session_Handler() );
92
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
-		$this->form_elements = new WPInv_Payment_Form_Elements();
94
-		$this->tax           = new WPInv_EUVat();
95
-		$this->tax->init();
96
-		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
97
-
98
-		// Init other objects.
99
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
100
-		$this->set( 'session', new WPInv_Session_Handler() );
101
-		$this->set( 'notes', new WPInv_Notes() );
102
-		$this->set( 'api', new WPInv_API() );
103
-		$this->set( 'post_types', new GetPaid_Post_Types() );
104
-		$this->set( 'template', new GetPaid_Template() );
105
-	}
106
-
107
-	 /**
108
-	 * Define plugin constants.
109
-	 */
110
-	public function define_constants() {
111
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
112
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
113
-		$this->version = WPINV_VERSION;
114
-	}
115
-
116
-	/**
117
-	 * Hook into actions and filters.
118
-	 *
119
-	 * @since 1.0.19
120
-	 */
121
-	protected function init_hooks() {
122
-		/* Internationalize the text strings used. */
123
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
124
-
125
-		/* Perform actions on admin initialization. */
126
-		add_action( 'admin_init', array( &$this, 'admin_init') );
127
-
128
-		// Init the plugin after WordPress inits.
129
-		add_action( 'init', array( $this, 'init' ), 1 );
130
-		add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
131
-		add_action( 'init', array( &$this, 'wpinv_actions' ) );
132
-
133
-		if ( class_exists( 'BuddyPress' ) ) {
134
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
135
-		}
136
-
137
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
138
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
139
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
140
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
141
-
142
-		if ( is_admin() ) {
143
-			add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
144
-			add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
145
-			add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
146
-
147
-		} else {
148
-			add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
149
-		}
150
-
151
-		// Fires after registering actions.
152
-		do_action( 'wpinv_actions', $this );
153
-		do_action( 'getpaid_actions', $this );
154
-		add_action( 'admin_init', array( &$this, 'activation_redirect') );
155
-
156
-	}
157
-
158
-	/**
159
-	 * Maybe show the AyeCode Connect Notice.
160
-	 */
161
-	public function init_ayecode_connect_helper(){
162
-		// AyeCode Connect notice
163
-		if ( is_admin() ){
164
-			// set the strings so they can be translated
165
-			$strings = array(
166
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
167
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
168
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
169
-				'connect_button'    => __("Connect Site","invoicing"),
170
-				'connecting_button'    => __("Connecting...","invoicing"),
171
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
172
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
173
-			);
174
-			new AyeCode_Connect_Helper($strings,array('wpi-addons'));
175
-		}
176
-	}
177
-
178
-	public function plugins_loaded() {
179
-		/* Internationalize the text strings used. */
180
-		$this->load_textdomain();
181
-
182
-		do_action( 'wpinv_loaded' );
183
-
184
-		// Fix oxygen page builder conflict
185
-		if ( function_exists( 'ct_css_output' ) ) {
186
-			wpinv_oxygen_fix_conflict();
187
-		}
188
-	}
189
-
190
-	/**
191
-	 * Load the translation of the plugin.
192
-	 *
193
-	 * @since 1.0
194
-	 */
195
-	public function load_textdomain( $locale = NULL ) {
196
-		if ( empty( $locale ) ) {
197
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
198
-		}
199
-
200
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
201
-
202
-		unload_textdomain( 'invoicing' );
203
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
204
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
205
-
206
-		/**
207
-		 * Define language constants.
208
-		 */
209
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
210
-	}
211
-
212
-	/**
213
-	 * Include required core files used in admin and on the frontend.
214
-	 */
215
-	public function includes() {
216
-
217
-		// Start with the settings.
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
219
-
220
-		// Packages/libraries.
221
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
224
-
225
-		// Load functions.
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
235
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
236
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
237
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
238
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
239
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
240
-
241
-		// Register autoloader.
242
-		try {
243
-			spl_autoload_register( array( $this, 'autoload' ), true );
244
-		} catch ( Exception $e ) {
245
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
246
-		}
247
-
248
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
249
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
250
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
251
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
252
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
253
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
254
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
255
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
256
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
257
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
258
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
259
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
260
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
261
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
262
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
263
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
264
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
265
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
266
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
267
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
268
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
269
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
270
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
271
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
272
-
273
-		/**
274
-		 * Load the tax class.
275
-		 */
276
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
277
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
278
-		}
279
-
280
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
281
-		if ( !empty( $gateways ) ) {
282
-			foreach ( $gateways as $gateway ) {
283
-				if ( $gateway == 'manual' ) {
284
-					continue;
285
-				}
286
-
287
-				$gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
288
-
289
-				if ( file_exists( $gateway_file ) ) {
290
-					require_once( $gateway_file );
291
-				}
292
-			}
293
-		}
294
-
295
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
296
-			GetPaid_Post_Types_Admin::init();
297
-
298
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
299
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
300
-			//require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
301
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
302
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
303
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
304
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
305
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
306
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
307
-			//require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
308
-			// load the user class only on the users.php page
309
-			global $pagenow;
310
-			if($pagenow=='users.php'){
311
-				new WPInv_Admin_Users();
312
-			}
313
-		}
314
-
315
-		// Register cli commands
316
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
317
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
318
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
319
-		}
320
-
321
-		// include css inliner
322
-		if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
323
-			include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
324
-		}
325
-
326
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
327
-	}
328
-
329
-	/**
330
-	 * Class autoloader
331
-	 *
332
-	 * @param       string $class_name The name of the class to load.
333
-	 * @access      public
334
-	 * @since       1.0.19
335
-	 * @return      void
336
-	 */
337
-	public function autoload( $class_name ) {
338
-
339
-		// Normalize the class name...
340
-		$class_name  = strtolower( $class_name );
341
-
342
-		// ... and make sure it is our class.
343
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
344
-			return;
345
-		}
346
-
347
-		// Next, prepare the file name from the class.
348
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
349
-
350
-		// Base path of the classes.
351
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
352
-
353
-		// And an array of possible locations in order of importance.
354
-		$locations = array(
355
-			"$plugin_path/includes",
356
-			"$plugin_path/includes/data-stores",
357
-			"$plugin_path/includes/gateways",
358
-			"$plugin_path/includes/api",
359
-			"$plugin_path/includes/admin",
360
-			"$plugin_path/includes/admin/meta-boxes",
361
-		);
362
-
363
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
364
-
365
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
366
-				include trailingslashit( $location ) . $file_name;
367
-				break;
368
-			}
369
-
370
-		}
371
-
372
-	}
373
-
374
-	/**
375
-	 * Inits hooks etc.
376
-	 */
377
-	public function init() {
378
-
379
-		// Fires before getpaid inits.
380
-		do_action( 'before_getpaid_init', $this );
381
-
382
-		// Load default gateways.
383
-		$gateways = apply_filters(
384
-			'getpaid_default_gateways',
385
-			array(
386
-				'manual'        => 'GetPaid_Manual_Gateway',
387
-				'paypal'        => 'GetPaid_Paypal_Gateway',
388
-				'worldpay'      => 'GetPaid_Worldpay_Gateway',
389
-				'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
390
-				'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
391
-			)
392
-		);
393
-
394
-		foreach ( $gateways as $id => $class ) {
395
-			$this->gateways[ $id ] = new $class();
396
-		}
397
-
398
-		// Fires after getpaid inits.
399
-		do_action( 'getpaid_init', $this );
400
-
401
-	}
402
-
403
-	/**
404
-	 * Checks if this is an IPN request and processes it.
405
-	 */
406
-	public function maybe_process_ipn() {
407
-
408
-		// Ensure that this is an IPN request.
409
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
410
-			return;
411
-		}
412
-
413
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
414
-
415
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
416
-		do_action( "wpinv_verify_{$gateway}_ipn" );
417
-		exit;
418
-
419
-	}
420
-
421
-	public function admin_init() {
422
-		$this->default_payment_form = wpinv_get_default_payment_form();
423
-		add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
424
-	}
425
-
426
-	public function activation_redirect() {
427
-		// Bail if no activation redirect
428
-		if ( !get_transient( '_wpinv_activation_redirect' ) ) {
429
-			return;
430
-		}
431
-
432
-		// Delete the redirect transient
433
-		delete_transient( '_wpinv_activation_redirect' );
434
-
435
-		// Bail if activating from network, or bulk
436
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
437
-			return;
438
-		}
439
-
440
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
441
-		exit;
442
-	}
443
-
444
-	public function enqueue_scripts() {
445
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
446
-
447
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
448
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
449
-		wp_enqueue_style( 'wpinv_front_style' );
450
-
451
-		// Register scripts
452
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
453
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
454
-
455
-		$localize                         = array();
456
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
457
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
458
-		$localize['currency_symbol']      = wpinv_currency_symbol();
459
-		$localize['currency_pos']         = wpinv_currency_position();
460
-		$localize['thousand_sep']         = wpinv_thousands_separator();
461
-		$localize['decimal_sep']          = wpinv_decimal_separator();
462
-		$localize['decimals']             = wpinv_decimals();
463
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
464
-		$localize['UseTaxes']             = wpinv_use_taxes();
465
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
466
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
467
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
468
-
469
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
470
-
471
-		wp_enqueue_script( 'jquery-blockui' );
472
-		$autofill_api = wpinv_get_option('address_autofill_api');
473
-		$autofill_active = wpinv_get_option('address_autofill_active');
474
-		if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
475
-			if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
476
-				wp_dequeue_script( 'google-maps-api' );
477
-			}
478
-			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
479
-			wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
480
-		}
481
-
482
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
483
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
484
-
485
-		wp_enqueue_script( 'wpinv-front-script' );
486
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
487
-
488
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
489
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
490
-	}
491
-
492
-	public function admin_enqueue_scripts( $hook ) {
493
-		global $post, $pagenow;
494
-
495
-		$post_type  = wpinv_admin_post_type();
496
-		$suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
497
-		$page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
498
-
499
-		$jquery_ui_css = false;
500
-		if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
501
-			$jquery_ui_css = true;
502
-		} else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
503
-			$jquery_ui_css = true;
504
-		}
505
-		if ( $jquery_ui_css ) {
506
-			wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
507
-			wp_enqueue_style( 'jquery-ui-css' );
508
-			wp_deregister_style( 'yoast-seo-select2' );
509
-			wp_deregister_style( 'yoast-seo-monorepo' );
510
-		}
511
-
512
-		wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
513
-		wp_enqueue_style( 'wpinv_meta_box_style' );
514
-
515
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
516
-		wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
517
-		wp_enqueue_style( 'wpinv_admin_style' );
518
-
519
-		$enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
520
-		if ( $page == 'wpinv-subscriptions' ) {
521
-			wp_enqueue_script( 'jquery-ui-datepicker' );
522
-			wp_deregister_style( 'yoast-seo-select2' );
523
-			wp_deregister_style( 'yoast-seo-monorepo' );
524
-		}
525
-
526
-		if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
527
-			wp_enqueue_script( 'jquery-ui-datepicker' );
528
-		}
529
-
530
-		wp_enqueue_style( 'wp-color-picker' );
531
-		wp_enqueue_script( 'wp-color-picker' );
532
-
533
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
534
-
535
-		if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
536
-			$autofill_api = wpinv_get_option('address_autofill_api');
537
-			$autofill_active = wpinv_get_option('address_autofill_active');
538
-			if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) {
539
-				wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
540
-				wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true);
541
-			}
542
-		}
543
-
544
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
545
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
546
-
547
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
548
-		wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
549
-		wp_enqueue_script( 'wpinv-admin-script' );
550
-
551
-		$localize                               = array();
552
-		$localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
553
-		$localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
554
-		$localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
555
-		$localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
556
-		$localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
557
-		$localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
558
-		$localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
559
-		$localize['tax']                        = wpinv_tax_amount();
560
-		$localize['discount']                   = wpinv_discount_amount();
561
-		$localize['currency_symbol']            = wpinv_currency_symbol();
562
-		$localize['currency_pos']               = wpinv_currency_position();
563
-		$localize['thousand_sep']               = wpinv_thousands_separator();
564
-		$localize['decimal_sep']                = wpinv_decimal_separator();
565
-		$localize['decimals']                   = wpinv_decimals();
566
-		$localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
567
-		$localize['status_publish']             = wpinv_status_nicename( 'publish' );
568
-		$localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
569
-		$localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
570
-		$localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
571
-		$localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
572
-		$localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
573
-		$localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
574
-		$localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
575
-		$localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
576
-		$localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
577
-		$localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
578
-		$localize['action_edit']                = __( 'Edit', 'invoicing' );
579
-		$localize['action_cancel']              = __( 'Cancel', 'invoicing' );
580
-		$localize['item_description']           = __( 'Item Description', 'invoicing' );
581
-		$localize['discount_description']       = __( 'Discount Description', 'invoicing' );
582
-		$localize['invoice_description']        = __( 'Invoice Description', 'invoicing' );
583
-		$localize['searching']                  = __( 'Searching', 'invoicing' );
584
-
585
-		$localize = apply_filters( 'wpinv_admin_js_localize', $localize );
586
-
587
-		wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
588
-
589
-		// Load payment form scripts on our admin pages only.
590
-		if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
591
-
592
-			wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
593
-			wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
594
-			wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
595
-
596
-			$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
597
-			wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
598
-
599
-			wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
600
-				'elements'      => $this->form_elements->get_elements(),
601
-				'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
602
-				'all_items'     => $this->form_elements->get_published_items(),
603
-				'currency'      => wpinv_currency_symbol(),
604
-				'position'      => wpinv_currency_position(),
605
-				'decimals'      => (int) wpinv_decimals(),
606
-				'thousands_sep' => wpinv_thousands_separator(),
607
-				'decimals_sep'  => wpinv_decimal_separator(),
608
-				'form_items'    => $this->form_elements->get_form_items( $post->ID ),
609
-				'is_default'    => $post->ID == $this->default_payment_form,
610
-			) );
611
-
612
-			wp_enqueue_script( 'wpinv-admin-payment-form-script' );
613
-		}
614
-
615
-		if ( $page == 'wpinv-subscriptions' ) {
616
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
617
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
618
-		}
619
-
620
-		if ( $page == 'wpinv-reports' ) {
621
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
622
-		}
623
-
624
-	}
625
-
626
-	public function admin_body_class( $classes ) {
627
-		global $pagenow, $post, $current_screen;
628
-
629
-		if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
630
-			$classes .= ' wpinv-cpt';
631
-		}
632
-
633
-		$page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
634
-
635
-		$add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
636
-		if ( $add_class ) {
637
-			$classes .= ' wpi-' . wpinv_sanitize_key( $page );
638
-		}
639
-
640
-		$settings_class = array();
641
-		if ( $page == 'wpinv-settings' ) {
642
-			if ( !empty( $_REQUEST['tab'] ) ) {
643
-				$settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
644
-			}
645
-
646
-			if ( !empty( $_REQUEST['section'] ) ) {
647
-				$settings_class[] = sanitize_text_field( $_REQUEST['section'] );
648
-			}
649
-
650
-			$settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
651
-		}
652
-
653
-		if ( !empty( $settings_class ) ) {
654
-			$classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
655
-		}
656
-
657
-		$post_type = wpinv_admin_post_type();
658
-
659
-		if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
660
-			return $classes .= ' wpinv';
661
-		}
662
-
663
-		if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
664
-			$classes .= ' wpi-editable-n';
665
-		}
666
-
667
-		return $classes;
668
-	}
669
-
670
-	public function admin_print_scripts_edit_php() {
671
-
672
-	}
673
-
674
-	public function wpinv_actions() {
675
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
676
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
677
-		}
678
-	}
679
-
680
-	public function pre_get_posts( $wp_query ) {
681
-		if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
682
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
683
-		}
684
-
685
-		return $wp_query;
686
-	}
687
-
688
-	public function bp_invoicing_init() {
689
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
690
-	}
691
-
692
-	/**
693
-	 * Register widgets
694
-	 *
695
-	 */
696
-	public function register_widgets() {
697
-		$widgets = apply_filters(
698
-			'getpaid_widget_classes',
699
-			array(
700
-				'WPInv_Checkout_Widget',
701
-				'WPInv_History_Widget',
702
-				'WPInv_Receipt_Widget',
703
-				'WPInv_Subscriptions_Widget',
704
-				'WPInv_Buy_Item_Widget',
705
-				'WPInv_Messages_Widget',
706
-				'WPInv_GetPaid_Widget'
707
-			)
708
-		);
709
-
710
-		foreach ( $widgets as $widget ) {
711
-			register_widget( $widget );
712
-		}
17
+    /**
18
+     * GetPaid version.
19
+     *
20
+     * @var string
21
+     */
22
+    public $version;
23
+
24
+    /**
25
+     * Data container.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $data = array();
30
+
31
+    /**
32
+     * Form elements instance.
33
+     *
34
+     * @var WPInv_Payment_Form_Elements
35
+     */
36
+    public $form_elements;
37
+
38
+    /**
39
+     * Tax instance.
40
+     *
41
+     * @var WPInv_EUVat
42
+     */
43
+    public $tax;
44
+
45
+    /**
46
+     * @param array An array of payment gateways.
47
+     */
48
+    public $gateways;
49
+
50
+    /**
51
+     * Class constructor.
52
+     */
53
+    public function __construct() {
54
+        $this->define_constants();
55
+        $this->includes();
56
+        $this->init_hooks();
57
+        $this->set_properties();
58
+    }
59
+
60
+    /**
61
+     * Sets a custom data property.
62
+     * 
63
+     * @param string $prop The prop to set.
64
+     * @param mixed $value The value to retrieve.
65
+     */
66
+    public function set( $prop, $value ) {
67
+        $this->data[ $prop ] = $value;
68
+    }
69
+
70
+    /**
71
+     * Gets a custom data property.
72
+     * 
73
+     * @param string $prop The prop to set.
74
+     * @return mixed The value.
75
+     */
76
+    public function get( $prop ) {
77
+
78
+        if ( isset( $this->data[ $prop ] ) ) {
79
+            return $this->data[ $prop ];
80
+        }
81
+
82
+        return null;
83
+    }
84
+
85
+    /**
86
+     * Define class properties.
87
+     */
88
+    public function set_properties() {
89
+
90
+        // Sessions.
91
+        $this->set( 'session', new WPInv_Session_Handler() );
92
+        $GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
93
+        $this->form_elements = new WPInv_Payment_Form_Elements();
94
+        $this->tax           = new WPInv_EUVat();
95
+        $this->tax->init();
96
+        $GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
97
+
98
+        // Init other objects.
99
+        $this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
100
+        $this->set( 'session', new WPInv_Session_Handler() );
101
+        $this->set( 'notes', new WPInv_Notes() );
102
+        $this->set( 'api', new WPInv_API() );
103
+        $this->set( 'post_types', new GetPaid_Post_Types() );
104
+        $this->set( 'template', new GetPaid_Template() );
105
+    }
106
+
107
+        /**
108
+         * Define plugin constants.
109
+         */
110
+    public function define_constants() {
111
+        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
112
+        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
113
+        $this->version = WPINV_VERSION;
114
+    }
115
+
116
+    /**
117
+     * Hook into actions and filters.
118
+     *
119
+     * @since 1.0.19
120
+     */
121
+    protected function init_hooks() {
122
+        /* Internationalize the text strings used. */
123
+        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
124
+
125
+        /* Perform actions on admin initialization. */
126
+        add_action( 'admin_init', array( &$this, 'admin_init') );
127
+
128
+        // Init the plugin after WordPress inits.
129
+        add_action( 'init', array( $this, 'init' ), 1 );
130
+        add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
131
+        add_action( 'init', array( &$this, 'wpinv_actions' ) );
132
+
133
+        if ( class_exists( 'BuddyPress' ) ) {
134
+            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
135
+        }
136
+
137
+        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
138
+        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
139
+        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
140
+        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
141
+
142
+        if ( is_admin() ) {
143
+            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
144
+            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
145
+            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
146
+
147
+        } else {
148
+            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
149
+        }
150
+
151
+        // Fires after registering actions.
152
+        do_action( 'wpinv_actions', $this );
153
+        do_action( 'getpaid_actions', $this );
154
+        add_action( 'admin_init', array( &$this, 'activation_redirect') );
155
+
156
+    }
157
+
158
+    /**
159
+     * Maybe show the AyeCode Connect Notice.
160
+     */
161
+    public function init_ayecode_connect_helper(){
162
+        // AyeCode Connect notice
163
+        if ( is_admin() ){
164
+            // set the strings so they can be translated
165
+            $strings = array(
166
+                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
167
+                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
168
+                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
169
+                'connect_button'    => __("Connect Site","invoicing"),
170
+                'connecting_button'    => __("Connecting...","invoicing"),
171
+                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
172
+                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
173
+            );
174
+            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
175
+        }
176
+    }
177
+
178
+    public function plugins_loaded() {
179
+        /* Internationalize the text strings used. */
180
+        $this->load_textdomain();
181
+
182
+        do_action( 'wpinv_loaded' );
183
+
184
+        // Fix oxygen page builder conflict
185
+        if ( function_exists( 'ct_css_output' ) ) {
186
+            wpinv_oxygen_fix_conflict();
187
+        }
188
+    }
189
+
190
+    /**
191
+     * Load the translation of the plugin.
192
+     *
193
+     * @since 1.0
194
+     */
195
+    public function load_textdomain( $locale = NULL ) {
196
+        if ( empty( $locale ) ) {
197
+            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
198
+        }
199
+
200
+        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
201
+
202
+        unload_textdomain( 'invoicing' );
203
+        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
204
+        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
205
+
206
+        /**
207
+         * Define language constants.
208
+         */
209
+        require_once( WPINV_PLUGIN_DIR . 'language.php' );
210
+    }
211
+
212
+    /**
213
+     * Include required core files used in admin and on the frontend.
214
+     */
215
+    public function includes() {
216
+
217
+        // Start with the settings.
218
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
219
+
220
+        // Packages/libraries.
221
+        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
222
+        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
223
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
224
+
225
+        // Load functions.
226
+        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
227
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
228
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
229
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
230
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
231
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
232
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
233
+        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
234
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
235
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
236
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
237
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
238
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
239
+        require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
240
+
241
+        // Register autoloader.
242
+        try {
243
+            spl_autoload_register( array( $this, 'autoload' ), true );
244
+        } catch ( Exception $e ) {
245
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
246
+        }
247
+
248
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
249
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
250
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
251
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
252
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
253
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
254
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
255
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
256
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
257
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
258
+        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
259
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
260
+        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
261
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
262
+        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
263
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
264
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
265
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
266
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
267
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
268
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
269
+        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
270
+        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
271
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
272
+
273
+        /**
274
+         * Load the tax class.
275
+         */
276
+        if ( ! class_exists( 'WPInv_EUVat' ) ) {
277
+            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
278
+        }
279
+
280
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
281
+        if ( !empty( $gateways ) ) {
282
+            foreach ( $gateways as $gateway ) {
283
+                if ( $gateway == 'manual' ) {
284
+                    continue;
285
+                }
286
+
287
+                $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
288
+
289
+                if ( file_exists( $gateway_file ) ) {
290
+                    require_once( $gateway_file );
291
+                }
292
+            }
293
+        }
294
+
295
+        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
296
+            GetPaid_Post_Types_Admin::init();
297
+
298
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
299
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
300
+            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
301
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
302
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
303
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
304
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
305
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
306
+            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
307
+            //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
308
+            // load the user class only on the users.php page
309
+            global $pagenow;
310
+            if($pagenow=='users.php'){
311
+                new WPInv_Admin_Users();
312
+            }
313
+        }
314
+
315
+        // Register cli commands
316
+        if ( defined( 'WP_CLI' ) && WP_CLI ) {
317
+            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
318
+            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
319
+        }
320
+
321
+        // include css inliner
322
+        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
323
+            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
324
+        }
325
+
326
+        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
327
+    }
328
+
329
+    /**
330
+     * Class autoloader
331
+     *
332
+     * @param       string $class_name The name of the class to load.
333
+     * @access      public
334
+     * @since       1.0.19
335
+     * @return      void
336
+     */
337
+    public function autoload( $class_name ) {
338
+
339
+        // Normalize the class name...
340
+        $class_name  = strtolower( $class_name );
341
+
342
+        // ... and make sure it is our class.
343
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
344
+            return;
345
+        }
346
+
347
+        // Next, prepare the file name from the class.
348
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
349
+
350
+        // Base path of the classes.
351
+        $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
352
+
353
+        // And an array of possible locations in order of importance.
354
+        $locations = array(
355
+            "$plugin_path/includes",
356
+            "$plugin_path/includes/data-stores",
357
+            "$plugin_path/includes/gateways",
358
+            "$plugin_path/includes/api",
359
+            "$plugin_path/includes/admin",
360
+            "$plugin_path/includes/admin/meta-boxes",
361
+        );
362
+
363
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
364
+
365
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
366
+                include trailingslashit( $location ) . $file_name;
367
+                break;
368
+            }
369
+
370
+        }
371
+
372
+    }
373
+
374
+    /**
375
+     * Inits hooks etc.
376
+     */
377
+    public function init() {
378
+
379
+        // Fires before getpaid inits.
380
+        do_action( 'before_getpaid_init', $this );
381
+
382
+        // Load default gateways.
383
+        $gateways = apply_filters(
384
+            'getpaid_default_gateways',
385
+            array(
386
+                'manual'        => 'GetPaid_Manual_Gateway',
387
+                'paypal'        => 'GetPaid_Paypal_Gateway',
388
+                'worldpay'      => 'GetPaid_Worldpay_Gateway',
389
+                'bank_transfer' => 'GetPaid_Bank_Transfer_Gateway',
390
+                'authorizenet'  => 'GetPaid_Authorize_Net_Gateway',
391
+            )
392
+        );
393
+
394
+        foreach ( $gateways as $id => $class ) {
395
+            $this->gateways[ $id ] = new $class();
396
+        }
397
+
398
+        // Fires after getpaid inits.
399
+        do_action( 'getpaid_init', $this );
400
+
401
+    }
402
+
403
+    /**
404
+     * Checks if this is an IPN request and processes it.
405
+     */
406
+    public function maybe_process_ipn() {
407
+
408
+        // Ensure that this is an IPN request.
409
+        if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
410
+            return;
411
+        }
412
+
413
+        $gateway = wpinv_clean( $_GET['wpi-gateway'] );
414
+
415
+        do_action( 'wpinv_verify_payment_ipn', $gateway );
416
+        do_action( "wpinv_verify_{$gateway}_ipn" );
417
+        exit;
418
+
419
+    }
420
+
421
+    public function admin_init() {
422
+        $this->default_payment_form = wpinv_get_default_payment_form();
423
+        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
424
+    }
425
+
426
+    public function activation_redirect() {
427
+        // Bail if no activation redirect
428
+        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
429
+            return;
430
+        }
431
+
432
+        // Delete the redirect transient
433
+        delete_transient( '_wpinv_activation_redirect' );
434
+
435
+        // Bail if activating from network, or bulk
436
+        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
437
+            return;
438
+        }
439
+
440
+        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
441
+        exit;
442
+    }
443
+
444
+    public function enqueue_scripts() {
445
+        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
446
+
447
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
448
+        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
449
+        wp_enqueue_style( 'wpinv_front_style' );
450
+
451
+        // Register scripts
452
+        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
453
+        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
454
+
455
+        $localize                         = array();
456
+        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
457
+        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
458
+        $localize['currency_symbol']      = wpinv_currency_symbol();
459
+        $localize['currency_pos']         = wpinv_currency_position();
460
+        $localize['thousand_sep']         = wpinv_thousands_separator();
461
+        $localize['decimal_sep']          = wpinv_decimal_separator();
462
+        $localize['decimals']             = wpinv_decimals();
463
+        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
464
+        $localize['UseTaxes']             = wpinv_use_taxes();
465
+        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
466
+        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
467
+        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
468
+
469
+        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
470
+
471
+        wp_enqueue_script( 'jquery-blockui' );
472
+        $autofill_api = wpinv_get_option('address_autofill_api');
473
+        $autofill_active = wpinv_get_option('address_autofill_active');
474
+        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
475
+            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
476
+                wp_dequeue_script( 'google-maps-api' );
477
+            }
478
+            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
479
+            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
480
+        }
481
+
482
+        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
483
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
484
+
485
+        wp_enqueue_script( 'wpinv-front-script' );
486
+        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
487
+
488
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
489
+        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
490
+    }
491
+
492
+    public function admin_enqueue_scripts( $hook ) {
493
+        global $post, $pagenow;
494
+
495
+        $post_type  = wpinv_admin_post_type();
496
+        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
497
+        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
498
+
499
+        $jquery_ui_css = false;
500
+        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
501
+            $jquery_ui_css = true;
502
+        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
503
+            $jquery_ui_css = true;
504
+        }
505
+        if ( $jquery_ui_css ) {
506
+            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
507
+            wp_enqueue_style( 'jquery-ui-css' );
508
+            wp_deregister_style( 'yoast-seo-select2' );
509
+            wp_deregister_style( 'yoast-seo-monorepo' );
510
+        }
511
+
512
+        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
513
+        wp_enqueue_style( 'wpinv_meta_box_style' );
514
+
515
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
516
+        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
517
+        wp_enqueue_style( 'wpinv_admin_style' );
518
+
519
+        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
520
+        if ( $page == 'wpinv-subscriptions' ) {
521
+            wp_enqueue_script( 'jquery-ui-datepicker' );
522
+            wp_deregister_style( 'yoast-seo-select2' );
523
+            wp_deregister_style( 'yoast-seo-monorepo' );
524
+        }
525
+
526
+        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
527
+            wp_enqueue_script( 'jquery-ui-datepicker' );
528
+        }
529
+
530
+        wp_enqueue_style( 'wp-color-picker' );
531
+        wp_enqueue_script( 'wp-color-picker' );
532
+
533
+        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
534
+
535
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
536
+            $autofill_api = wpinv_get_option('address_autofill_api');
537
+            $autofill_active = wpinv_get_option('address_autofill_active');
538
+            if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api)) {
539
+                wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
540
+                wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery'), '', true);
541
+            }
542
+        }
543
+
544
+        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
545
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
546
+
547
+        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
548
+        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
549
+        wp_enqueue_script( 'wpinv-admin-script' );
550
+
551
+        $localize                               = array();
552
+        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
553
+        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
554
+        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
555
+        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
556
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
557
+        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
558
+        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
559
+        $localize['tax']                        = wpinv_tax_amount();
560
+        $localize['discount']                   = wpinv_discount_amount();
561
+        $localize['currency_symbol']            = wpinv_currency_symbol();
562
+        $localize['currency_pos']               = wpinv_currency_position();
563
+        $localize['thousand_sep']               = wpinv_thousands_separator();
564
+        $localize['decimal_sep']                = wpinv_decimal_separator();
565
+        $localize['decimals']                   = wpinv_decimals();
566
+        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
567
+        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
568
+        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
569
+        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
570
+        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
571
+        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
572
+        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
573
+        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
574
+        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
575
+        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
576
+        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
577
+        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
578
+        $localize['action_edit']                = __( 'Edit', 'invoicing' );
579
+        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
580
+        $localize['item_description']           = __( 'Item Description', 'invoicing' );
581
+        $localize['discount_description']       = __( 'Discount Description', 'invoicing' );
582
+        $localize['invoice_description']        = __( 'Invoice Description', 'invoicing' );
583
+        $localize['searching']                  = __( 'Searching', 'invoicing' );
584
+
585
+        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
586
+
587
+        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
588
+
589
+        // Load payment form scripts on our admin pages only.
590
+        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
591
+
592
+            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
593
+            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
594
+            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
595
+
596
+            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
597
+            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
598
+
599
+            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
600
+                'elements'      => $this->form_elements->get_elements(),
601
+                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
602
+                'all_items'     => $this->form_elements->get_published_items(),
603
+                'currency'      => wpinv_currency_symbol(),
604
+                'position'      => wpinv_currency_position(),
605
+                'decimals'      => (int) wpinv_decimals(),
606
+                'thousands_sep' => wpinv_thousands_separator(),
607
+                'decimals_sep'  => wpinv_decimal_separator(),
608
+                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
609
+                'is_default'    => $post->ID == $this->default_payment_form,
610
+            ) );
611
+
612
+            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
613
+        }
614
+
615
+        if ( $page == 'wpinv-subscriptions' ) {
616
+            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
617
+            wp_enqueue_script( 'wpinv-sub-admin-script' );
618
+        }
619
+
620
+        if ( $page == 'wpinv-reports' ) {
621
+            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
622
+        }
623
+
624
+    }
625
+
626
+    public function admin_body_class( $classes ) {
627
+        global $pagenow, $post, $current_screen;
628
+
629
+        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
630
+            $classes .= ' wpinv-cpt';
631
+        }
632
+
633
+        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
634
+
635
+        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
636
+        if ( $add_class ) {
637
+            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
638
+        }
639
+
640
+        $settings_class = array();
641
+        if ( $page == 'wpinv-settings' ) {
642
+            if ( !empty( $_REQUEST['tab'] ) ) {
643
+                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
644
+            }
645
+
646
+            if ( !empty( $_REQUEST['section'] ) ) {
647
+                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
648
+            }
649
+
650
+            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
651
+        }
652
+
653
+        if ( !empty( $settings_class ) ) {
654
+            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
655
+        }
656
+
657
+        $post_type = wpinv_admin_post_type();
658
+
659
+        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
660
+            return $classes .= ' wpinv';
661
+        }
662
+
663
+        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
664
+            $classes .= ' wpi-editable-n';
665
+        }
666
+
667
+        return $classes;
668
+    }
669
+
670
+    public function admin_print_scripts_edit_php() {
671
+
672
+    }
673
+
674
+    public function wpinv_actions() {
675
+        if ( isset( $_REQUEST['wpi_action'] ) ) {
676
+            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
677
+        }
678
+    }
679
+
680
+    public function pre_get_posts( $wp_query ) {
681
+        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
682
+            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
683
+        }
684
+
685
+        return $wp_query;
686
+    }
687
+
688
+    public function bp_invoicing_init() {
689
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
690
+    }
691
+
692
+    /**
693
+     * Register widgets
694
+     *
695
+     */
696
+    public function register_widgets() {
697
+        $widgets = apply_filters(
698
+            'getpaid_widget_classes',
699
+            array(
700
+                'WPInv_Checkout_Widget',
701
+                'WPInv_History_Widget',
702
+                'WPInv_Receipt_Widget',
703
+                'WPInv_Subscriptions_Widget',
704
+                'WPInv_Buy_Item_Widget',
705
+                'WPInv_Messages_Widget',
706
+                'WPInv_GetPaid_Widget'
707
+            )
708
+        );
709
+
710
+        foreach ( $widgets as $widget ) {
711
+            register_widget( $widget );
712
+        }
713 713
 		
714
-	}
714
+    }
715 715
 
716
-	/**
717
-	 * Remove our pages from yoast sitemaps.
718
-	 *
719
-	 * @since 1.0.19
720
-	 * @param int[] $excluded_posts_ids
721
-	 */
722
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
716
+    /**
717
+     * Remove our pages from yoast sitemaps.
718
+     *
719
+     * @since 1.0.19
720
+     * @param int[] $excluded_posts_ids
721
+     */
722
+    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
723 723
 
724
-		// Ensure that we have an array.
725
-		if ( ! is_array( $excluded_posts_ids ) ) {
726
-			$excluded_posts_ids = array();
727
-		}
724
+        // Ensure that we have an array.
725
+        if ( ! is_array( $excluded_posts_ids ) ) {
726
+            $excluded_posts_ids = array();
727
+        }
728 728
 
729
-		// Prepare our pages.
730
-		$our_pages = array();
729
+        // Prepare our pages.
730
+        $our_pages = array();
731 731
 
732
-		// Checkout page.
733
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
732
+        // Checkout page.
733
+        $our_pages[] = wpinv_get_option( 'checkout_page', false );
734 734
 
735
-		// Success page.
736
-		$our_pages[] = wpinv_get_option( 'success_page', false );
735
+        // Success page.
736
+        $our_pages[] = wpinv_get_option( 'success_page', false );
737 737
 
738
-		// Failure page.
739
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
738
+        // Failure page.
739
+        $our_pages[] = wpinv_get_option( 'failure_page', false );
740 740
 
741
-		// History page.
742
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
741
+        // History page.
742
+        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
743 743
 
744
-		// Subscriptions page.
745
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
744
+        // Subscriptions page.
745
+        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
746 746
 
747
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
747
+        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
748 748
 
749
-		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
750
-		return array_unique( $excluded_posts_ids );
749
+        $excluded_posts_ids = $excluded_posts_ids + $our_pages;
750
+        return array_unique( $excluded_posts_ids );
751 751
 
752
-	}
752
+    }
753 753
 
754
-	public function wp_footer() {
755
-		echo '
754
+    public function wp_footer() {
755
+        echo '
756 756
 			<div class="bsui">
757 757
 				<div  id="getpaid-payment-modal" class="modal" tabindex="-1" role="dialog">
758 758
 					<div class="modal-dialog modal-dialog-centered modal-lg" role="checkout" style="max-width: 650px;">
@@ -763,6 +763,6 @@  discard block
 block discarded – undo
763 763
 				</div>
764 764
 			</div>
765 765
 		';
766
-	}
766
+    }
767 767
 
768 768
 }
Please login to merge, or discard this patch.
Spacing   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Main Invoicing class.
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * @param string $prop The prop to set.
64 64
 	 * @param mixed $value The value to retrieve.
65 65
 	 */
66
-	public function set( $prop, $value ) {
67
-		$this->data[ $prop ] = $value;
66
+	public function set($prop, $value) {
67
+		$this->data[$prop] = $value;
68 68
 	}
69 69
 
70 70
 	/**
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
 	 * @param string $prop The prop to set.
74 74
 	 * @return mixed The value.
75 75
 	 */
76
-	public function get( $prop ) {
76
+	public function get($prop) {
77 77
 
78
-		if ( isset( $this->data[ $prop ] ) ) {
79
-			return $this->data[ $prop ];
78
+		if (isset($this->data[$prop])) {
79
+			return $this->data[$prop];
80 80
 		}
81 81
 
82 82
 		return null;
@@ -88,28 +88,28 @@  discard block
 block discarded – undo
88 88
 	public function set_properties() {
89 89
 
90 90
 		// Sessions.
91
-		$this->set( 'session', new WPInv_Session_Handler() );
92
-		$GLOBALS['wpi_session'] = $this->get( 'session' ); // Backwards compatibility.
91
+		$this->set('session', new WPInv_Session_Handler());
92
+		$GLOBALS['wpi_session'] = $this->get('session'); // Backwards compatibility.
93 93
 		$this->form_elements = new WPInv_Payment_Form_Elements();
94 94
 		$this->tax           = new WPInv_EUVat();
95 95
 		$this->tax->init();
96 96
 		$GLOBALS['wpinv_euvat'] = $this->tax; // Backwards compatibility.
97 97
 
98 98
 		// Init other objects.
99
-		$this->set( 'reports', new WPInv_Reports() ); // TODO: Refactor.
100
-		$this->set( 'session', new WPInv_Session_Handler() );
101
-		$this->set( 'notes', new WPInv_Notes() );
102
-		$this->set( 'api', new WPInv_API() );
103
-		$this->set( 'post_types', new GetPaid_Post_Types() );
104
-		$this->set( 'template', new GetPaid_Template() );
99
+		$this->set('reports', new WPInv_Reports()); // TODO: Refactor.
100
+		$this->set('session', new WPInv_Session_Handler());
101
+		$this->set('notes', new WPInv_Notes());
102
+		$this->set('api', new WPInv_API());
103
+		$this->set('post_types', new GetPaid_Post_Types());
104
+		$this->set('template', new GetPaid_Template());
105 105
 	}
106 106
 
107 107
 	 /**
108 108
 	 * Define plugin constants.
109 109
 	 */
110 110
 	public function define_constants() {
111
-		define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
112
-		define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
111
+		define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
112
+		define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
113 113
 		$this->version = WPINV_VERSION;
114 114
 	}
115 115
 
@@ -120,58 +120,58 @@  discard block
 block discarded – undo
120 120
 	 */
121 121
 	protected function init_hooks() {
122 122
 		/* Internationalize the text strings used. */
123
-		add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
123
+		add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
124 124
 
125 125
 		/* Perform actions on admin initialization. */
126
-		add_action( 'admin_init', array( &$this, 'admin_init') );
126
+		add_action('admin_init', array(&$this, 'admin_init'));
127 127
 
128 128
 		// Init the plugin after WordPress inits.
129
-		add_action( 'init', array( $this, 'init' ), 1 );
130
-		add_action( 'getpaid_init', array( $this, 'maybe_process_ipn' ), 5 );
131
-		add_action( 'init', array( &$this, 'wpinv_actions' ) );
129
+		add_action('init', array($this, 'init'), 1);
130
+		add_action('getpaid_init', array($this, 'maybe_process_ipn'), 5);
131
+		add_action('init', array(&$this, 'wpinv_actions'));
132 132
 
133
-		if ( class_exists( 'BuddyPress' ) ) {
134
-			add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
133
+		if (class_exists('BuddyPress')) {
134
+			add_action('bp_include', array(&$this, 'bp_invoicing_init'));
135 135
 		}
136 136
 
137
-		add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
138
-		add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
139
-		add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
140
-		add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
137
+		add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
138
+		add_action('wp_footer', array(&$this, 'wp_footer'));
139
+		add_action('widgets_init', array(&$this, 'register_widgets'));
140
+		add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
141 141
 
142
-		if ( is_admin() ) {
143
-			add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
144
-			add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
145
-			add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
142
+		if (is_admin()) {
143
+			add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
144
+			add_filter('admin_body_class', array(&$this, 'admin_body_class'));
145
+			add_action('admin_init', array(&$this, 'init_ayecode_connect_helper'));
146 146
 
147 147
 		} else {
148
-			add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
148
+			add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
149 149
 		}
150 150
 
151 151
 		// Fires after registering actions.
152
-		do_action( 'wpinv_actions', $this );
153
-		do_action( 'getpaid_actions', $this );
154
-		add_action( 'admin_init', array( &$this, 'activation_redirect') );
152
+		do_action('wpinv_actions', $this);
153
+		do_action('getpaid_actions', $this);
154
+		add_action('admin_init', array(&$this, 'activation_redirect'));
155 155
 
156 156
 	}
157 157
 
158 158
 	/**
159 159
 	 * Maybe show the AyeCode Connect Notice.
160 160
 	 */
161
-	public function init_ayecode_connect_helper(){
161
+	public function init_ayecode_connect_helper() {
162 162
 		// AyeCode Connect notice
163
-		if ( is_admin() ){
163
+		if (is_admin()) {
164 164
 			// set the strings so they can be translated
165 165
 			$strings = array(
166
-				'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
167
-				'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
168
-				'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
169
-				'connect_button'    => __("Connect Site","invoicing"),
170
-				'connecting_button'    => __("Connecting...","invoicing"),
171
-				'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
172
-				'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
166
+				'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
167
+				'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
168
+				'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
169
+				'connect_button'    => __("Connect Site", "invoicing"),
170
+				'connecting_button'    => __("Connecting...", "invoicing"),
171
+				'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
172
+				'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
173 173
 			);
174
-			new AyeCode_Connect_Helper($strings,array('wpi-addons'));
174
+			new AyeCode_Connect_Helper($strings, array('wpi-addons'));
175 175
 		}
176 176
 	}
177 177
 
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 		/* Internationalize the text strings used. */
180 180
 		$this->load_textdomain();
181 181
 
182
-		do_action( 'wpinv_loaded' );
182
+		do_action('wpinv_loaded');
183 183
 
184 184
 		// Fix oxygen page builder conflict
185
-		if ( function_exists( 'ct_css_output' ) ) {
185
+		if (function_exists('ct_css_output')) {
186 186
 			wpinv_oxygen_fix_conflict();
187 187
 		}
188 188
 	}
@@ -192,21 +192,21 @@  discard block
 block discarded – undo
192 192
 	 *
193 193
 	 * @since 1.0
194 194
 	 */
195
-	public function load_textdomain( $locale = NULL ) {
196
-		if ( empty( $locale ) ) {
197
-			$locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
195
+	public function load_textdomain($locale = NULL) {
196
+		if (empty($locale)) {
197
+			$locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
198 198
 		}
199 199
 
200
-		$locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
200
+		$locale = apply_filters('plugin_locale', $locale, 'invoicing');
201 201
 
202
-		unload_textdomain( 'invoicing' );
203
-		load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
204
-		load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
202
+		unload_textdomain('invoicing');
203
+		load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
204
+		load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
205 205
 
206 206
 		/**
207 207
 		 * Define language constants.
208 208
 		 */
209
-		require_once( WPINV_PLUGIN_DIR . 'language.php' );
209
+		require_once(WPINV_PLUGIN_DIR . 'language.php');
210 210
 	}
211 211
 
212 212
 	/**
@@ -215,115 +215,115 @@  discard block
 block discarded – undo
215 215
 	public function includes() {
216 216
 
217 217
 		// Start with the settings.
218
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
218
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
219 219
 
220 220
 		// Packages/libraries.
221
-		require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
222
-		require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
223
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
221
+		require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
222
+		require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
223
+		require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php');
224 224
 
225 225
 		// Load functions.
226
-		require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
227
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
228
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
229
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
230
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
231
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
232
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
233
-		require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
234
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
235
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
236
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
237
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
238
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
239
-		require_once( WPINV_PLUGIN_DIR . 'includes/error-functions.php' );
226
+		require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php');
227
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
228
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
229
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
230
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
231
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
232
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
233
+		require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php');
234
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
235
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
236
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
237
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
238
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
239
+		require_once(WPINV_PLUGIN_DIR . 'includes/error-functions.php');
240 240
 
241 241
 		// Register autoloader.
242 242
 		try {
243
-			spl_autoload_register( array( $this, 'autoload' ), true );
244
-		} catch ( Exception $e ) {
245
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
246
-		}
247
-
248
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
249
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
250
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
251
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
252
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
253
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
254
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
255
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
256
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
257
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
258
-		require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
259
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
260
-		require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
261
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
262
-		require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
263
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
264
-		require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
265
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
266
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
267
-		require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
268
-		require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
269
-		require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
270
-		require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
271
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
243
+			spl_autoload_register(array($this, 'autoload'), true);
244
+		} catch (Exception $e) {
245
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
246
+		}
247
+
248
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
249
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
250
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
251
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
252
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
253
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
254
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
255
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
256
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
257
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
258
+		require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
259
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
260
+		require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
261
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
262
+		require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
263
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
264
+		require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
265
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
266
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
267
+		require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
268
+		require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
269
+		require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
270
+		require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
271
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php');
272 272
 
273 273
 		/**
274 274
 		 * Load the tax class.
275 275
 		 */
276
-		if ( ! class_exists( 'WPInv_EUVat' ) ) {
277
-			require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
276
+		if (!class_exists('WPInv_EUVat')) {
277
+			require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
278 278
 		}
279 279
 
280
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
281
-		if ( !empty( $gateways ) ) {
282
-			foreach ( $gateways as $gateway ) {
283
-				if ( $gateway == 'manual' ) {
280
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
281
+		if (!empty($gateways)) {
282
+			foreach ($gateways as $gateway) {
283
+				if ($gateway == 'manual') {
284 284
 					continue;
285 285
 				}
286 286
 
287 287
 				$gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
288 288
 
289
-				if ( file_exists( $gateway_file ) ) {
290
-					require_once( $gateway_file );
289
+				if (file_exists($gateway_file)) {
290
+					require_once($gateway_file);
291 291
 				}
292 292
 			}
293 293
 		}
294 294
 
295
-		if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
295
+		if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
296 296
 			GetPaid_Post_Types_Admin::init();
297 297
 
298
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
299
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
298
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
299
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
300 300
 			//require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
301
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
302
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
303
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
304
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
305
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
306
-			require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
301
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
302
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
303
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
304
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
305
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
306
+			require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
307 307
 			//require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
308 308
 			// load the user class only on the users.php page
309 309
 			global $pagenow;
310
-			if($pagenow=='users.php'){
310
+			if ($pagenow == 'users.php') {
311 311
 				new WPInv_Admin_Users();
312 312
 			}
313 313
 		}
314 314
 
315 315
 		// Register cli commands
316
-		if ( defined( 'WP_CLI' ) && WP_CLI ) {
317
-			require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
318
-			WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
316
+		if (defined('WP_CLI') && WP_CLI) {
317
+			require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
318
+			WP_CLI::add_command('invoicing', 'WPInv_CLI');
319 319
 		}
320 320
 
321 321
 		// include css inliner
322
-		if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
323
-			include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
322
+		if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
323
+			include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
324 324
 		}
325 325
 
326
-		require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
326
+		require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
327 327
 	}
328 328
 
329 329
 	/**
@@ -334,21 +334,21 @@  discard block
 block discarded – undo
334 334
 	 * @since       1.0.19
335 335
 	 * @return      void
336 336
 	 */
337
-	public function autoload( $class_name ) {
337
+	public function autoload($class_name) {
338 338
 
339 339
 		// Normalize the class name...
340
-		$class_name  = strtolower( $class_name );
340
+		$class_name = strtolower($class_name);
341 341
 
342 342
 		// ... and make sure it is our class.
343
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
343
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
344 344
 			return;
345 345
 		}
346 346
 
347 347
 		// Next, prepare the file name from the class.
348
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
348
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
349 349
 
350 350
 		// Base path of the classes.
351
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
351
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
352 352
 
353 353
 		// And an array of possible locations in order of importance.
354 354
 		$locations = array(
@@ -360,10 +360,10 @@  discard block
 block discarded – undo
360 360
 			"$plugin_path/includes/admin/meta-boxes",
361 361
 		);
362 362
 
363
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
363
+		foreach (apply_filters('getpaid_autoload_locations', $locations) as $location) {
364 364
 
365
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
366
-				include trailingslashit( $location ) . $file_name;
365
+			if (file_exists(trailingslashit($location) . $file_name)) {
366
+				include trailingslashit($location) . $file_name;
367 367
 				break;
368 368
 			}
369 369
 
@@ -377,7 +377,7 @@  discard block
 block discarded – undo
377 377
 	public function init() {
378 378
 
379 379
 		// Fires before getpaid inits.
380
-		do_action( 'before_getpaid_init', $this );
380
+		do_action('before_getpaid_init', $this);
381 381
 
382 382
 		// Load default gateways.
383 383
 		$gateways = apply_filters(
@@ -391,12 +391,12 @@  discard block
 block discarded – undo
391 391
 			)
392 392
 		);
393 393
 
394
-		foreach ( $gateways as $id => $class ) {
395
-			$this->gateways[ $id ] = new $class();
394
+		foreach ($gateways as $id => $class) {
395
+			$this->gateways[$id] = new $class();
396 396
 		}
397 397
 
398 398
 		// Fires after getpaid inits.
399
-		do_action( 'getpaid_init', $this );
399
+		do_action('getpaid_init', $this);
400 400
 
401 401
 	}
402 402
 
@@ -406,131 +406,131 @@  discard block
 block discarded – undo
406 406
 	public function maybe_process_ipn() {
407 407
 
408 408
 		// Ensure that this is an IPN request.
409
-		if ( empty( $_GET['wpi-listener'] ) || 'IPN' !== $_GET['wpi-listener'] || empty( $_GET['wpi-gateway'] ) ) {
409
+		if (empty($_GET['wpi-listener']) || 'IPN' !== $_GET['wpi-listener'] || empty($_GET['wpi-gateway'])) {
410 410
 			return;
411 411
 		}
412 412
 
413
-		$gateway = wpinv_clean( $_GET['wpi-gateway'] );
413
+		$gateway = wpinv_clean($_GET['wpi-gateway']);
414 414
 
415
-		do_action( 'wpinv_verify_payment_ipn', $gateway );
416
-		do_action( "wpinv_verify_{$gateway}_ipn" );
415
+		do_action('wpinv_verify_payment_ipn', $gateway);
416
+		do_action("wpinv_verify_{$gateway}_ipn");
417 417
 		exit;
418 418
 
419 419
 	}
420 420
 
421 421
 	public function admin_init() {
422 422
 		$this->default_payment_form = wpinv_get_default_payment_form();
423
-		add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
423
+		add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
424 424
 	}
425 425
 
426 426
 	public function activation_redirect() {
427 427
 		// Bail if no activation redirect
428
-		if ( !get_transient( '_wpinv_activation_redirect' ) ) {
428
+		if (!get_transient('_wpinv_activation_redirect')) {
429 429
 			return;
430 430
 		}
431 431
 
432 432
 		// Delete the redirect transient
433
-		delete_transient( '_wpinv_activation_redirect' );
433
+		delete_transient('_wpinv_activation_redirect');
434 434
 
435 435
 		// Bail if activating from network, or bulk
436
-		if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
436
+		if (is_network_admin() || isset($_GET['activate-multi'])) {
437 437
 			return;
438 438
 		}
439 439
 
440
-		wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
440
+		wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
441 441
 		exit;
442 442
 	}
443 443
 
444 444
 	public function enqueue_scripts() {
445
-		$suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
445
+		$suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
446 446
 
447
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
448
-		wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
449
-		wp_enqueue_style( 'wpinv_front_style' );
447
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css');
448
+		wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version);
449
+		wp_enqueue_style('wpinv_front_style');
450 450
 
451 451
 		// Register scripts
452
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
453
-		wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
452
+		wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
453
+		wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
454 454
 
455 455
 		$localize                         = array();
456
-		$localize['ajax_url']             = admin_url( 'admin-ajax.php' );
457
-		$localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
456
+		$localize['ajax_url']             = admin_url('admin-ajax.php');
457
+		$localize['nonce']                = wp_create_nonce('wpinv-nonce');
458 458
 		$localize['currency_symbol']      = wpinv_currency_symbol();
459 459
 		$localize['currency_pos']         = wpinv_currency_position();
460 460
 		$localize['thousand_sep']         = wpinv_thousands_separator();
461 461
 		$localize['decimal_sep']          = wpinv_decimal_separator();
462 462
 		$localize['decimals']             = wpinv_decimals();
463
-		$localize['txtComplete']          = __( 'Continue', 'invoicing' );
463
+		$localize['txtComplete']          = __('Continue', 'invoicing');
464 464
 		$localize['UseTaxes']             = wpinv_use_taxes();
465
-		$localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
466
-		$localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
467
-		$localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
465
+		$localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
466
+		$localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
467
+		$localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
468 468
 
469
-		$localize = apply_filters( 'wpinv_front_js_localize', $localize );
469
+		$localize = apply_filters('wpinv_front_js_localize', $localize);
470 470
 
471
-		wp_enqueue_script( 'jquery-blockui' );
471
+		wp_enqueue_script('jquery-blockui');
472 472
 		$autofill_api = wpinv_get_option('address_autofill_api');
473 473
 		$autofill_active = wpinv_get_option('address_autofill_active');
474
-		if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
475
-			if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
476
-				wp_dequeue_script( 'google-maps-api' );
474
+		if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
475
+			if (wp_script_is('google-maps-api', 'enqueued')) {
476
+				wp_dequeue_script('google-maps-api');
477 477
 			}
478
-			wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
479
-			wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
478
+			wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
479
+			wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
480 480
 		}
481 481
 
482
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
483
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
482
+		wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
483
+		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
484 484
 
485
-		wp_enqueue_script( 'wpinv-front-script' );
486
-		wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
485
+		wp_enqueue_script('wpinv-front-script');
486
+		wp_localize_script('wpinv-front-script', 'WPInv', $localize);
487 487
 
488
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
489
-		wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
488
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
489
+		wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
490 490
 	}
491 491
 
492
-	public function admin_enqueue_scripts( $hook ) {
492
+	public function admin_enqueue_scripts($hook) {
493 493
 		global $post, $pagenow;
494 494
 
495 495
 		$post_type  = wpinv_admin_post_type();
496
-		$suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
497
-		$page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
496
+		$suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
497
+		$page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
498 498
 
499 499
 		$jquery_ui_css = false;
500
-		if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
500
+		if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
501 501
 			$jquery_ui_css = true;
502
-		} else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
502
+		} else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
503 503
 			$jquery_ui_css = true;
504 504
 		}
505
-		if ( $jquery_ui_css ) {
506
-			wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
507
-			wp_enqueue_style( 'jquery-ui-css' );
508
-			wp_deregister_style( 'yoast-seo-select2' );
509
-			wp_deregister_style( 'yoast-seo-monorepo' );
505
+		if ($jquery_ui_css) {
506
+			wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
507
+			wp_enqueue_style('jquery-ui-css');
508
+			wp_deregister_style('yoast-seo-select2');
509
+			wp_deregister_style('yoast-seo-monorepo');
510 510
 		}
511 511
 
512
-		wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
513
-		wp_enqueue_style( 'wpinv_meta_box_style' );
512
+		wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
513
+		wp_enqueue_style('wpinv_meta_box_style');
514 514
 
515
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
516
-		wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
517
-		wp_enqueue_style( 'wpinv_admin_style' );
515
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
516
+		wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version);
517
+		wp_enqueue_style('wpinv_admin_style');
518 518
 
519
-		$enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
520
-		if ( $page == 'wpinv-subscriptions' ) {
521
-			wp_enqueue_script( 'jquery-ui-datepicker' );
522
-			wp_deregister_style( 'yoast-seo-select2' );
523
-			wp_deregister_style( 'yoast-seo-monorepo' );
519
+		$enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
520
+		if ($page == 'wpinv-subscriptions') {
521
+			wp_enqueue_script('jquery-ui-datepicker');
522
+			wp_deregister_style('yoast-seo-select2');
523
+			wp_deregister_style('yoast-seo-monorepo');
524 524
 		}
525 525
 
526
-		if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
527
-			wp_enqueue_script( 'jquery-ui-datepicker' );
526
+		if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
527
+			wp_enqueue_script('jquery-ui-datepicker');
528 528
 		}
529 529
 
530
-		wp_enqueue_style( 'wp-color-picker' );
531
-		wp_enqueue_script( 'wp-color-picker' );
530
+		wp_enqueue_style('wp-color-picker');
531
+		wp_enqueue_script('wp-color-picker');
532 532
 
533
-		wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
533
+		wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
534 534
 
535 535
 		if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
536 536
 			$autofill_api = wpinv_get_option('address_autofill_api');
@@ -541,21 +541,21 @@  discard block
 block discarded – undo
541 541
 			}
542 542
 		}
543 543
 
544
-		wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
545
-		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
544
+		wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
545
+		wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
546 546
 
547
-		$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
548
-		wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
549
-		wp_enqueue_script( 'wpinv-admin-script' );
547
+		$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
548
+		wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version);
549
+		wp_enqueue_script('wpinv-admin-script');
550 550
 
551 551
 		$localize                               = array();
552
-		$localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
553
-		$localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
554
-		$localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
555
-		$localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
556
-		$localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
557
-		$localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
558
-		$localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
552
+		$localize['ajax_url']                   = admin_url('admin-ajax.php');
553
+		$localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
554
+		$localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
555
+		$localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
556
+		$localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
557
+		$localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
558
+		$localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
559 559
 		$localize['tax']                        = wpinv_tax_amount();
560 560
 		$localize['discount']                   = wpinv_discount_amount();
561 561
 		$localize['currency_symbol']            = wpinv_currency_symbol();
@@ -563,104 +563,104 @@  discard block
 block discarded – undo
563 563
 		$localize['thousand_sep']               = wpinv_thousands_separator();
564 564
 		$localize['decimal_sep']                = wpinv_decimal_separator();
565 565
 		$localize['decimals']                   = wpinv_decimals();
566
-		$localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
567
-		$localize['status_publish']             = wpinv_status_nicename( 'publish' );
568
-		$localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
569
-		$localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
570
-		$localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
571
-		$localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
572
-		$localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
573
-		$localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
574
-		$localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
575
-		$localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
576
-		$localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
577
-		$localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
578
-		$localize['action_edit']                = __( 'Edit', 'invoicing' );
579
-		$localize['action_cancel']              = __( 'Cancel', 'invoicing' );
580
-		$localize['item_description']           = __( 'Item Description', 'invoicing' );
581
-		$localize['discount_description']       = __( 'Discount Description', 'invoicing' );
582
-		$localize['invoice_description']        = __( 'Invoice Description', 'invoicing' );
583
-		$localize['searching']                  = __( 'Searching', 'invoicing' );
584
-
585
-		$localize = apply_filters( 'wpinv_admin_js_localize', $localize );
586
-
587
-		wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
566
+		$localize['save_invoice']               = __('Save Invoice', 'invoicing');
567
+		$localize['status_publish']             = wpinv_status_nicename('publish');
568
+		$localize['status_pending']             = wpinv_status_nicename('wpi-pending');
569
+		$localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
570
+		$localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
571
+		$localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
572
+		$localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
573
+		$localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
574
+		$localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
575
+		$localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
576
+		$localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
577
+		$localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
578
+		$localize['action_edit']                = __('Edit', 'invoicing');
579
+		$localize['action_cancel']              = __('Cancel', 'invoicing');
580
+		$localize['item_description']           = __('Item Description', 'invoicing');
581
+		$localize['discount_description']       = __('Discount Description', 'invoicing');
582
+		$localize['invoice_description']        = __('Invoice Description', 'invoicing');
583
+		$localize['searching']                  = __('Searching', 'invoicing');
584
+
585
+		$localize = apply_filters('wpinv_admin_js_localize', $localize);
586
+
587
+		wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
588 588
 
589 589
 		// Load payment form scripts on our admin pages only.
590
-		if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
590
+		if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) {
591 591
 
592
-			wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
593
-			wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
594
-			wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
592
+			wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
593
+			wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
594
+			wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
595 595
 
596
-			$version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
597
-			wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
596
+			$version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
597
+			wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
598 598
 
599
-			wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
599
+			wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
600 600
 				'elements'      => $this->form_elements->get_elements(),
601
-				'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
601
+				'form_elements' => $this->form_elements->get_form_elements($post->ID),
602 602
 				'all_items'     => $this->form_elements->get_published_items(),
603 603
 				'currency'      => wpinv_currency_symbol(),
604 604
 				'position'      => wpinv_currency_position(),
605 605
 				'decimals'      => (int) wpinv_decimals(),
606 606
 				'thousands_sep' => wpinv_thousands_separator(),
607 607
 				'decimals_sep'  => wpinv_decimal_separator(),
608
-				'form_items'    => $this->form_elements->get_form_items( $post->ID ),
608
+				'form_items'    => $this->form_elements->get_form_items($post->ID),
609 609
 				'is_default'    => $post->ID == $this->default_payment_form,
610
-			) );
610
+			));
611 611
 
612
-			wp_enqueue_script( 'wpinv-admin-payment-form-script' );
612
+			wp_enqueue_script('wpinv-admin-payment-form-script');
613 613
 		}
614 614
 
615
-		if ( $page == 'wpinv-subscriptions' ) {
616
-			wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
617
-			wp_enqueue_script( 'wpinv-sub-admin-script' );
615
+		if ($page == 'wpinv-subscriptions') {
616
+			wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
617
+			wp_enqueue_script('wpinv-sub-admin-script');
618 618
 		}
619 619
 
620
-		if ( $page == 'wpinv-reports' ) {
621
-			wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
620
+		if ($page == 'wpinv-reports') {
621
+			wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
622 622
 		}
623 623
 
624 624
 	}
625 625
 
626
-	public function admin_body_class( $classes ) {
626
+	public function admin_body_class($classes) {
627 627
 		global $pagenow, $post, $current_screen;
628 628
 
629
-		if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
629
+		if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) {
630 630
 			$classes .= ' wpinv-cpt';
631 631
 		}
632 632
 
633
-		$page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
633
+		$page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
634 634
 
635
-		$add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
636
-		if ( $add_class ) {
637
-			$classes .= ' wpi-' . wpinv_sanitize_key( $page );
635
+		$add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
636
+		if ($add_class) {
637
+			$classes .= ' wpi-' . wpinv_sanitize_key($page);
638 638
 		}
639 639
 
640 640
 		$settings_class = array();
641
-		if ( $page == 'wpinv-settings' ) {
642
-			if ( !empty( $_REQUEST['tab'] ) ) {
643
-				$settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
641
+		if ($page == 'wpinv-settings') {
642
+			if (!empty($_REQUEST['tab'])) {
643
+				$settings_class[] = sanitize_text_field($_REQUEST['tab']);
644 644
 			}
645 645
 
646
-			if ( !empty( $_REQUEST['section'] ) ) {
647
-				$settings_class[] = sanitize_text_field( $_REQUEST['section'] );
646
+			if (!empty($_REQUEST['section'])) {
647
+				$settings_class[] = sanitize_text_field($_REQUEST['section']);
648 648
 			}
649 649
 
650
-			$settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
650
+			$settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
651 651
 		}
652 652
 
653
-		if ( !empty( $settings_class ) ) {
654
-			$classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
653
+		if (!empty($settings_class)) {
654
+			$classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
655 655
 		}
656 656
 
657 657
 		$post_type = wpinv_admin_post_type();
658 658
 
659
-		if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
659
+		if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
660 660
 			return $classes .= ' wpinv';
661 661
 		}
662 662
 
663
-		if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
663
+		if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
664 664
 			$classes .= ' wpi-editable-n';
665 665
 		}
666 666
 
@@ -672,21 +672,21 @@  discard block
 block discarded – undo
672 672
 	}
673 673
 
674 674
 	public function wpinv_actions() {
675
-		if ( isset( $_REQUEST['wpi_action'] ) ) {
676
-			do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
675
+		if (isset($_REQUEST['wpi_action'])) {
676
+			do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
677 677
 		}
678 678
 	}
679 679
 
680
-	public function pre_get_posts( $wp_query ) {
681
-		if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
682
-			$wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
680
+	public function pre_get_posts($wp_query) {
681
+		if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
682
+			$wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
683 683
 		}
684 684
 
685 685
 		return $wp_query;
686 686
 	}
687 687
 
688 688
 	public function bp_invoicing_init() {
689
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
689
+		require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
690 690
 	}
691 691
 
692 692
 	/**
@@ -707,8 +707,8 @@  discard block
 block discarded – undo
707 707
 			)
708 708
 		);
709 709
 
710
-		foreach ( $widgets as $widget ) {
711
-			register_widget( $widget );
710
+		foreach ($widgets as $widget) {
711
+			register_widget($widget);
712 712
 		}
713 713
 		
714 714
 	}
@@ -719,10 +719,10 @@  discard block
 block discarded – undo
719 719
 	 * @since 1.0.19
720 720
 	 * @param int[] $excluded_posts_ids
721 721
 	 */
722
-	public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
722
+	public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
723 723
 
724 724
 		// Ensure that we have an array.
725
-		if ( ! is_array( $excluded_posts_ids ) ) {
725
+		if (!is_array($excluded_posts_ids)) {
726 726
 			$excluded_posts_ids = array();
727 727
 		}
728 728
 
@@ -730,24 +730,24 @@  discard block
 block discarded – undo
730 730
 		$our_pages = array();
731 731
 
732 732
 		// Checkout page.
733
-		$our_pages[] = wpinv_get_option( 'checkout_page', false );
733
+		$our_pages[] = wpinv_get_option('checkout_page', false);
734 734
 
735 735
 		// Success page.
736
-		$our_pages[] = wpinv_get_option( 'success_page', false );
736
+		$our_pages[] = wpinv_get_option('success_page', false);
737 737
 
738 738
 		// Failure page.
739
-		$our_pages[] = wpinv_get_option( 'failure_page', false );
739
+		$our_pages[] = wpinv_get_option('failure_page', false);
740 740
 
741 741
 		// History page.
742
-		$our_pages[] = wpinv_get_option( 'invoice_history_page', false );
742
+		$our_pages[] = wpinv_get_option('invoice_history_page', false);
743 743
 
744 744
 		// Subscriptions page.
745
-		$our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
745
+		$our_pages[] = wpinv_get_option('invoice_subscription_page', false);
746 746
 
747
-		$our_pages   = array_map( 'intval', array_filter( $our_pages ) );
747
+		$our_pages   = array_map('intval', array_filter($our_pages));
748 748
 
749 749
 		$excluded_posts_ids = $excluded_posts_ids + $our_pages;
750
-		return array_unique( $excluded_posts_ids );
750
+		return array_unique($excluded_posts_ids);
751 751
 
752 752
 	}
753 753
 
Please login to merge, or discard this patch.
includes/error-functions.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns the errors as html
@@ -14,27 +14,27 @@  discard block
 block discarded – undo
14 14
  * @param clear whether or not to clear the errors.
15 15
  * @since  1.0.19
16 16
  */
17
-function getpaid_get_errors_html( $clear = true ) {
17
+function getpaid_get_errors_html($clear = true) {
18 18
 
19 19
     $errors = '';
20
-    foreach ( wpinv_get_errors() as $error_id => $error ) {
21
-        $type     = 'error';
20
+    foreach (wpinv_get_errors() as $error_id => $error) {
21
+        $type = 'error';
22 22
 
23
-        if ( is_array( $error ) ) {
23
+        if (is_array($error)) {
24 24
             $type  = $error['type'];
25 25
             $error = $error['text'];
26 26
         }
27 27
 
28 28
         $errors .= aui()->alert(
29 29
             array(
30
-                'content'     => wp_kses_post( $error ),
30
+                'content'     => wp_kses_post($error),
31 31
                 'type'        => $type,
32 32
             )
33 33
         );
34 34
 
35 35
     }
36 36
 
37
-    if ( $clear ){
37
+    if ($clear) {
38 38
         wpinv_clear_errors();
39 39
     }
40 40
 
@@ -55,8 +55,8 @@  discard block
 block discarded – undo
55 55
  * @return array
56 56
  */
57 57
 function wpinv_get_errors() {
58
-    $errors = getpaid_session()->get( 'wpinv_errors' );
59
-    return is_array( $errors ) ? $errors : array();
58
+    $errors = getpaid_session()->get('wpinv_errors');
59
+    return is_array($errors) ? $errors : array();
60 60
 }
61 61
 
62 62
 /**
@@ -66,15 +66,15 @@  discard block
 block discarded – undo
66 66
  * @param string $error_message The error message.
67 67
  * @param string $type Either error, info, warning, primary, dark, light or success.
68 68
  */
69
-function wpinv_set_error( $error_id, $error_message, $type = 'error' ) {
69
+function wpinv_set_error($error_id, $error_message, $type = 'error') {
70 70
 
71 71
     $errors              = wpinv_get_errors();
72
-    $errors[ $error_id ] = array(
72
+    $errors[$error_id] = array(
73 73
         'type' =>  $type,
74 74
         'text' =>  $error_message,
75 75
     );
76 76
 
77
-    getpaid()->session->set( 'wpinv_errors', $errors );
77
+    getpaid()->session->set('wpinv_errors', $errors);
78 78
 }
79 79
 
80 80
 /**
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
  * 
83 83
  */
84 84
 function wpinv_has_errors() {
85
-    return count( wpinv_get_errors() ) > 0;
85
+    return count(wpinv_get_errors()) > 0;
86 86
 }
87 87
 
88 88
 /**
@@ -90,21 +90,21 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  */
92 92
 function wpinv_clear_errors() {
93
-    getpaid_session()->set( 'wpinv_errors', null );
93
+    getpaid_session()->set('wpinv_errors', null);
94 94
 }
95 95
 
96 96
 /**
97 97
  * Clears a single error.
98 98
  * 
99 99
  */
100
-function wpinv_unset_error( $error_id ) {
100
+function wpinv_unset_error($error_id) {
101 101
     $errors = wpinv_get_errors();
102 102
 
103
-    if ( isset( $errors[ $error_id ] ) ) {
104
-        unset( $errors[ $error_id ] );
103
+    if (isset($errors[$error_id])) {
104
+        unset($errors[$error_id]);
105 105
     }
106 106
 
107
-    getpaid_session()->set( 'wpinv_errors', $errors );
107
+    getpaid_session()->set('wpinv_errors', $errors);
108 108
 }
109 109
 
110 110
 /**
@@ -115,15 +115,15 @@  discard block
 block discarded – undo
115 115
  * @param string $message Message to log.
116 116
  * @param string $version Version the message was added in.
117 117
  */
118
-function getpaid_doing_it_wrong( $function, $message, $version ) {
118
+function getpaid_doing_it_wrong($function, $message, $version) {
119 119
 
120 120
 	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
121 121
 
122
-	if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
123
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
124
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
122
+	if (is_ajax() || defined('REST_REQUEST')) {
123
+		do_action('doing_it_wrong_run', $function, $message, $version);
124
+		error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
125 125
 	} else {
126
-		_doing_it_wrong( $function, $message, $version );
126
+		_doing_it_wrong($function, $message, $version);
127 127
 	}
128 128
 
129 129
 }
Please login to merge, or discard this patch.
includes/invoice-functions.php 1 patch
Spacing   +333 added lines, -333 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( $_GET['invoice_key'] );
22
+    $invoice = new WPInv_Invoice($_GET['invoice_key']);
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
84
+    return apply_filters('getpaid_invoice_post_types', $post_types);
85 85
 }
86 86
 
87 87
 /**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  * @param string $post_type The post type to check for.
92 92
  */
93
-function getpaid_is_invoice_post_type( $post_type ) {
94
-    return ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
93
+function getpaid_is_invoice_post_type($post_type) {
94
+    return !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
95 95
 }
96 96
 
97 97
 /**
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
102 102
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
103 103
  */
104
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
105
-    $data[ 'invoice_id' ] = 0;
106
-    return wpinv_insert_invoice( $data, $wp_error );
104
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
105
+    $data['invoice_id'] = 0;
106
+    return wpinv_insert_invoice($data, $wp_error);
107 107
 }
108 108
 
109 109
 /**
@@ -113,36 +113,36 @@  discard block
 block discarded – undo
113 113
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
114 114
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
115 115
  */
116
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
116
+function wpinv_update_invoice($data = array(), $wp_error = false) {
117 117
 
118 118
     // Backwards compatibility.
119
-    if ( ! empty( $data['ID'] ) ) {
119
+    if (!empty($data['ID'])) {
120 120
         $data['invoice_id'] = $data['ID'];
121 121
     }
122 122
 
123 123
     // Do we have an invoice id?
124
-    if ( empty( $data['invoice_id'] ) ) {
125
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
124
+    if (empty($data['invoice_id'])) {
125
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
126 126
     }
127 127
 
128 128
     // Retrieve the invoice.
129
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
129
+    $invoice = wpinv_get_invoice($data['invoice_id']);
130 130
 
131 131
     // And abort if it does not exist.
132
-    if ( empty( $invoice ) ) {
133
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
132
+    if (empty($invoice)) {
133
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
134 134
     }
135 135
 
136 136
     // Do not update totals for paid / refunded invoices.
137
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
137
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
138 138
 
139
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
140
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
139
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
140
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
141 141
         }
142 142
 
143 143
     }
144 144
 
145
-    return wpinv_insert_invoice( $data, $wp_error );
145
+    return wpinv_insert_invoice($data, $wp_error);
146 146
 
147 147
 }
148 148
 
@@ -153,34 +153,34 @@  discard block
 block discarded – undo
153 153
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
154 154
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
155 155
  */
156
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
156
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
157 157
 
158 158
     // Ensure that we have invoice data.
159
-    if ( empty( $data ) ) {
159
+    if (empty($data)) {
160 160
         return false;
161 161
     }
162 162
 
163 163
     // The invoice id will be provided when updating an invoice.
164
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
164
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
165 165
 
166 166
     // Retrieve the invoice.
167
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
167
+    $invoice = new WPInv_Invoice($data['invoice_id']);
168 168
 
169 169
     // Do we have an error?
170
-    if ( ! empty( $invoice->last_error ) ) {
171
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
170
+    if (!empty($invoice->last_error)) {
171
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
172 172
     }
173 173
 
174 174
     // Backwards compatibility (billing address).
175
-    if ( ! empty( $data['user_info'] ) ) {
175
+    if (!empty($data['user_info'])) {
176 176
 
177
-        foreach ( $data['user_info'] as $key => $value ) {
177
+        foreach ($data['user_info'] as $key => $value) {
178 178
 
179
-            if ( $key == 'discounts' ) {
179
+            if ($key == 'discounts') {
180 180
                 $value = (array) $value;
181
-                $data[ 'discount_code' ] = empty( $value ) ? null : $value[0];
181
+                $data['discount_code'] = empty($value) ? null : $value[0];
182 182
             } else {
183
-                $data[ $key ] = $value;
183
+                $data[$key] = $value;
184 184
             }
185 185
 
186 186
         }
@@ -188,30 +188,30 @@  discard block
 block discarded – undo
188 188
     }
189 189
 
190 190
     // Backwards compatibility.
191
-    if ( ! empty( $data['payment_details'] ) ) {
191
+    if (!empty($data['payment_details'])) {
192 192
 
193
-        foreach ( $data['payment_details'] as $key => $value ) {
194
-            $data[ $key ] = $value;
193
+        foreach ($data['payment_details'] as $key => $value) {
194
+            $data[$key] = $value;
195 195
         }
196 196
 
197 197
     }
198 198
 
199 199
     // Set up the owner of the invoice.
200
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
200
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
201 201
 
202 202
     // Make sure the user exists.
203
-    if ( ! get_userdata( $user_id ) ) {
204
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
203
+    if (!get_userdata($user_id)) {
204
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
205 205
     }
206 206
 
207
-    $address = wpinv_get_user_address( $user_id );
207
+    $address = wpinv_get_user_address($user_id);
208 208
 
209
-    foreach ( $address as $key => $value ) {
209
+    foreach ($address as $key => $value) {
210 210
 
211
-        if ( $value == '' ) {
212
-            $address[ $key ] = null;
211
+        if ($value == '') {
212
+            $address[$key] = null;
213 213
         } else {
214
-            $address[ $key ] = wpinv_clean( $value );
214
+            $address[$key] = wpinv_clean($value);
215 215
         }
216 216
 
217 217
     }
@@ -222,103 +222,103 @@  discard block
 block discarded – undo
222 222
         array(
223 223
 
224 224
             // Basic info.
225
-            'template'             => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
226
-            'email_cc'             => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
227
-            'date_created'         => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
228
-            'due_date'             => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
229
-            'date_completed'       => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
230
-            'number'               => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
231
-            'key'                  => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
232
-            'status'               => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
233
-            'post_type'            => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
234
-            'user_ip'              => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
235
-            'parent_id'            => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
236
-            'mode'                 => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
237
-            'description'          => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
225
+            'template'             => isset($data['template']) ? wpinv_clean($data['template']) : null,
226
+            'email_cc'             => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
227
+            'date_created'         => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
228
+            'due_date'             => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
229
+            'date_completed'       => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
230
+            'number'               => isset($data['number']) ? wpinv_clean($data['number']) : null,
231
+            'key'                  => isset($data['key']) ? wpinv_clean($data['key']) : null,
232
+            'status'               => isset($data['status']) ? wpinv_clean($data['status']) : null,
233
+            'post_type'            => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
234
+            'user_ip'              => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
235
+            'parent_id'            => isset($data['parent']) ? intval($data['parent']) : null,
236
+            'mode'                 => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
237
+            'description'          => isset($data['description']) ? wp_kses_post($data['description']) : null,
238 238
 
239 239
             // Payment info.
240
-            'disable_taxes'        => ! empty( $data['disable_taxes'] ),
241
-            'currency'             => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
242
-            'gateway'              => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
243
-            'transaction_id'       => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
244
-            'discount_code'        => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
245
-            'payment_form'         => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
246
-            'submission_id'        => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
247
-            'subscription_id'      => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
248
-            'is_viewed'            => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
249
-            'fees'                 => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
250
-            'discounts'            => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
251
-            'taxes'                => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
240
+            'disable_taxes'        => !empty($data['disable_taxes']),
241
+            'currency'             => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
242
+            'gateway'              => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
243
+            'transaction_id'       => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
244
+            'discount_code'        => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
245
+            'payment_form'         => isset($data['payment_form']) ? intval($data['payment_form']) : null,
246
+            'submission_id'        => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
247
+            'subscription_id'      => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
248
+            'is_viewed'            => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
249
+            'fees'                 => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
250
+            'discounts'            => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
251
+            'taxes'                => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
252 252
             
253 253
 
254 254
             // Billing details.
255 255
             'user_id'              => $data['user_id'],
256
-            'first_name'           => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
257
-            'last_name'            => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
258
-            'address'              => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] ,
259
-            'vat_number'           => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
260
-            'company'              => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
261
-            'zip'                  => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
262
-            'state'                => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
263
-            'city'                 => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
264
-            'country'              => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
265
-            'phone'                => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
266
-            'address_confirmed'    => ! empty( $data['address_confirmed'] ),
256
+            'first_name'           => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
257
+            'last_name'            => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
258
+            'address'              => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
259
+            'vat_number'           => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
260
+            'company'              => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
261
+            'zip'                  => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
262
+            'state'                => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
263
+            'city'                 => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
264
+            'country'              => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
265
+            'phone'                => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
266
+            'address_confirmed'    => !empty($data['address_confirmed']),
267 267
 
268 268
         )
269 269
 
270 270
     );
271 271
 
272 272
     // Backwards compatibililty.
273
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
273
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
274 274
         $data['items'] = array();
275 275
 
276
-        foreach( $data['cart_details'] as $_item ) {
276
+        foreach ($data['cart_details'] as $_item) {
277 277
 
278 278
             // Ensure that we have an item id.
279
-            if ( empty(  $_item['id']  ) ) {
279
+            if (empty($_item['id'])) {
280 280
                 continue;
281 281
             }
282 282
 
283 283
             // Retrieve the item.
284
-            $item = new GetPaid_Form_Item(  $_item['id']  );
284
+            $item = new GetPaid_Form_Item($_item['id']);
285 285
 
286 286
             // Ensure that it is purchasable.
287
-            if ( ! $item->can_purchase() ) {
287
+            if (!$item->can_purchase()) {
288 288
                 continue;
289 289
             }
290 290
 
291 291
             // Set quantity.
292
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
293
-                $item->set_quantity( $_item['quantity'] );
292
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
293
+                $item->set_quantity($_item['quantity']);
294 294
             }
295 295
 
296 296
             // Set price.
297
-            if ( isset( $_item['item_price'] ) ) {
298
-                $item->set_price( $_item['item_price'] );
297
+            if (isset($_item['item_price'])) {
298
+                $item->set_price($_item['item_price']);
299 299
             }
300 300
 
301
-            if ( isset( $_item['custom_price'] ) ) {
302
-                $item->set_price( $_item['custom_price'] );
301
+            if (isset($_item['custom_price'])) {
302
+                $item->set_price($_item['custom_price']);
303 303
             }
304 304
 
305 305
             // Set name.
306
-            if ( ! empty( $_item['name'] ) ) {
307
-                $item->set_name( $_item['name'] );
306
+            if (!empty($_item['name'])) {
307
+                $item->set_name($_item['name']);
308 308
             }
309 309
 
310 310
             // Set description.
311
-            if ( isset( $_item['description'] ) ) {
312
-                $item->set_custom_description( $_item['description'] );
311
+            if (isset($_item['description'])) {
312
+                $item->set_custom_description($_item['description']);
313 313
             }
314 314
 
315 315
             // Set meta.
316
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
316
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
317 317
 
318
-                $item->set_item_meta( $_item['meta'] );
318
+                $item->set_item_meta($_item['meta']);
319 319
 
320
-                if ( isset( $_item['meta']['description'] ) ) {
321
-                    $item->set_custom_description( $_item['meta']['description'] );
320
+                if (isset($_item['meta']['description'])) {
321
+                    $item->set_custom_description($_item['meta']['description']);
322 322
                 }
323 323
 
324 324
             }
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
     }
330 330
 
331 331
     // Add invoice items.
332
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
332
+    if (!empty($data['items']) && is_array($data['items'])) {
333 333
 
334
-        $invoice->set_items( array() );
334
+        $invoice->set_items(array());
335 335
 
336
-        foreach ( $data['items'] as $item ) {
336
+        foreach ($data['items'] as $item) {
337 337
 
338
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
339
-                $invoice->add_item( $item );
338
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
339
+                $invoice->add_item($item);
340 340
             }
341 341
 
342 342
         }
@@ -346,30 +346,30 @@  discard block
 block discarded – undo
346 346
     // Save the invoice.
347 347
     $invoice->save();
348 348
 
349
-    if ( ! $invoice->get_id() ) {
350
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
349
+    if (!$invoice->get_id()) {
350
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
351 351
     }
352 352
 
353 353
     // Add private note.
354
-    if ( ! empty( $data['private_note'] ) ) {
355
-        $invoice->add_note( $data['private_note'] );
354
+    if (!empty($data['private_note'])) {
355
+        $invoice->add_note($data['private_note']);
356 356
     }
357 357
 
358 358
     // User notes.
359
-    if ( !empty( $data['user_note'] ) ) {
360
-        $invoice->add_note( $data['user_note'], true );
359
+    if (!empty($data['user_note'])) {
360
+        $invoice->add_note($data['user_note'], true);
361 361
     }
362 362
 
363 363
     // Created via.
364
-    if ( isset( $data['created_via'] ) ) {
365
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
364
+    if (isset($data['created_via'])) {
365
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
366 366
     }
367 367
 
368 368
     // Backwards compatiblity.
369
-    if ( $invoice->is_quote() ) {
369
+    if ($invoice->is_quote()) {
370 370
 
371
-        if ( isset( $data['valid_until'] ) ) {
372
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
371
+        if (isset($data['valid_until'])) {
372
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
373 373
         }
374 374
         return $invoice;
375 375
 
@@ -384,18 +384,18 @@  discard block
 block discarded – undo
384 384
  * @param $bool $deprecated
385 385
  * @return WPInv_Invoice|null
386 386
  */
387
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
387
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
388 388
 
389 389
     // If we are retrieving the invoice from the cart...
390
-    if ( $deprecated && empty( $invoice ) ) {
390
+    if ($deprecated && empty($invoice)) {
391 391
         $invoice = (int) getpaid_get_current_invoice_id();
392 392
     }
393 393
 
394 394
     // Retrieve the invoice.
395
-    $invoice = new WPInv_Invoice( $invoice );
395
+    $invoice = new WPInv_Invoice($invoice);
396 396
 
397 397
     // Check if it exists.
398
-    if ( $invoice->get_id() != 0 ) {
398
+    if ($invoice->get_id() != 0) {
399 399
         return $invoice;
400 400
     }
401 401
 
@@ -408,15 +408,15 @@  discard block
 block discarded – undo
408 408
  * @param array $args Args to search for.
409 409
  * @return WPInv_Invoice[]|int[]|object
410 410
  */
411
-function wpinv_get_invoices( $args ) {
411
+function wpinv_get_invoices($args) {
412 412
 
413 413
     // Prepare args.
414 414
     $args = wp_parse_args(
415 415
         $args,
416 416
         array(
417
-            'status'   => array_keys( wpinv_get_invoice_statuses() ),
417
+            'status'   => array_keys(wpinv_get_invoice_statuses()),
418 418
             'type'     => 'wpi_invoice',
419
-            'limit'    => get_option( 'posts_per_page' ),
419
+            'limit'    => get_option('posts_per_page'),
420 420
             'return'   => 'objects',
421 421
         )
422 422
     );
@@ -434,24 +434,24 @@  discard block
 block discarded – undo
434 434
         'post__in'       => 'include',
435 435
     );
436 436
 
437
-    foreach ( $map_legacy as $to => $from ) {
438
-        if ( isset( $args[ $from ] ) ) {
439
-            $args[ $to ] = $args[ $from ];
440
-            unset( $args[ $from ] );
437
+    foreach ($map_legacy as $to => $from) {
438
+        if (isset($args[$from])) {
439
+            $args[$to] = $args[$from];
440
+            unset($args[$from]);
441 441
         }
442 442
     }
443 443
 
444 444
     // Backwards compatibility.
445
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
445
+    if (!empty($args['email']) && empty($args['user'])) {
446 446
         $args['user'] = $args['email'];
447
-        unset( $args['email'] );
447
+        unset($args['email']);
448 448
     }
449 449
 
450 450
     // Handle cases where the user is set as an email.
451
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
452
-        $user = get_user_by( 'email', $args['user'] );
451
+    if (!empty($args['author']) && is_email($args['author'])) {
452
+        $user = get_user_by('email', $args['user']);
453 453
 
454
-        if ( $user ) {
454
+        if ($user) {
455 455
             $args['author'] = $user->user_email;
456 456
         }
457 457
 
@@ -462,31 +462,31 @@  discard block
 block discarded – undo
462 462
 
463 463
     // Show all posts.
464 464
     $paginate = true;
465
-    if ( isset( $args['paginate'] ) ) {
465
+    if (isset($args['paginate'])) {
466 466
         
467 467
         $paginate = $args['paginate'];
468
-        $args['no_found_rows'] = empty( $args['paginate'] );
469
-        unset( $args['paginate'] );
468
+        $args['no_found_rows'] = empty($args['paginate']);
469
+        unset($args['paginate']);
470 470
 
471 471
     }
472 472
 
473 473
     // Whether to return objects or fields.
474 474
     $return = $args['return'];
475
-    unset( $args['return'] );
475
+    unset($args['return']);
476 476
 
477 477
     // Get invoices.
478
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
478
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
479 479
 
480 480
     // Prepare the results.
481
-    if ( 'objects' === $return ) {
482
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
483
-    } elseif ( 'self' === $return ) {
481
+    if ('objects' === $return) {
482
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
483
+    } elseif ('self' === $return) {
484 484
         return $invoices;
485 485
     } else {
486 486
         $results = $invoices->posts;
487 487
     }
488 488
 
489
-    if ( $paginate ) {
489
+    if ($paginate) {
490 490
         return (object) array(
491 491
             'invoices'      => $results,
492 492
             'total'         => $invoices->found_posts,
@@ -504,8 +504,8 @@  discard block
 block discarded – undo
504 504
  * @param string $transaction_id The transaction id to check.
505 505
  * @return int Invoice id on success or 0 on failure
506 506
  */
507
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
508
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
507
+function wpinv_get_id_by_transaction_id($transaction_id) {
508
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
509 509
 }
510 510
 
511 511
 /**
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
  * @param string $invoice_number The invoice number to check.
515 515
  * @return int Invoice id on success or 0 on failure
516 516
  */
517
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
518
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
517
+function wpinv_get_id_by_invoice_number($invoice_number) {
518
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
519 519
 }
520 520
 
521 521
 /**
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
  * @param string $invoice_key The invoice key to check.
525 525
  * @return int Invoice id on success or 0 on failure
526 526
  */
527
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
528
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
527
+function wpinv_get_invoice_id_by_key($invoice_key) {
528
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
529 529
 }
530 530
 
531 531
 /**
@@ -535,19 +535,19 @@  discard block
 block discarded – undo
535 535
  * @param string $type Optionally filter by type i.e customer|system
536 536
  * @return array|null
537 537
  */
538
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
538
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
539 539
 
540 540
     // Prepare the invoice.
541
-    $invoice = wpinv_get_invoice( $invoice );
542
-    if ( empty( $invoice ) ) {
541
+    $invoice = wpinv_get_invoice($invoice);
542
+    if (empty($invoice)) {
543 543
         return NULL;
544 544
     }
545 545
 
546 546
     // Fetch notes.
547
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
547
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
548 548
 
549 549
     // Filter the notes.
550
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
550
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
551 551
 }
552 552
 
553 553
 /**
@@ -557,27 +557,27 @@  discard block
 block discarded – undo
557 557
     $columns = array(
558 558
 
559 559
             'invoice-number'  => array(
560
-                'title' => __( 'Invoice', 'invoicing' ),
560
+                'title' => __('Invoice', 'invoicing'),
561 561
                 'class' => 'text-left'
562 562
             ),
563 563
 
564 564
             'created-date'    => array(
565
-                'title' => __( 'Created Date', 'invoicing' ),
565
+                'title' => __('Created Date', 'invoicing'),
566 566
                 'class' => 'text-left'
567 567
             ),
568 568
 
569 569
             'payment-date'    => array(
570
-                'title' => __( 'Payment Date', 'invoicing' ),
570
+                'title' => __('Payment Date', 'invoicing'),
571 571
                 'class' => 'text-left'
572 572
             ),
573 573
 
574 574
             'invoice-status'  => array(
575
-                'title' => __( 'Status', 'invoicing' ),
575
+                'title' => __('Status', 'invoicing'),
576 576
                 'class' => 'text-center'
577 577
             ),
578 578
 
579 579
             'invoice-total'   => array(
580
-                'title' => __( 'Total', 'invoicing' ),
580
+                'title' => __('Total', 'invoicing'),
581 581
                 'class' => 'text-right'
582 582
             ),
583 583
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 
589 589
         );
590 590
 
591
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
591
+    return apply_filters('wpinv_user_invoices_columns', $columns);
592 592
 }
593 593
 
594 594
 /**
@@ -598,54 +598,54 @@  discard block
 block discarded – undo
598 598
 
599 599
     // Find the invoice.
600 600
     $invoice_id = getpaid_get_current_invoice_id();
601
-    $invoice = new WPInv_Invoice( $invoice_id );
601
+    $invoice = new WPInv_Invoice($invoice_id);
602 602
 
603 603
     // Abort if non was found.
604
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
604
+    if (empty($invoice_id) || $invoice->is_draft()) {
605 605
 
606 606
         return aui()->alert(
607 607
             array(
608 608
                 'type'    => 'warning',
609
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
609
+                'content' => __('We could not find your invoice', 'invoicing'),
610 610
             )
611 611
         );
612 612
 
613 613
     }
614 614
 
615 615
     // Can the user view this invoice?
616
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
616
+    if (!wpinv_can_view_receipt($invoice_id)) {
617 617
 
618 618
         return aui()->alert(
619 619
             array(
620 620
                 'type'    => 'warning',
621
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
621
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
622 622
             )
623 623
         );
624 624
 
625 625
     }
626 626
 
627 627
     // Load the template.
628
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
628
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
629 629
 
630 630
 }
631 631
 
632 632
 /**
633 633
  * Displays the invoice history.
634 634
  */
635
-function getpaid_invoice_history( $user_id = 0 ) {
635
+function getpaid_invoice_history($user_id = 0) {
636 636
 
637 637
     // Ensure that we have a user id.
638
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
638
+    if (empty($user_id) || !is_numeric($user_id)) {
639 639
         $user_id = get_current_user_id();
640 640
     }
641 641
 
642 642
     // View user id.
643
-    if ( empty( $user_id ) ) {
643
+    if (empty($user_id)) {
644 644
 
645 645
         return aui()->alert(
646 646
             array(
647 647
                 'type'    => 'warning',
648
-                'content' => __( 'You must be logged in to view your invoice history.', 'invoicing' ),
648
+                'content' => __('You must be logged in to view your invoice history.', 'invoicing'),
649 649
             )
650 650
         );
651 651
 
@@ -655,35 +655,35 @@  discard block
 block discarded – undo
655 655
     $invoices = wpinv_get_invoices(
656 656
 
657 657
         array(
658
-            'page'     => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
658
+            'page'     => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
659 659
             'user'     => $user_id,
660 660
             'paginate' => true,
661 661
         )
662 662
 
663 663
     );
664 664
 
665
-    if ( empty( $invoices->total ) ) {
665
+    if (empty($invoices->total)) {
666 666
 
667 667
         return aui()->alert(
668 668
             array(
669 669
                 'type'    => 'info',
670
-                'content' => __( 'No invoices found.', 'invoicing' ),
670
+                'content' => __('No invoices found.', 'invoicing'),
671 671
             )
672 672
         );
673 673
 
674 674
     }
675 675
 
676 676
     // Load the template.
677
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices' ) );
677
+    return wpinv_get_template_html('invoice-history.php', compact('invoices'));
678 678
 
679 679
 }
680 680
 
681
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
682
-    if ( empty( $status_display ) ) {
683
-        $status_display = wpinv_status_nicename( $status );
681
+function wpinv_invoice_status_label($status, $status_display = '') {
682
+    if (empty($status_display)) {
683
+        $status_display = wpinv_status_nicename($status);
684 684
     }
685 685
     
686
-    switch ( $status ) {
686
+    switch ($status) {
687 687
         case 'publish' :
688 688
         case 'wpi-renewal' :
689 689
             $class = 'label-success';
@@ -708,159 +708,159 @@  discard block
 block discarded – undo
708 708
 
709 709
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
710 710
 
711
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
711
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
712 712
 }
713 713
 
714
-function wpinv_format_invoice_number( $number, $type = '' ) {
715
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
716
-    if ( null !== $check ) {
714
+function wpinv_format_invoice_number($number, $type = '') {
715
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
716
+    if (null !== $check) {
717 717
         return $check;
718 718
     }
719 719
 
720
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
720
+    if (!empty($number) && !is_numeric($number)) {
721 721
         return $number;
722 722
     }
723 723
 
724
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
725
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
726
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
724
+    $padd = wpinv_get_option('invoice_number_padd');
725
+    $prefix  = wpinv_get_option('invoice_number_prefix');
726
+    $postfix = wpinv_get_option('invoice_number_postfix');
727 727
     
728
-    $padd = absint( $padd );
729
-    $formatted_number = absint( $number );
728
+    $padd = absint($padd);
729
+    $formatted_number = absint($number);
730 730
     
731
-    if ( $padd > 0 ) {
732
-        $formatted_number = zeroise( $formatted_number, $padd );
731
+    if ($padd > 0) {
732
+        $formatted_number = zeroise($formatted_number, $padd);
733 733
     }    
734 734
 
735 735
     $formatted_number = $prefix . $formatted_number . $postfix;
736 736
 
737
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
737
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
738 738
 }
739 739
 
740
-function wpinv_get_next_invoice_number( $type = '' ) {
741
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
742
-    if ( null !== $check ) {
740
+function wpinv_get_next_invoice_number($type = '') {
741
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
742
+    if (null !== $check) {
743 743
         return $check;
744 744
     }
745 745
     
746
-    if ( !wpinv_sequential_number_active() ) {
746
+    if (!wpinv_sequential_number_active()) {
747 747
         return false;
748 748
     }
749 749
 
750
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
751
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
752
-    if ( !absint( $start ) > 0 ) {
750
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
751
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
752
+    if (!absint($start) > 0) {
753 753
         $start = 1;
754 754
     }
755 755
     $increment_number = true;
756 756
     $save_number = false;
757 757
 
758
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
759
-        $number = wpinv_clean_invoice_number( $number );
758
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
759
+        $number = wpinv_clean_invoice_number($number);
760 760
     }
761 761
 
762
-    if ( empty( $number ) ) {
763
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
764
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
762
+    if (empty($number)) {
763
+        if (!($last_number === 0 || $last_number === '0')) {
764
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
765 765
 
766
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
767
-                if ( is_numeric( $invoice_number ) ) {
766
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
767
+                if (is_numeric($invoice_number)) {
768 768
                     $number = $invoice_number;
769 769
                 } else {
770
-                    $number = wpinv_clean_invoice_number( $invoice_number );
770
+                    $number = wpinv_clean_invoice_number($invoice_number);
771 771
                 }
772 772
             }
773 773
 
774
-            if ( empty( $number ) ) {
774
+            if (empty($number)) {
775 775
                 $increment_number = false;
776 776
                 $number = $start;
777
-                $save_number = ( $number - 1 );
777
+                $save_number = ($number - 1);
778 778
             } else {
779 779
                 $save_number = $number;
780 780
             }
781 781
         }
782 782
     }
783 783
 
784
-    if ( $start > $number ) {
784
+    if ($start > $number) {
785 785
         $increment_number = false;
786 786
         $number = $start;
787
-        $save_number = ( $number - 1 );
787
+        $save_number = ($number - 1);
788 788
     }
789 789
 
790
-    if ( $save_number !== false ) {
791
-        update_option( 'wpinv_last_invoice_number', $save_number );
790
+    if ($save_number !== false) {
791
+        update_option('wpinv_last_invoice_number', $save_number);
792 792
     }
793 793
     
794
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
794
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
795 795
 
796
-    if ( $increment_number ) {
796
+    if ($increment_number) {
797 797
         $number++;
798 798
     }
799 799
 
800
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
800
+    return apply_filters('wpinv_get_next_invoice_number', $number);
801 801
 }
802 802
 
803
-function wpinv_clean_invoice_number( $number, $type = '' ) {
804
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
805
-    if ( null !== $check ) {
803
+function wpinv_clean_invoice_number($number, $type = '') {
804
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
805
+    if (null !== $check) {
806 806
         return $check;
807 807
     }
808 808
     
809
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
810
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
809
+    $prefix  = wpinv_get_option('invoice_number_prefix');
810
+    $postfix = wpinv_get_option('invoice_number_postfix');
811 811
 
812
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
812
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
813 813
 
814
-    $length      = strlen( $number );
815
-    $postfix_pos = strrpos( $number, $postfix );
814
+    $length      = strlen($number);
815
+    $postfix_pos = strrpos($number, $postfix);
816 816
     
817
-    if ( false !== $postfix_pos ) {
818
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
817
+    if (false !== $postfix_pos) {
818
+        $number = substr_replace($number, '', $postfix_pos, $length);
819 819
     }
820 820
 
821
-    $number = intval( $number );
821
+    $number = intval($number);
822 822
 
823
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
823
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
824 824
 }
825 825
 
826
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
826
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
827 827
     global $wpdb;
828 828
 
829
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
830
-    if ( null !== $check ) {
829
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
830
+    if (null !== $check) {
831 831
         return $check;
832 832
     }
833 833
 
834
-    if ( wpinv_sequential_number_active() ) {
834
+    if (wpinv_sequential_number_active()) {
835 835
         $number = wpinv_get_next_invoice_number();
836 836
 
837
-        if ( $save_sequential ) {
838
-            update_option( 'wpinv_last_invoice_number', $number );
837
+        if ($save_sequential) {
838
+            update_option('wpinv_last_invoice_number', $number);
839 839
         }
840 840
     } else {
841 841
         $number = $post_ID;
842 842
     }
843 843
 
844
-    $number = wpinv_format_invoice_number( $number );
844
+    $number = wpinv_format_invoice_number($number);
845 845
 
846
-    update_post_meta( $post_ID, '_wpinv_number', $number );
846
+    update_post_meta($post_ID, '_wpinv_number', $number);
847 847
 
848
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
848
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
849 849
 
850
-    clean_post_cache( $post_ID );
850
+    clean_post_cache($post_ID);
851 851
 
852 852
     return $number;
853 853
 }
854 854
 
855
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
856
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
855
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
856
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
857 857
 }
858 858
 
859
-function wpinv_generate_post_name( $post_ID ) {
860
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
861
-    $post_name = sanitize_title( $prefix . $post_ID );
859
+function wpinv_generate_post_name($post_ID) {
860
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
861
+    $post_name = sanitize_title($prefix . $post_ID);
862 862
 
863
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
863
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
864 864
 }
865 865
 
866 866
 /**
@@ -868,8 +868,8 @@  discard block
 block discarded – undo
868 868
  * 
869 869
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
870 870
  */
871
-function wpinv_is_invoice_viewed( $invoice ) {
872
-    $invoice = new WPInv_Invoice( $invoice );
871
+function wpinv_is_invoice_viewed($invoice) {
872
+    $invoice = new WPInv_Invoice($invoice);
873 873
     return (bool) $invoice->get_is_viewed();
874 874
 }
875 875
 
@@ -878,51 +878,51 @@  discard block
 block discarded – undo
878 878
  * 
879 879
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
880 880
  */
881
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
882
-    $invoice = new WPInv_Invoice( $invoice );
881
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
882
+    $invoice = new WPInv_Invoice($invoice);
883 883
 
884
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
885
-        $invoice->set_is_viewed( true );
884
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
885
+        $invoice->set_is_viewed(true);
886 886
         $invoice->save();
887 887
     }
888 888
 
889 889
 }
890
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
891
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
890
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
891
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
892 892
 
893 893
 /**
894 894
  * Fetch a subscription given an invoice.
895 895
  *
896 896
  * @return WPInv_Subscription|bool
897 897
  */
898
-function wpinv_get_subscription( $invoice ) {
898
+function wpinv_get_subscription($invoice) {
899 899
 
900 900
     // Abort if we do not have an invoice.
901
-    if ( empty( $invoice ) ) {
901
+    if (empty($invoice)) {
902 902
         return false;
903 903
     }
904 904
 
905 905
     // Retrieve the invoice.
906
-    $invoice = new WPInv_Invoice( $invoice );
906
+    $invoice = new WPInv_Invoice($invoice);
907 907
 
908 908
     // Ensure it is a recurring invoice.
909
-    if ( ! $invoice->is_recurring() ) {
909
+    if (!$invoice->is_recurring()) {
910 910
         return false;
911 911
     }
912 912
 
913 913
     // Fetch the subscription handler.
914
-    $subs_db    = new WPInv_Subscriptions_DB();
914
+    $subs_db = new WPInv_Subscriptions_DB();
915 915
 
916 916
     // Fetch the parent in case it is a renewal.
917
-    if ( $invoice->is_renewal() ) {
918
-        $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_parent_id(), 'number' => 1 ) );
917
+    if ($invoice->is_renewal()) {
918
+        $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_parent_id(), 'number' => 1));
919 919
     } else {
920
-        $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_id(), 'number' => 1 ) );
920
+        $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_id(), 'number' => 1));
921 921
     }
922 922
 
923 923
     // Return the subscription if it exists.
924
-    if ( ! empty( $subs ) ) {
925
-        return reset( $subs );
924
+    if (!empty($subs)) {
925
+        return reset($subs);
926 926
     }
927 927
 
928 928
     return false;
@@ -936,27 +936,27 @@  discard block
 block discarded – undo
936 936
  * @param array $status_transition
937 937
  * @todo: descrease customer/store earnings
938 938
  */
939
-function getpaid_maybe_process_refund( $invoice_id, $invoice, $status_transition ) {
939
+function getpaid_maybe_process_refund($invoice_id, $invoice, $status_transition) {
940 940
 
941
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
941
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
942 942
         return;
943 943
     }
944 944
 
945 945
     $discount_code = $invoice->get_discount_code();
946
-    if ( ! empty( $discount_code ) ) {
947
-        $discount = wpinv_get_discount_obj( $discount_code );
946
+    if (!empty($discount_code)) {
947
+        $discount = wpinv_get_discount_obj($discount_code);
948 948
 
949
-        if ( $discount->exists() ) {
949
+        if ($discount->exists()) {
950 950
             $discount->increase_usage( -1 );
951 951
         }
952 952
 
953 953
     }
954 954
 
955
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice_id );
956
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice_id );
957
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice_id );
955
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice_id);
956
+    do_action('wpinv_refund_invoice', $invoice, $invoice_id);
957
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice_id);
958 958
 }
959
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3 );
959
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3);
960 960
 
961 961
 
962 962
 /**
@@ -964,48 +964,48 @@  discard block
 block discarded – undo
964 964
  *
965 965
  * @param int $invoice_id
966 966
  */
967
-function getpaid_process_invoice_payment( $invoice_id ) {
967
+function getpaid_process_invoice_payment($invoice_id) {
968 968
 
969 969
     // Fetch the invoice.
970
-    $invoice = new WPInv_Invoice( $invoice_id );
970
+    $invoice = new WPInv_Invoice($invoice_id);
971 971
 
972 972
     // We only want to do this once.
973
-    if ( 1 ==  get_post_meta( $invoice_id, 'wpinv_processed_payment', true ) ) {
973
+    if (1 == get_post_meta($invoice_id, 'wpinv_processed_payment', true)) {
974 974
         return;
975 975
     }
976 976
 
977
-    update_post_meta( $invoice_id, 'wpinv_processed_payment', 1 );
977
+    update_post_meta($invoice_id, 'wpinv_processed_payment', 1);
978 978
 
979 979
     // Fires when processing a payment.
980
-    do_action( 'getpaid_process_payment', $invoice );
980
+    do_action('getpaid_process_payment', $invoice);
981 981
 
982 982
     // Fire an action for each invoice item.
983
-    foreach( $invoice->get_items() as $item ) {
984
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
983
+    foreach ($invoice->get_items() as $item) {
984
+        do_action('getpaid_process_item_payment', $item, $invoice);
985 985
     }
986 986
 
987 987
     // Increase discount usage.
988 988
     $discount_code = $invoice->get_discount_code();
989
-    if ( ! empty( $discount_code ) ) {
990
-        $discount = wpinv_get_discount_obj( $discount_code );
989
+    if (!empty($discount_code)) {
990
+        $discount = wpinv_get_discount_obj($discount_code);
991 991
 
992
-        if ( $discount->exists() ) {
992
+        if ($discount->exists()) {
993 993
             $discount->increase_usage();
994 994
         }
995 995
 
996 996
     }
997 997
 
998 998
     // Record reverse vat.
999
-    if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
999
+    if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
1000 1000
 
1001
-        if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->get_country() ) ) {
1002
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
1001
+        if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->get_country())) {
1002
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
1003 1003
         }
1004 1004
 
1005 1005
     }
1006 1006
 
1007 1007
 }
1008
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
1008
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
1009 1009
 
1010 1010
 /**
1011 1011
  * Returns an array of invoice item columns
@@ -1013,13 +1013,13 @@  discard block
 block discarded – undo
1013 1013
  * @param int|WPInv_Invoice $invoice
1014 1014
  * @return array
1015 1015
  */
1016
-function getpaid_invoice_item_columns( $invoice ) {
1016
+function getpaid_invoice_item_columns($invoice) {
1017 1017
 
1018 1018
     // Prepare the invoice.
1019
-    $invoice = new WPInv_Invoice( $invoice );
1019
+    $invoice = new WPInv_Invoice($invoice);
1020 1020
 
1021 1021
     // Abort if there is no invoice.
1022
-    if ( 0 == $invoice->get_id() ) {
1022
+    if (0 == $invoice->get_id()) {
1023 1023
         return array();
1024 1024
     }
1025 1025
 
@@ -1027,47 +1027,47 @@  discard block
 block discarded – undo
1027 1027
     $columns = apply_filters(
1028 1028
         'getpaid_invoice_item_columns',
1029 1029
         array(
1030
-            'name'     => __( 'Item', 'invoicing' ),
1031
-            'price'    => __( 'Price', 'invoicing' ),
1032
-            'quantity' => __( 'Quantity', 'invoicing' ),
1033
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
1030
+            'name'     => __('Item', 'invoicing'),
1031
+            'price'    => __('Price', 'invoicing'),
1032
+            'quantity' => __('Quantity', 'invoicing'),
1033
+            'subtotal' => __('Subtotal', 'invoicing'),
1034 1034
         ),
1035 1035
         $invoice
1036 1036
     );
1037 1037
 
1038 1038
     // Quantities.
1039
-    if ( isset( $columns[ 'quantity' ] ) ) {
1039
+    if (isset($columns['quantity'])) {
1040 1040
 
1041
-        if ( 'hours' == $invoice->get_template() ) {
1042
-            $columns[ 'quantity' ] = __( 'Hours', 'invoicing' );
1041
+        if ('hours' == $invoice->get_template()) {
1042
+            $columns['quantity'] = __('Hours', 'invoicing');
1043 1043
         }
1044 1044
 
1045
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
1046
-            unset( $columns[ 'quantity' ] );
1045
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
1046
+            unset($columns['quantity']);
1047 1047
         }
1048 1048
 
1049 1049
     }
1050 1050
 
1051 1051
 
1052 1052
     // Price.
1053
-    if ( isset( $columns[ 'price' ] ) ) {
1053
+    if (isset($columns['price'])) {
1054 1054
 
1055
-        if ( 'amount' == $invoice->get_template() ) {
1056
-            $columns[ 'price' ] = __( 'Amount', 'invoicing' );
1055
+        if ('amount' == $invoice->get_template()) {
1056
+            $columns['price'] = __('Amount', 'invoicing');
1057 1057
         }
1058 1058
 
1059
-        if ( 'hours' == $invoice->get_template() ) {
1060
-            $columns[ 'price' ] = __( 'Rate', 'invoicing' );
1059
+        if ('hours' == $invoice->get_template()) {
1060
+            $columns['price'] = __('Rate', 'invoicing');
1061 1061
         }
1062 1062
 
1063 1063
     }
1064 1064
 
1065 1065
 
1066 1066
     // Sub total.
1067
-    if ( isset( $columns[ 'subtotal' ] ) ) {
1067
+    if (isset($columns['subtotal'])) {
1068 1068
 
1069
-        if ( 'amount' == $invoice->get_template() ) {
1070
-            unset( $columns[ 'subtotal' ] );
1069
+        if ('amount' == $invoice->get_template()) {
1070
+            unset($columns['subtotal']);
1071 1071
         }
1072 1072
 
1073 1073
     }
@@ -1081,29 +1081,29 @@  discard block
 block discarded – undo
1081 1081
  * @param int|WPInv_Invoice $invoice
1082 1082
  * @return array
1083 1083
  */
1084
-function getpaid_invoice_totals_rows( $invoice ) {
1084
+function getpaid_invoice_totals_rows($invoice) {
1085 1085
 
1086 1086
     // Prepare the invoice.
1087
-    $invoice = new WPInv_Invoice( $invoice );
1087
+    $invoice = new WPInv_Invoice($invoice);
1088 1088
 
1089 1089
     // Abort if there is no invoice.
1090
-    if ( 0 == $invoice->get_id() ) {
1090
+    if (0 == $invoice->get_id()) {
1091 1091
         return array();
1092 1092
     }
1093 1093
 
1094 1094
     $totals = apply_filters(
1095 1095
         'getpaid_invoice_totals_rows',
1096 1096
         array(
1097
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
1098
-            'tax'      => __( 'Tax', 'invoicing' ),
1099
-            'discount' => __( 'Discount', 'invoicing' ),
1100
-            'total'    => __( 'Total', 'invoicing' ),
1097
+            'subtotal' => __('Subtotal', 'invoicing'),
1098
+            'tax'      => __('Tax', 'invoicing'),
1099
+            'discount' => __('Discount', 'invoicing'),
1100
+            'total'    => __('Total', 'invoicing'),
1101 1101
         ),
1102 1102
         $invoice
1103 1103
     );
1104 1104
 
1105
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
1106
-        unset( $totals['tax'] );
1105
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
1106
+        unset($totals['tax']);
1107 1107
     }
1108 1108
 
1109 1109
     return $totals;
@@ -1115,22 +1115,22 @@  discard block
 block discarded – undo
1115 1115
  * @param int $invoice_id
1116 1116
  * @param WPInv_Invoice $invoice
1117 1117
  */
1118
-function getpaid_new_invoice( $invoice_id, $invoice ) {
1118
+function getpaid_new_invoice($invoice_id, $invoice) {
1119 1119
 
1120
-    if ( ! $invoice->get_status() ) {
1120
+    if (!$invoice->get_status()) {
1121 1121
         return;
1122 1122
     }
1123 1123
 
1124 1124
     // Add an invoice created note.
1125 1125
     $invoice->add_note(
1126 1126
         wp_sprintf(
1127
-            __( 'Invoice created with the status "%s".', 'invoicing' ),
1128
-            wpinv_status_nicename( $invoice->get_status() )
1127
+            __('Invoice created with the status "%s".', 'invoicing'),
1128
+            wpinv_status_nicename($invoice->get_status())
1129 1129
         )
1130 1130
     );
1131 1131
 
1132 1132
 }
1133
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice', 10, 2 );
1133
+add_action('getpaid_new_invoice', 'getpaid_new_invoice', 10, 2);
1134 1134
 
1135 1135
 /**
1136 1136
  * This function updates invoice caches.
@@ -1138,21 +1138,21 @@  discard block
 block discarded – undo
1138 1138
  * @param int $invoice_id
1139 1139
  * @param WPInv_Invoice $invoice
1140 1140
  */
1141
-function getpaid_update_invoice_caches( $invoice_id, $invoice ) {
1141
+function getpaid_update_invoice_caches($invoice_id, $invoice) {
1142 1142
 
1143 1143
     // Cache invoice number.
1144
-    wp_cache_set( $invoice->get_number(), $invoice_id, "getpaid_invoice_numbers_to_invoice_ids" );
1144
+    wp_cache_set($invoice->get_number(), $invoice_id, "getpaid_invoice_numbers_to_invoice_ids");
1145 1145
 
1146 1146
     // Cache invoice key.
1147
-    wp_cache_set( $invoice->get_key(), $invoice_id, "getpaid_invoice_keys_to_invoice_ids" );
1147
+    wp_cache_set($invoice->get_key(), $invoice_id, "getpaid_invoice_keys_to_invoice_ids");
1148 1148
 
1149 1149
     // (Maybe) cache transaction id.
1150 1150
     $transaction_id = $invoice->get_transaction_id();
1151 1151
 
1152
-    if ( ! empty( $transaction_id ) ) {
1153
-        wp_cache_set( $transaction_id, $invoice_id, "getpaid_invoice_transaction_ids_to_invoice_ids" );
1152
+    if (!empty($transaction_id)) {
1153
+        wp_cache_set($transaction_id, $invoice_id, "getpaid_invoice_transaction_ids_to_invoice_ids");
1154 1154
     }
1155 1155
 
1156 1156
 }
1157
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5, 2 );
1158
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5, 2 );
1157
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5, 2);
1158
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5, 2);
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 2 patches
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142 142
 function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
143
+    return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
144 144
 }
145 145
 
146 146
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+    return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
162 162
 }
163 163
 
164 164
 /**
@@ -175,122 +175,122 @@  discard block
 block discarded – undo
175 175
 }
176 176
 
177 177
 function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
178
+    do_action( 'get_template_part_' . $slug, $slug, $name );
179 179
 
180
-	// Setup possible parts
181
-	$templates = array();
182
-	if ( isset( $name ) )
183
-		$templates[] = $slug . '-' . $name . '.php';
184
-	$templates[] = $slug . '.php';
180
+    // Setup possible parts
181
+    $templates = array();
182
+    if ( isset( $name ) )
183
+        $templates[] = $slug . '-' . $name . '.php';
184
+    $templates[] = $slug . '.php';
185 185
 
186
-	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
186
+    // Allow template parts to be filtered
187
+    $templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
188 188
 
189
-	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
189
+    // Return the part that is found
190
+    return wpinv_locate_tmpl( $templates, $load, false );
191 191
 }
192 192
 
193 193
 function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
194
-	// No file found yet
195
-	$located = false;
194
+    // No file found yet
195
+    $located = false;
196 196
 
197
-	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
197
+    // Try to find a template file
198
+    foreach ( (array)$template_names as $template_name ) {
199 199
 
200
-		// Continue if template is empty
201
-		if ( empty( $template_name ) )
202
-			continue;
200
+        // Continue if template is empty
201
+        if ( empty( $template_name ) )
202
+            continue;
203 203
 
204
-		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
204
+        // Trim off any slashes from the template name
205
+        $template_name = ltrim( $template_name, '/' );
206 206
 
207
-		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
207
+        // try locating this template file by looping through the template paths
208
+        foreach( wpinv_get_theme_template_paths() as $template_path ) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
211
-				$located = $template_path . $template_name;
212
-				break;
213
-			}
214
-		}
210
+            if( file_exists( $template_path . $template_name ) ) {
211
+                $located = $template_path . $template_name;
212
+                break;
213
+            }
214
+        }
215 215
 
216
-		if( !empty( $located ) ) {
217
-			break;
218
-		}
219
-	}
216
+        if( !empty( $located ) ) {
217
+            break;
218
+        }
219
+    }
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+    if ( ( true == $load ) && ! empty( $located ) )
222
+        load_template( $located, $require_once );
223 223
 
224
-	return $located;
224
+    return $located;
225 225
 }
226 226
 
227 227
 function wpinv_get_theme_template_paths() {
228
-	$template_dir = wpinv_get_theme_template_dir_name();
228
+    $template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230
-	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
233
-		100 => wpinv_get_templates_dir()
234
-	);
230
+    $file_paths = array(
231
+        1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
+        10 => trailingslashit( get_template_directory() ) . $template_dir,
233
+        100 => wpinv_get_templates_dir()
234
+    );
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+    $file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
237 237
 
238
-	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
238
+    // sort the file paths based on priority
239
+    ksort( $file_paths, SORT_NUMERIC );
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+    return array_map( 'trailingslashit', $file_paths );
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246
-	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
246
+    $pages   = array();
247
+    $pages[] = wpinv_get_option( 'success_page' );
248
+    $pages[] = wpinv_get_option( 'failure_page' );
249
+    $pages[] = wpinv_get_option( 'invoice_history_page' );
250
+    $pages[] = wpinv_get_option( 'invoice_subscription_page' );
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
-		return;
254
-	}
252
+    if( !wpinv_is_checkout() && !is_page( $pages ) ) {
253
+        return;
254
+    }
255 255
 
256
-	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
256
+    echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258 258
 add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
259 259
 
260 260
 function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
261
+    $classes = (array)$class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
264
-		$classes[] = 'wpinv-checkout';
265
-		$classes[] = 'wpinv-page';
266
-	}
263
+    if( wpinv_is_checkout() ) {
264
+        $classes[] = 'wpinv-checkout';
265
+        $classes[] = 'wpinv-page';
266
+    }
267 267
 
268
-	if( wpinv_is_success_page() ) {
269
-		$classes[] = 'wpinv-success';
270
-		$classes[] = 'wpinv-page';
271
-	}
268
+    if( wpinv_is_success_page() ) {
269
+        $classes[] = 'wpinv-success';
270
+        $classes[] = 'wpinv-page';
271
+    }
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
274
-		$classes[] = 'wpinv-failed-transaction';
275
-		$classes[] = 'wpinv-page';
276
-	}
273
+    if( wpinv_is_failed_transaction_page() ) {
274
+        $classes[] = 'wpinv-failed-transaction';
275
+        $classes[] = 'wpinv-page';
276
+    }
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
279
-		$classes[] = 'wpinv-history';
280
-		$classes[] = 'wpinv-page';
281
-	}
278
+    if( wpinv_is_invoice_history_page() ) {
279
+        $classes[] = 'wpinv-history';
280
+        $classes[] = 'wpinv-page';
281
+    }
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
284
-		$classes[] = 'wpinv-subscription';
285
-		$classes[] = 'wpinv-page';
286
-	}
283
+    if( wpinv_is_subscriptions_history_page() ) {
284
+        $classes[] = 'wpinv-subscription';
285
+        $classes[] = 'wpinv-page';
286
+    }
287 287
 
288
-	if( wpinv_is_test_mode() ) {
289
-		$classes[] = 'wpinv-test-mode';
290
-		$classes[] = 'wpinv-page';
291
-	}
288
+    if( wpinv_is_test_mode() ) {
289
+        $classes[] = 'wpinv-test-mode';
290
+        $classes[] = 'wpinv-page';
291
+    }
292 292
 
293
-	return array_unique( $classes );
293
+    return array_unique( $classes );
294 294
 }
295 295
 add_filter( 'body_class', 'wpinv_add_body_classes' );
296 296
 
@@ -992,21 +992,21 @@  discard block
 block discarded – undo
992 992
 
993 993
     $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
994 994
     
995
-	// Remove unavailable tags.
995
+    // Remove unavailable tags.
996 996
     $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
997 997
 
998 998
     // Clean up white space.
999
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
999
+    $formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
1000 1000
     $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
1001 1001
     
1002 1002
     // Break newlines apart and remove empty lines/trim commas and white space.
1003
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
1003
+    $formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
1004 1004
 
1005 1005
     // Add html breaks.
1006
-	$formatted_address = implode( $separator, $formatted_address );
1006
+    $formatted_address = implode( $separator, $formatted_address );
1007 1007
 
1008
-	// We're done!
1009
-	return $formatted_address;
1008
+    // We're done!
1009
+    return $formatted_address;
1010 1010
     
1011 1011
 }
1012 1012
 
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
 }
1209 1209
 
1210 1210
 function wpinv_empty_cart_message() {
1211
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1211
+    return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1212 1212
 }
1213 1213
 
1214 1214
 /**
@@ -1624,46 +1624,46 @@  discard block
 block discarded – undo
1624 1624
     global $invoicing;
1625 1625
 
1626 1626
     foreach ( array_keys( $items ) as $id ) {
1627
-	    if ( 'publish' != get_post_status( $id ) ) {
1628
-		    unset( $items[ $id ] );
1629
-	    }
1627
+        if ( 'publish' != get_post_status( $id ) ) {
1628
+            unset( $items[ $id ] );
1629
+        }
1630 1630
     }
1631 1631
 
1632 1632
     if ( empty( $items ) ) {
1633
-		return aui()->alert(
1634
-			array(
1635
-				'type'    => 'warning',
1636
-				'content' => __( 'No published items found', 'invoicing' ),
1637
-			)
1638
-		);
1633
+        return aui()->alert(
1634
+            array(
1635
+                'type'    => 'warning',
1636
+                'content' => __( 'No published items found', 'invoicing' ),
1637
+            )
1638
+        );
1639 1639
     }
1640 1640
 
1641 1641
     $item_key = getpaid_convert_items_to_string( $items );
1642 1642
 
1643 1643
     // Get the form elements and items.
1644 1644
     $form     = wpinv_get_default_payment_form();
1645
-	$elements = $invoicing->form_elements->get_form_elements( $form );
1646
-	$items    = $invoicing->form_elements->convert_normal_items( $items );
1645
+    $elements = $invoicing->form_elements->get_form_elements( $form );
1646
+    $items    = $invoicing->form_elements->convert_normal_items( $items );
1647 1647
 
1648
-	ob_start();
1649
-	echo "<form class='wpinv_payment_form'>";
1650
-	do_action( 'wpinv_payment_form_top' );
1648
+    ob_start();
1649
+    echo "<form class='wpinv_payment_form'>";
1650
+    do_action( 'wpinv_payment_form_top' );
1651 1651
     echo "<input type='hidden' name='form_id' value='$form'/>";
1652 1652
     echo "<input type='hidden' name='form_items' value='$item_key'/>";
1653
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1654
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1653
+    wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1654
+    wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1655 1655
 
1656
-	foreach ( $elements as $element ) {
1657
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1658
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1659
-	}
1656
+    foreach ( $elements as $element ) {
1657
+        do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1658
+        do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1659
+    }
1660 1660
 
1661
-	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1662
-	do_action( 'wpinv_payment_form_bottom' );
1663
-	echo '</form>';
1661
+    echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1662
+    do_action( 'wpinv_payment_form_bottom' );
1663
+    echo '</form>';
1664 1664
 
1665
-	$content = ob_get_clean();
1666
-	return str_replace( 'sr-only', '', $content );
1665
+    $content = ob_get_clean();
1666
+    return str_replace( 'sr-only', '', $content );
1667 1667
 }
1668 1668
 
1669 1669
 /**
@@ -1675,47 +1675,47 @@  discard block
 block discarded – undo
1675 1675
     $invoice = wpinv_get_invoice( $invoice_id );
1676 1676
 
1677 1677
     if ( empty( $invoice ) ) {
1678
-		return aui()->alert(
1679
-			array(
1680
-				'type'    => 'warning',
1681
-				'content' => __( 'Invoice not found', 'invoicing' ),
1682
-			)
1683
-		);
1678
+        return aui()->alert(
1679
+            array(
1680
+                'type'    => 'warning',
1681
+                'content' => __( 'Invoice not found', 'invoicing' ),
1682
+            )
1683
+        );
1684 1684
     }
1685 1685
 
1686 1686
     if ( $invoice->is_paid() ) {
1687
-		return aui()->alert(
1688
-			array(
1689
-				'type'    => 'warning',
1690
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1691
-			)
1692
-		);
1687
+        return aui()->alert(
1688
+            array(
1689
+                'type'    => 'warning',
1690
+                'content' => __( 'Invoice has already been paid', 'invoicing' ),
1691
+            )
1692
+        );
1693 1693
     }
1694 1694
 
1695 1695
     // Get the form elements and items.
1696 1696
     $form     = wpinv_get_default_payment_form();
1697
-	$elements = $invoicing->form_elements->get_form_elements( $form );
1698
-	$items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1697
+    $elements = $invoicing->form_elements->get_form_elements( $form );
1698
+    $items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1699 1699
 
1700
-	ob_start();
1701
-	echo "<form class='wpinv_payment_form'>";
1702
-	do_action( 'wpinv_payment_form_top' );
1700
+    ob_start();
1701
+    echo "<form class='wpinv_payment_form'>";
1702
+    do_action( 'wpinv_payment_form_top' );
1703 1703
     echo "<input type='hidden' name='form_id' value='$form'/>";
1704 1704
     echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>";
1705
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1706
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1705
+    wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1706
+    wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1707 1707
 
1708
-	foreach ( $elements as $element ) {
1709
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1710
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1711
-	}
1708
+    foreach ( $elements as $element ) {
1709
+        do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1710
+        do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1711
+    }
1712 1712
 
1713
-	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1714
-	do_action( 'wpinv_payment_form_bottom' );
1715
-	echo '</form>';
1713
+    echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1714
+    do_action( 'wpinv_payment_form_bottom' );
1715
+    echo '</form>';
1716 1716
 
1717
-	$content = ob_get_clean();
1718
-	return str_replace( 'sr-only', '', $content );
1717
+    $content = ob_get_clean();
1718
+    return str_replace( 'sr-only', '', $content );
1719 1719
 }
1720 1720
 
1721 1721
 /**
@@ -1770,7 +1770,7 @@  discard block
 block discarded – undo
1770 1770
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; 
1771 1771
     }
1772 1772
 	
1773
-	if ( ! empty( $items ) ) {
1773
+    if ( ! empty( $items ) ) {
1774 1774
         $items  = esc_attr( $items );
1775 1775
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; 
1776 1776
     }
Please login to merge, or discard this patch.
Spacing   +561 added lines, -561 removed lines patch added patch discarded remove patch
@@ -4,99 +4,99 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Displays an invoice.
11 11
  * 
12 12
  * @param WPInv_Invoice $invoice.
13 13
  */
14
-function getpaid_invoice( $invoice ) {
15
-    if ( ! empty( $invoice ) ) {
16
-        wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) );
14
+function getpaid_invoice($invoice) {
15
+    if (!empty($invoice)) {
16
+        wpinv_get_template('invoice/invoice.php', compact('invoice'));
17 17
     }
18 18
 }
19
-add_action( 'getpaid_invoice', 'getpaid_invoice', 10 );
19
+add_action('getpaid_invoice', 'getpaid_invoice', 10);
20 20
 
21 21
 /**
22 22
  * Displays the invoice footer.
23 23
  */
24
-function getpaid_invoice_footer( $invoice ) {
25
-    if ( ! empty( $invoice ) ) {
26
-        wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) );
24
+function getpaid_invoice_footer($invoice) {
25
+    if (!empty($invoice)) {
26
+        wpinv_get_template('invoice/footer.php', compact('invoice'));
27 27
     }
28 28
 }
29
-add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 );
29
+add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10);
30 30
 
31 31
 /**
32 32
  * Displays the invoice top bar.
33 33
  */
34
-function getpaid_invoice_header( $invoice ) {
35
-    if ( ! empty( $invoice ) ) {
36
-        wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) );
34
+function getpaid_invoice_header($invoice) {
35
+    if (!empty($invoice)) {
36
+        wpinv_get_template('invoice/header.php', compact('invoice'));
37 37
     }
38 38
 }
39
-add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 );
39
+add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10);
40 40
 
41 41
 /**
42 42
  * Displays actions on the left side of the header.
43 43
  */
44
-function getpaid_invoice_header_left_actions( $invoice ) {
45
-    if ( ! empty( $invoice ) ) {
46
-        wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) );
44
+function getpaid_invoice_header_left_actions($invoice) {
45
+    if (!empty($invoice)) {
46
+        wpinv_get_template('invoice/header-left-actions.php', compact('invoice'));
47 47
     }
48 48
 }
49
-add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 );
49
+add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10);
50 50
 
51 51
 /**
52 52
  * Displays actions on the right side of the invoice top bar.
53 53
  */
54
-function getpaid_invoice_header_right_actions( $invoice ) {
55
-    if ( ! empty( $invoice ) ) {
56
-        wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) );
54
+function getpaid_invoice_header_right_actions($invoice) {
55
+    if (!empty($invoice)) {
56
+        wpinv_get_template('invoice/header-right-actions.php', compact('invoice'));
57 57
     }
58 58
 }
59
-add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 );
59
+add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10);
60 60
 
61 61
 /**
62 62
  * Displays the invoice title, watermark, logo etc.
63 63
  */
64
-function getpaid_invoice_details_top( $invoice ) {
65
-    if ( ! empty( $invoice ) ) {
66
-        wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) );
64
+function getpaid_invoice_details_top($invoice) {
65
+    if (!empty($invoice)) {
66
+        wpinv_get_template('invoice/details-top.php', compact('invoice'));
67 67
     }
68 68
 }
69
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 );
69
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10);
70 70
 
71 71
 /**
72 72
  * Displays the company logo.
73 73
  */
74
-function getpaid_invoice_logo( $invoice ) {
75
-    if ( ! empty( $invoice ) ) {
76
-        wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) );
74
+function getpaid_invoice_logo($invoice) {
75
+    if (!empty($invoice)) {
76
+        wpinv_get_template('invoice/invoice-logo.php', compact('invoice'));
77 77
     }
78 78
 }
79
-add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' );
79
+add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo');
80 80
 
81 81
 /**
82 82
  * Displays the type of invoice.
83 83
  */
84
-function getpaid_invoice_type( $invoice ) {
85
-    if ( ! empty( $invoice ) ) {
86
-        wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) );
84
+function getpaid_invoice_type($invoice) {
85
+    if (!empty($invoice)) {
86
+        wpinv_get_template('invoice/invoice-type.php', compact('invoice'));
87 87
     }
88 88
 }
89
-add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' );
89
+add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type');
90 90
 
91 91
 /**
92 92
  * Displays the invoice details.
93 93
  */
94
-function getpaid_invoice_details_main( $invoice ) {
95
-    if ( ! empty( $invoice ) ) {
96
-        wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) );
94
+function getpaid_invoice_details_main($invoice) {
95
+    if (!empty($invoice)) {
96
+        wpinv_get_template('invoice/details.php', compact('invoice'));
97 97
     }
98 98
 }
99
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 );
99
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50);
100 100
 
101 101
 /**
102 102
  * Returns a path to the templates directory.
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
126 126
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
127 127
  */
128
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
129
-    return getpaid_template()->display_template( $template_name, $args, $template_path, $default_path );
128
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
129
+    return getpaid_template()->display_template($template_name, $args, $template_path, $default_path);
130 130
 }
131 131
 
132 132
 /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
142
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
143
+	return getpaid_template()->get_template($template_name, $args, $template_path, $default_path);
144 144
 }
145 145
 
146 146
 /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
  * @return string
150 150
  */
151 151
 function wpinv_template_path() {
152
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
152
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
153 153
 }
154 154
 
155 155
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
162 162
 }
163 163
 
164 164
 /**
@@ -170,56 +170,56 @@  discard block
 block discarded – undo
170 170
  * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
171 171
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
172 172
  */
173
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
174
-    return getpaid_template()->locate_template( $template_name, $template_path, $default_path );
173
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
174
+    return getpaid_template()->locate_template($template_name, $template_path, $default_path);
175 175
 }
176 176
 
177
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
177
+function wpinv_get_template_part($slug, $name = null, $load = true) {
178
+	do_action('get_template_part_' . $slug, $slug, $name);
179 179
 
180 180
 	// Setup possible parts
181 181
 	$templates = array();
182
-	if ( isset( $name ) )
182
+	if (isset($name))
183 183
 		$templates[] = $slug . '-' . $name . '.php';
184 184
 	$templates[] = $slug . '.php';
185 185
 
186 186
 	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
187
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
188 188
 
189 189
 	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
190
+	return wpinv_locate_tmpl($templates, $load, false);
191 191
 }
192 192
 
193
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
193
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
194 194
 	// No file found yet
195 195
 	$located = false;
196 196
 
197 197
 	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
198
+	foreach ((array) $template_names as $template_name) {
199 199
 
200 200
 		// Continue if template is empty
201
-		if ( empty( $template_name ) )
201
+		if (empty($template_name))
202 202
 			continue;
203 203
 
204 204
 		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
205
+		$template_name = ltrim($template_name, '/');
206 206
 
207 207
 		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
208
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
210
+			if (file_exists($template_path . $template_name)) {
211 211
 				$located = $template_path . $template_name;
212 212
 				break;
213 213
 			}
214 214
 		}
215 215
 
216
-		if( !empty( $located ) ) {
216
+		if (!empty($located)) {
217 217
 			break;
218 218
 		}
219 219
 	}
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+	if ((true == $load) && !empty($located))
222
+		load_template($located, $require_once);
223 223
 
224 224
 	return $located;
225 225
 }
@@ -228,155 +228,155 @@  discard block
 block discarded – undo
228 228
 	$template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230 230
 	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
231
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
232
+		10 => trailingslashit(get_template_directory()) . $template_dir,
233 233
 		100 => wpinv_get_templates_dir()
234 234
 	);
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
237 237
 
238 238
 	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
239
+	ksort($file_paths, SORT_NUMERIC);
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+	return array_map('trailingslashit', $file_paths);
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246 246
 	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
247
+	$pages[] = wpinv_get_option('success_page');
248
+	$pages[] = wpinv_get_option('failure_page');
249
+	$pages[] = wpinv_get_option('invoice_history_page');
250
+	$pages[] = wpinv_get_option('invoice_subscription_page');
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
252
+	if (!wpinv_is_checkout() && !is_page($pages)) {
253 253
 		return;
254 254
 	}
255 255
 
256 256
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
258
+add_action('wp_head', 'wpinv_checkout_meta_tags');
259 259
 
260
-function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
260
+function wpinv_add_body_classes($class) {
261
+	$classes = (array) $class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
263
+	if (wpinv_is_checkout()) {
264 264
 		$classes[] = 'wpinv-checkout';
265 265
 		$classes[] = 'wpinv-page';
266 266
 	}
267 267
 
268
-	if( wpinv_is_success_page() ) {
268
+	if (wpinv_is_success_page()) {
269 269
 		$classes[] = 'wpinv-success';
270 270
 		$classes[] = 'wpinv-page';
271 271
 	}
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
273
+	if (wpinv_is_failed_transaction_page()) {
274 274
 		$classes[] = 'wpinv-failed-transaction';
275 275
 		$classes[] = 'wpinv-page';
276 276
 	}
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
278
+	if (wpinv_is_invoice_history_page()) {
279 279
 		$classes[] = 'wpinv-history';
280 280
 		$classes[] = 'wpinv-page';
281 281
 	}
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
283
+	if (wpinv_is_subscriptions_history_page()) {
284 284
 		$classes[] = 'wpinv-subscription';
285 285
 		$classes[] = 'wpinv-page';
286 286
 	}
287 287
 
288
-	if( wpinv_is_test_mode() ) {
288
+	if (wpinv_is_test_mode()) {
289 289
 		$classes[] = 'wpinv-test-mode';
290 290
 		$classes[] = 'wpinv-page';
291 291
 	}
292 292
 
293
-	return array_unique( $classes );
293
+	return array_unique($classes);
294 294
 }
295
-add_filter( 'body_class', 'wpinv_add_body_classes' );
295
+add_filter('body_class', 'wpinv_add_body_classes');
296 296
 
297
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
298
-    $args = array( 'nopaging' => true );
297
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
298
+    $args = array('nopaging' => true);
299 299
 
300
-    if ( ! empty( $status ) )
300
+    if (!empty($status))
301 301
         $args['post_status'] = $status;
302 302
 
303
-    $discounts = wpinv_get_discounts( $args );
303
+    $discounts = wpinv_get_discounts($args);
304 304
     $options   = array();
305 305
 
306
-    if ( $discounts ) {
307
-        foreach ( $discounts as $discount ) {
308
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
306
+    if ($discounts) {
307
+        foreach ($discounts as $discount) {
308
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
309 309
         }
310 310
     } else {
311
-        $options[0] = __( 'No discounts found', 'invoicing' );
311
+        $options[0] = __('No discounts found', 'invoicing');
312 312
     }
313 313
 
314
-    $output = wpinv_html_select( array(
314
+    $output = wpinv_html_select(array(
315 315
         'name'             => $name,
316 316
         'selected'         => $selected,
317 317
         'options'          => $options,
318 318
         'show_option_all'  => false,
319 319
         'show_option_none' => false,
320
-    ) );
320
+    ));
321 321
 
322 322
     return $output;
323 323
 }
324 324
 
325
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
326
-    $current     = date( 'Y' );
327
-    $start_year  = $current - absint( $years_before );
328
-    $end_year    = $current + absint( $years_after );
329
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
325
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
326
+    $current     = date('Y');
327
+    $start_year  = $current - absint($years_before);
328
+    $end_year    = $current + absint($years_after);
329
+    $selected    = empty($selected) ? date('Y') : $selected;
330 330
     $options     = array();
331 331
 
332
-    while ( $start_year <= $end_year ) {
333
-        $options[ absint( $start_year ) ] = $start_year;
332
+    while ($start_year <= $end_year) {
333
+        $options[absint($start_year)] = $start_year;
334 334
         $start_year++;
335 335
     }
336 336
 
337
-    $output = wpinv_html_select( array(
337
+    $output = wpinv_html_select(array(
338 338
         'name'             => $name,
339 339
         'selected'         => $selected,
340 340
         'options'          => $options,
341 341
         'show_option_all'  => false,
342 342
         'show_option_none' => false
343
-    ) );
343
+    ));
344 344
 
345 345
     return $output;
346 346
 }
347 347
 
348
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
348
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
349 349
 
350 350
     $options = array(
351
-        '1'  => __( 'January', 'invoicing' ),
352
-        '2'  => __( 'February', 'invoicing' ),
353
-        '3'  => __( 'March', 'invoicing' ),
354
-        '4'  => __( 'April', 'invoicing' ),
355
-        '5'  => __( 'May', 'invoicing' ),
356
-        '6'  => __( 'June', 'invoicing' ),
357
-        '7'  => __( 'July', 'invoicing' ),
358
-        '8'  => __( 'August', 'invoicing' ),
359
-        '9'  => __( 'September', 'invoicing' ),
360
-        '10' => __( 'October', 'invoicing' ),
361
-        '11' => __( 'November', 'invoicing' ),
362
-        '12' => __( 'December', 'invoicing' ),
351
+        '1'  => __('January', 'invoicing'),
352
+        '2'  => __('February', 'invoicing'),
353
+        '3'  => __('March', 'invoicing'),
354
+        '4'  => __('April', 'invoicing'),
355
+        '5'  => __('May', 'invoicing'),
356
+        '6'  => __('June', 'invoicing'),
357
+        '7'  => __('July', 'invoicing'),
358
+        '8'  => __('August', 'invoicing'),
359
+        '9'  => __('September', 'invoicing'),
360
+        '10' => __('October', 'invoicing'),
361
+        '11' => __('November', 'invoicing'),
362
+        '12' => __('December', 'invoicing'),
363 363
     );
364 364
 
365 365
     // If no month is selected, default to the current month
366
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
366
+    $selected = empty($selected) ? date('n') : $selected;
367 367
 
368
-    $output = wpinv_html_select( array(
368
+    $output = wpinv_html_select(array(
369 369
         'name'             => $name,
370 370
         'selected'         => $selected,
371 371
         'options'          => $options,
372 372
         'show_option_all'  => false,
373 373
         'show_option_none' => false
374
-    ) );
374
+    ));
375 375
 
376 376
     return $output;
377 377
 }
378 378
 
379
-function wpinv_html_select( $args = array() ) {
379
+function wpinv_html_select($args = array()) {
380 380
     $defaults = array(
381 381
         'options'          => array(),
382 382
         'name'             => null,
@@ -385,8 +385,8 @@  discard block
 block discarded – undo
385 385
         'selected'         => 0,
386 386
         'placeholder'      => null,
387 387
         'multiple'         => false,
388
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
389
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
388
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
389
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
390 390
         'data'             => array(),
391 391
         'onchange'         => null,
392 392
         'required'         => false,
@@ -394,74 +394,74 @@  discard block
 block discarded – undo
394 394
         'readonly'         => false,
395 395
     );
396 396
 
397
-    $args = wp_parse_args( $args, $defaults );
397
+    $args = wp_parse_args($args, $defaults);
398 398
 
399 399
     $data_elements = '';
400
-    foreach ( $args['data'] as $key => $value ) {
401
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
400
+    foreach ($args['data'] as $key => $value) {
401
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
402 402
     }
403 403
 
404
-    if( $args['multiple'] ) {
404
+    if ($args['multiple']) {
405 405
         $multiple = ' MULTIPLE';
406 406
     } else {
407 407
         $multiple = '';
408 408
     }
409 409
 
410
-    if( $args['placeholder'] ) {
410
+    if ($args['placeholder']) {
411 411
         $placeholder = $args['placeholder'];
412 412
     } else {
413 413
         $placeholder = '';
414 414
     }
415 415
     
416 416
     $options = '';
417
-    if( !empty( $args['onchange'] ) ) {
418
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
417
+    if (!empty($args['onchange'])) {
418
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
419 419
     }
420 420
     
421
-    if( !empty( $args['required'] ) ) {
421
+    if (!empty($args['required'])) {
422 422
         $options .= ' required="required"';
423 423
     }
424 424
     
425
-    if( !empty( $args['disabled'] ) ) {
425
+    if (!empty($args['disabled'])) {
426 426
         $options .= ' disabled';
427 427
     }
428 428
     
429
-    if( !empty( $args['readonly'] ) ) {
429
+    if (!empty($args['readonly'])) {
430 430
         $options .= ' readonly';
431 431
     }
432 432
 
433
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
434
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
433
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
434
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
435 435
 
436
-    if ( $args['show_option_all'] ) {
437
-        if( $args['multiple'] ) {
438
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
436
+    if ($args['show_option_all']) {
437
+        if ($args['multiple']) {
438
+            $selected = selected(true, in_array(0, $args['selected']), false);
439 439
         } else {
440
-            $selected = selected( $args['selected'], 0, false );
440
+            $selected = selected($args['selected'], 0, false);
441 441
         }
442
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
442
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
443 443
     }
444 444
 
445
-    if ( !empty( $args['options'] ) ) {
445
+    if (!empty($args['options'])) {
446 446
 
447
-        if ( $args['show_option_none'] ) {
448
-            if( $args['multiple'] ) {
449
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
447
+        if ($args['show_option_none']) {
448
+            if ($args['multiple']) {
449
+                $selected = selected(true, in_array("", $args['selected']), false);
450 450
             } else {
451
-                $selected = selected( $args['selected'] === "", true, false );
451
+                $selected = selected($args['selected'] === "", true, false);
452 452
             }
453
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
453
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
454 454
         }
455 455
 
456
-        foreach( $args['options'] as $key => $option ) {
456
+        foreach ($args['options'] as $key => $option) {
457 457
 
458
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
459
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
458
+            if ($args['multiple'] && is_array($args['selected'])) {
459
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
460 460
             } else {
461
-                $selected = selected( $args['selected'], $key, false );
461
+                $selected = selected($args['selected'], $key, false);
462 462
             }
463 463
 
464
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
464
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
465 465
         }
466 466
     }
467 467
 
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
     return $output;
471 471
 }
472 472
 
473
-function wpinv_item_dropdown( $args = array() ) {
473
+function wpinv_item_dropdown($args = array()) {
474 474
     $defaults = array(
475 475
         'name'              => 'wpi_item',
476 476
         'id'                => 'wpi_item',
@@ -478,14 +478,14 @@  discard block
 block discarded – undo
478 478
         'multiple'          => false,
479 479
         'selected'          => 0,
480 480
         'number'            => 100,
481
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
482
-        'data'              => array( 'search-type' => 'item' ),
481
+        'placeholder'       => __('Choose a item', 'invoicing'),
482
+        'data'              => array('search-type' => 'item'),
483 483
         'show_option_all'   => false,
484 484
         'show_option_none'  => false,
485 485
         'show_recurring'    => false,
486 486
     );
487 487
 
488
-    $args = wp_parse_args( $args, $defaults );
488
+    $args = wp_parse_args($args, $defaults);
489 489
 
490 490
     $item_args = array(
491 491
         'post_type'      => 'wpi_item',
@@ -494,44 +494,44 @@  discard block
 block discarded – undo
494 494
         'posts_per_page' => $args['number']
495 495
     );
496 496
 
497
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
497
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
498 498
 
499
-    $items      = get_posts( $item_args );
499
+    $items      = get_posts($item_args);
500 500
     $options    = array();
501
-    if ( $items ) {
502
-        foreach ( $items as $item ) {
503
-            $title = esc_html( $item->post_title );
501
+    if ($items) {
502
+        foreach ($items as $item) {
503
+            $title = esc_html($item->post_title);
504 504
             
505
-            if ( !empty( $args['show_recurring'] ) ) {
506
-                $title .= wpinv_get_item_suffix( $item->ID, false );
505
+            if (!empty($args['show_recurring'])) {
506
+                $title .= wpinv_get_item_suffix($item->ID, false);
507 507
             }
508 508
             
509
-            $options[ absint( $item->ID ) ] = $title;
509
+            $options[absint($item->ID)] = $title;
510 510
         }
511 511
     }
512 512
 
513 513
     // This ensures that any selected items are included in the drop down
514
-    if( is_array( $args['selected'] ) ) {
515
-        foreach( $args['selected'] as $item ) {
516
-            if( ! in_array( $item, $options ) ) {
517
-                $title = get_the_title( $item );
518
-                if ( !empty( $args['show_recurring'] ) ) {
519
-                    $title .= wpinv_get_item_suffix( $item, false );
514
+    if (is_array($args['selected'])) {
515
+        foreach ($args['selected'] as $item) {
516
+            if (!in_array($item, $options)) {
517
+                $title = get_the_title($item);
518
+                if (!empty($args['show_recurring'])) {
519
+                    $title .= wpinv_get_item_suffix($item, false);
520 520
                 }
521 521
                 $options[$item] = $title;
522 522
             }
523 523
         }
524
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
525
-        if ( ! in_array( $args['selected'], $options ) ) {
526
-            $title = get_the_title( $args['selected'] );
527
-            if ( !empty( $args['show_recurring'] ) ) {
528
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
524
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
525
+        if (!in_array($args['selected'], $options)) {
526
+            $title = get_the_title($args['selected']);
527
+            if (!empty($args['show_recurring'])) {
528
+                $title .= wpinv_get_item_suffix($args['selected'], false);
529 529
             }
530
-            $options[$args['selected']] = get_the_title( $args['selected'] );
530
+            $options[$args['selected']] = get_the_title($args['selected']);
531 531
         }
532 532
     }
533 533
 
534
-    $output = wpinv_html_select( array(
534
+    $output = wpinv_html_select(array(
535 535
         'name'             => $args['name'],
536 536
         'selected'         => $args['selected'],
537 537
         'id'               => $args['id'],
@@ -542,7 +542,7 @@  discard block
 block discarded – undo
542 542
         'show_option_all'  => $args['show_option_all'],
543 543
         'show_option_none' => $args['show_option_none'],
544 544
         'data'             => $args['data'],
545
-    ) );
545
+    ));
546 546
 
547 547
     return $output;
548 548
 }
@@ -562,16 +562,16 @@  discard block
 block discarded – undo
562 562
     );
563 563
 
564 564
     $options = array();
565
-    if ( $items ) {
566
-        foreach ( $items as $item ) {
567
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
565
+    if ($items) {
566
+        foreach ($items as $item) {
567
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
568 568
         }
569 569
     }
570 570
 
571 571
     return $options;
572 572
 }
573 573
 
574
-function wpinv_html_checkbox( $args = array() ) {
574
+function wpinv_html_checkbox($args = array()) {
575 575
     $defaults = array(
576 576
         'name'     => null,
577 577
         'current'  => null,
@@ -582,17 +582,17 @@  discard block
 block discarded – undo
582 582
         )
583 583
     );
584 584
 
585
-    $args = wp_parse_args( $args, $defaults );
585
+    $args = wp_parse_args($args, $defaults);
586 586
 
587
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
587
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
588 588
     $options = '';
589
-    if ( ! empty( $args['options']['disabled'] ) ) {
589
+    if (!empty($args['options']['disabled'])) {
590 590
         $options .= ' disabled="disabled"';
591
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
591
+    } elseif (!empty($args['options']['readonly'])) {
592 592
         $options .= ' readonly';
593 593
     }
594 594
 
595
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
595
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
596 596
 
597 597
     return $output;
598 598
 }
@@ -600,30 +600,30 @@  discard block
 block discarded – undo
600 600
 /**
601 601
  * Displays a hidden field.
602 602
  */
603
-function getpaid_hidden_field( $name, $value ) {
604
-    $name  = sanitize_text_field( $name );
605
-    $value = esc_attr( $value );
603
+function getpaid_hidden_field($name, $value) {
604
+    $name  = sanitize_text_field($name);
605
+    $value = esc_attr($value);
606 606
 
607 607
     echo "<input type='hidden' name='$name' value='$value' />";
608 608
 }
609 609
 
610
-function wpinv_html_text( $args = array() ) {
610
+function wpinv_html_text($args = array()) {
611 611
     // Backwards compatibility
612
-    if ( func_num_args() > 1 ) {
612
+    if (func_num_args() > 1) {
613 613
         $args = func_get_args();
614 614
 
615 615
         $name  = $args[0];
616
-        $value = isset( $args[1] ) ? $args[1] : '';
617
-        $label = isset( $args[2] ) ? $args[2] : '';
618
-        $desc  = isset( $args[3] ) ? $args[3] : '';
616
+        $value = isset($args[1]) ? $args[1] : '';
617
+        $label = isset($args[2]) ? $args[2] : '';
618
+        $desc  = isset($args[3]) ? $args[3] : '';
619 619
     }
620 620
 
621 621
     $defaults = array(
622 622
         'id'           => '',
623
-        'name'         => isset( $name )  ? $name  : 'text',
624
-        'value'        => isset( $value ) ? $value : null,
625
-        'label'        => isset( $label ) ? $label : null,
626
-        'desc'         => isset( $desc )  ? $desc  : null,
623
+        'name'         => isset($name) ? $name : 'text',
624
+        'value'        => isset($value) ? $value : null,
625
+        'label'        => isset($label) ? $label : null,
626
+        'desc'         => isset($desc) ? $desc : null,
627 627
         'placeholder'  => '',
628 628
         'class'        => 'regular-text',
629 629
         'disabled'     => false,
@@ -633,51 +633,51 @@  discard block
 block discarded – undo
633 633
         'data'         => false
634 634
     );
635 635
 
636
-    $args = wp_parse_args( $args, $defaults );
636
+    $args = wp_parse_args($args, $defaults);
637 637
 
638
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
638
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
639 639
     $options = '';
640
-    if( $args['required'] ) {
640
+    if ($args['required']) {
641 641
         $options .= ' required="required"';
642 642
     }
643
-    if( $args['readonly'] ) {
643
+    if ($args['readonly']) {
644 644
         $options .= ' readonly';
645 645
     }
646
-    if( $args['readonly'] ) {
646
+    if ($args['readonly']) {
647 647
         $options .= ' readonly';
648 648
     }
649 649
 
650 650
     $data = '';
651
-    if ( !empty( $args['data'] ) ) {
652
-        foreach ( $args['data'] as $key => $value ) {
653
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
651
+    if (!empty($args['data'])) {
652
+        foreach ($args['data'] as $key => $value) {
653
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
654 654
         }
655 655
     }
656 656
 
657
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
658
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
659
-    if ( ! empty( $args['desc'] ) ) {
660
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
657
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
658
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
659
+    if (!empty($args['desc'])) {
660
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
661 661
     }
662 662
 
663
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
663
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
664 664
 
665 665
     $output .= '</span>';
666 666
 
667 667
     return $output;
668 668
 }
669 669
 
670
-function wpinv_html_date_field( $args = array() ) {
671
-    if( empty( $args['class'] ) ) {
670
+function wpinv_html_date_field($args = array()) {
671
+    if (empty($args['class'])) {
672 672
         $args['class'] = 'wpiDatepicker';
673
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
673
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
674 674
         $args['class'] .= ' wpiDatepicker';
675 675
     }
676 676
 
677
-    return wpinv_html_text( $args );
677
+    return wpinv_html_text($args);
678 678
 }
679 679
 
680
-function wpinv_html_textarea( $args = array() ) {
680
+function wpinv_html_textarea($args = array()) {
681 681
     $defaults = array(
682 682
         'name'        => 'textarea',
683 683
         'value'       => null,
@@ -688,31 +688,31 @@  discard block
 block discarded – undo
688 688
         'placeholder' => '',
689 689
     );
690 690
 
691
-    $args = wp_parse_args( $args, $defaults );
691
+    $args = wp_parse_args($args, $defaults);
692 692
 
693
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
693
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
694 694
     $disabled = '';
695
-    if( $args['disabled'] ) {
695
+    if ($args['disabled']) {
696 696
         $disabled = ' disabled="disabled"';
697 697
     }
698 698
 
699
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
700
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
701
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
699
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
700
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
701
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
702 702
 
703
-    if ( ! empty( $args['desc'] ) ) {
704
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
703
+    if (!empty($args['desc'])) {
704
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
705 705
     }
706 706
     $output .= '</span>';
707 707
 
708 708
     return $output;
709 709
 }
710 710
 
711
-function wpinv_html_ajax_user_search( $args = array() ) {
711
+function wpinv_html_ajax_user_search($args = array()) {
712 712
     $defaults = array(
713 713
         'name'        => 'user_id',
714 714
         'value'       => null,
715
-        'placeholder' => __( 'Enter username', 'invoicing' ),
715
+        'placeholder' => __('Enter username', 'invoicing'),
716 716
         'label'       => null,
717 717
         'desc'        => null,
718 718
         'class'       => '',
@@ -721,13 +721,13 @@  discard block
 block discarded – undo
721 721
         'data'        => false
722 722
     );
723 723
 
724
-    $args = wp_parse_args( $args, $defaults );
724
+    $args = wp_parse_args($args, $defaults);
725 725
 
726 726
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
727 727
 
728 728
     $output  = '<span class="wpinv_user_search_wrap">';
729
-        $output .= wpinv_html_text( $args );
730
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
729
+        $output .= wpinv_html_text($args);
730
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
731 731
     $output .= '</span>';
732 732
 
733 733
     return $output;
@@ -743,20 +743,20 @@  discard block
 block discarded – undo
743 743
  * 
744 744
  * @param string $template the template that is currently being used.
745 745
  */
746
-function wpinv_template( $template ) {
746
+function wpinv_template($template) {
747 747
     global $post;
748 748
 
749
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
749
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
750 750
 
751 751
         // If the user can view this invoice, display it.
752
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
752
+        if (wpinv_user_can_view_invoice($post->ID)) {
753 753
 
754
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
754
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
755 755
 
756 756
         // Else display an error message.
757 757
         } else {
758 758
 
759
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
759
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
760 760
 
761 761
         }
762 762
 
@@ -764,46 +764,46 @@  discard block
 block discarded – undo
764 764
 
765 765
     return $template;
766 766
 }
767
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
767
+add_filter('template_include', 'wpinv_template', 10, 1);
768 768
 
769 769
 function wpinv_get_business_address() {
770 770
     $business_address   = wpinv_store_address();
771
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
771
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
772 772
     
773 773
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
774 774
     
775
-    return apply_filters( 'wpinv_get_business_address', $business_address );
775
+    return apply_filters('wpinv_get_business_address', $business_address);
776 776
 }
777 777
 
778 778
 /**
779 779
  * Displays the company address.
780 780
  */
781 781
 function wpinv_display_from_address() {
782
-    wpinv_get_template( 'invoice/company-address.php' );
782
+    wpinv_get_template('invoice/company-address.php');
783 783
 }
784
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
784
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
785 785
 
786
-function wpinv_watermark( $id = 0 ) {
787
-    $output = wpinv_get_watermark( $id );
788
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
786
+function wpinv_watermark($id = 0) {
787
+    $output = wpinv_get_watermark($id);
788
+    return apply_filters('wpinv_get_watermark', $output, $id);
789 789
 }
790 790
 
791
-function wpinv_get_watermark( $id ) {
792
-    if ( !$id > 0 ) {
791
+function wpinv_get_watermark($id) {
792
+    if (!$id > 0) {
793 793
         return NULL;
794 794
     }
795 795
 
796
-    $invoice = wpinv_get_invoice( $id );
796
+    $invoice = wpinv_get_invoice($id);
797 797
     
798
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
799
-        if ( $invoice->is_paid() ) {
800
-            return __( 'Paid', 'invoicing' );
798
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
799
+        if ($invoice->is_paid()) {
800
+            return __('Paid', 'invoicing');
801 801
         }
802
-        if ( $invoice->is_refunded() ) {
803
-            return __( 'Refunded', 'invoicing' );
802
+        if ($invoice->is_refunded()) {
803
+            return __('Refunded', 'invoicing');
804 804
         }
805
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
806
-            return __( 'Cancelled', 'invoicing' );
805
+        if ($invoice->has_status(array('wpi-cancelled'))) {
806
+            return __('Cancelled', 'invoicing');
807 807
         }
808 808
     }
809 809
     
@@ -813,140 +813,140 @@  discard block
 block discarded – undo
813 813
 /**
814 814
  * @deprecated
815 815
  */
816
-function wpinv_display_invoice_details( $invoice ) {
817
-    return getpaid_invoice_meta( $invoice );
816
+function wpinv_display_invoice_details($invoice) {
817
+    return getpaid_invoice_meta($invoice);
818 818
 }
819 819
 
820 820
 /**
821 821
  * Displays invoice meta.
822 822
  */
823
-function getpaid_invoice_meta( $invoice ) {
823
+function getpaid_invoice_meta($invoice) {
824 824
 
825
-    $invoice = new WPInv_Invoice( $invoice );
825
+    $invoice = new WPInv_Invoice($invoice);
826 826
 
827 827
     // Ensure that we have an invoice.
828
-    if ( 0 == $invoice->get_id() ) {
828
+    if (0 == $invoice->get_id()) {
829 829
         return;
830 830
     }
831 831
 
832 832
     // Load the invoice meta.
833
-    $meta    = array(
833
+    $meta = array(
834 834
 
835 835
         'number' => array(
836 836
             'label' => sprintf(
837
-                __( '%s Number', 'invoicing' ),
838
-                ucfirst( $invoice->get_type() )
837
+                __('%s Number', 'invoicing'),
838
+                ucfirst($invoice->get_type())
839 839
             ),
840
-            'value' => sanitize_text_field( $invoice->get_number() ),
840
+            'value' => sanitize_text_field($invoice->get_number()),
841 841
         ),
842 842
 
843 843
         'status' => array(
844 844
             'label' => sprintf(
845
-                __( '%s Status', 'invoicing' ),
846
-                ucfirst( $invoice->get_type() )
845
+                __('%s Status', 'invoicing'),
846
+                ucfirst($invoice->get_type())
847 847
             ),
848
-            'value' => sanitize_text_field( $invoice->get_status_nicename() ),
848
+            'value' => sanitize_text_field($invoice->get_status_nicename()),
849 849
         ),
850 850
 
851 851
         'date' => array(
852 852
             'label' => sprintf(
853
-                __( '%s Date', 'invoicing' ),
854
-                ucfirst( $invoice->get_type() )
853
+                __('%s Date', 'invoicing'),
854
+                ucfirst($invoice->get_type())
855 855
             ),
856
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
856
+            'value' => getpaid_format_date($invoice->get_created_date()),
857 857
         ),
858 858
 
859 859
         'date_paid' => array(
860
-            'label' => __( 'Paid On', 'invoicing' ),
861
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
860
+            'label' => __('Paid On', 'invoicing'),
861
+            'value' => getpaid_format_date($invoice->get_completed_date()),
862 862
         ),
863 863
 
864 864
         'gateway'   => array(
865
-            'label' => __( 'Payment Method', 'invoicing' ),
866
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
865
+            'label' => __('Payment Method', 'invoicing'),
866
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
867 867
         ),
868 868
 
869 869
         'transaction_id' => array(
870
-            'label' => __( 'Transaction ID', 'invoicing' ),
871
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
870
+            'label' => __('Transaction ID', 'invoicing'),
871
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
872 872
         ),
873 873
 
874 874
         'due_date'  => array(
875
-            'label' => __( 'Due Date', 'invoicing' ),
876
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
875
+            'label' => __('Due Date', 'invoicing'),
876
+            'value' => getpaid_format_date($invoice->get_due_date()),
877 877
         ),
878 878
 
879 879
         'vat_number' => array(
880 880
             'label' => sprintf(
881
-                __( '%s Number', 'invoicing' ),
881
+                __('%s Number', 'invoicing'),
882 882
                 getpaid_tax()->get_vat_name()
883 883
             ),
884
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
884
+            'value' => sanitize_text_field($invoice->get_vat_number()),
885 885
         ),
886 886
 
887 887
     );
888 888
 
889 889
     // If it is not paid, remove the date of payment.
890
-    if ( ! $invoice->is_paid() ) {
891
-        unset( $meta[ 'date_paid' ] );
892
-        unset( $meta[ 'transaction_id' ] );
890
+    if (!$invoice->is_paid()) {
891
+        unset($meta['date_paid']);
892
+        unset($meta['transaction_id']);
893 893
     }
894 894
 
895
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
896
-        unset( $meta[ 'gateway' ] );
895
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
896
+        unset($meta['gateway']);
897 897
     }
898 898
 
899 899
     // Only display the due date if due dates are enabled.
900
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
901
-        unset( $meta[ 'due_date' ] );
900
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
901
+        unset($meta['due_date']);
902 902
     }
903 903
 
904 904
     // Only display the vat number if taxes are enabled.
905
-    if ( ! wpinv_use_taxes() ) {
906
-        unset( $meta[ 'vat_number' ] );
905
+    if (!wpinv_use_taxes()) {
906
+        unset($meta['vat_number']);
907 907
     }
908 908
 
909
-    if ( $invoice->is_recurring() ) {
909
+    if ($invoice->is_recurring()) {
910 910
 
911 911
         // Link to the parent invoice.
912
-        if ( $invoice->is_renewal() ) {
912
+        if ($invoice->is_renewal()) {
913 913
 
914
-            $meta[ 'parent' ] = array(
914
+            $meta['parent'] = array(
915 915
 
916 916
                 'label' => sprintf(
917
-                    __( 'Parent %s', 'invoicing' ),
918
-                    ucfirst( $invoice->get_type() )
917
+                    __('Parent %s', 'invoicing'),
918
+                    ucfirst($invoice->get_type())
919 919
                 ),
920 920
 
921
-                'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
921
+                'value' => wpinv_invoice_link($invoice->get_parent_id()),
922 922
 
923 923
             );
924 924
 
925 925
         }
926 926
 
927
-        $subscription = wpinv_get_subscription( $invoice );
927
+        $subscription = wpinv_get_subscription($invoice);
928 928
 
929
-        if ( ! empty ( $subscription ) ) {
929
+        if (!empty ($subscription)) {
930 930
 
931 931
             // Display the renewal date.
932
-            if ( $subscription->is_active() && 'cancelled' != $subscription->status ) {
932
+            if ($subscription->is_active() && 'cancelled' != $subscription->status) {
933 933
 
934
-                $meta[ 'renewal_date' ] = array(
934
+                $meta['renewal_date'] = array(
935 935
 
936
-                    'label' => __( 'Renews On', 'invoicing' ),
937
-                    'value' => getpaid_format_date( $subscription->expiration ),
936
+                    'label' => __('Renews On', 'invoicing'),
937
+                    'value' => getpaid_format_date($subscription->expiration),
938 938
         
939 939
                 );
940 940
 
941 941
             }
942 942
 
943
-            if ( $invoice->is_parent() ) {
943
+            if ($invoice->is_parent()) {
944 944
 
945 945
                 // Display the recurring amount.
946
-                $meta[ 'recurring_total' ] = array(
946
+                $meta['recurring_total'] = array(
947 947
 
948
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
949
-                    'value' => wpinv_price( wpinv_format_amount( $subscription->recurring_amount ), $invoice->get_currency() ),
948
+                    'label' => __('Recurring Amount', 'invoicing'),
949
+                    'value' => wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()),
950 950
         
951 951
                 );
952 952
 
@@ -956,20 +956,20 @@  discard block
 block discarded – undo
956 956
     }
957 957
 
958 958
     // Add the invoice total to the meta.
959
-    $meta[ 'invoice_total' ] = array(
959
+    $meta['invoice_total'] = array(
960 960
 
961
-        'label' => __( 'Total Amount', 'invoicing' ),
962
-        'value' => wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ),
961
+        'label' => __('Total Amount', 'invoicing'),
962
+        'value' => wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()),
963 963
 
964 964
     );
965 965
 
966 966
     // Provide a way for third party plugins to filter the meta.
967
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
967
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
968 968
 
969
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
969
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
970 970
 
971 971
 }
972
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
972
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
973 973
 
974 974
 /**
975 975
  * Retrieves the address markup to use on Invoices.
@@ -981,29 +981,29 @@  discard block
 block discarded – undo
981 981
  * @param  string $separator How to separate address lines.
982 982
  * @return string
983 983
  */
984
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
984
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
985 985
 
986 986
     // Retrieve the address markup...
987
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
988
-    $format = wpinv_get_full_address_format( $country );
987
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
988
+    $format = wpinv_get_full_address_format($country);
989 989
 
990 990
     // ... and the replacements.
991
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
991
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
992 992
 
993
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
993
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
994 994
     
995 995
 	// Remove unavailable tags.
996
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
996
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
997 997
 
998 998
     // Clean up white space.
999
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
1000
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
999
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
1000
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
1001 1001
     
1002 1002
     // Break newlines apart and remove empty lines/trim commas and white space.
1003
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
1003
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
1004 1004
 
1005 1005
     // Add html breaks.
1006
-	$formatted_address = implode( $separator, $formatted_address );
1006
+	$formatted_address = implode($separator, $formatted_address);
1007 1007
 
1008 1008
 	// We're done!
1009 1009
 	return $formatted_address;
@@ -1015,88 +1015,88 @@  discard block
 block discarded – undo
1015 1015
  * 
1016 1016
  * @param WPInv_Invoice $invoice
1017 1017
  */
1018
-function wpinv_display_to_address( $invoice = 0 ) {
1019
-    if ( ! empty( $invoice ) ) {
1020
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
1018
+function wpinv_display_to_address($invoice = 0) {
1019
+    if (!empty($invoice)) {
1020
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
1021 1021
     }
1022 1022
 }
1023
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
1023
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
1024 1024
 
1025 1025
 
1026 1026
 /**
1027 1027
  * Displays invoice line items.
1028 1028
  */
1029
-function wpinv_display_line_items( $invoice_id = 0 ) {
1029
+function wpinv_display_line_items($invoice_id = 0) {
1030 1030
 
1031 1031
     // Prepare the invoice.
1032
-    $invoice = new WPInv_Invoice( $invoice_id );
1032
+    $invoice = new WPInv_Invoice($invoice_id);
1033 1033
 
1034 1034
     // Abort if there is no invoice.
1035
-    if ( 0 == $invoice->get_id() ) {
1035
+    if (0 == $invoice->get_id()) {
1036 1036
         return;
1037 1037
     }
1038 1038
 
1039 1039
     // Line item columns.
1040
-    $columns = getpaid_invoice_item_columns( $invoice );
1041
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
1040
+    $columns = getpaid_invoice_item_columns($invoice);
1041
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
1042 1042
 
1043
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
1043
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
1044 1044
 }
1045
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
1045
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
1046 1046
 
1047 1047
 /**
1048 1048
  * Displays invoice notices on invoices.
1049 1049
  */
1050 1050
 function wpinv_display_invoice_notice() {
1051 1051
 
1052
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
1053
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
1052
+    $label  = wpinv_get_option('vat_invoice_notice_label');
1053
+    $notice = wpinv_get_option('vat_invoice_notice');
1054 1054
 
1055
-    if ( empty( $label ) && empty( $notice ) ) {
1055
+    if (empty($label) && empty($notice)) {
1056 1056
         return;
1057 1057
     }
1058 1058
 
1059 1059
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
1060 1060
 
1061
-    if ( ! empty( $label ) ) {
1062
-        $label = sanitize_text_field( $label );
1061
+    if (!empty($label)) {
1062
+        $label = sanitize_text_field($label);
1063 1063
         echo "<h5>$label</h5>";
1064 1064
     }
1065 1065
 
1066
-    if ( ! empty( $notice ) ) {
1067
-        echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>';
1066
+    if (!empty($notice)) {
1067
+        echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>';
1068 1068
     }
1069 1069
 
1070 1070
     echo '</div>';
1071 1071
 }
1072
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
1072
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
1073 1073
 
1074 1074
 /**
1075 1075
  * @param WPInv_Invoice $invoice
1076 1076
  */
1077
-function wpinv_display_invoice_notes( $invoice ) {
1077
+function wpinv_display_invoice_notes($invoice) {
1078 1078
 
1079 1079
     // Retrieve the notes.
1080
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
1080
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
1081 1081
 
1082 1082
     // Abort if we have non.
1083
-    if ( empty( $notes ) ) {
1083
+    if (empty($notes)) {
1084 1084
         return;
1085 1085
     }
1086 1086
 
1087 1087
     // Echo the note.
1088 1088
     echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">';
1089
-    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>';
1089
+    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>';
1090 1090
     echo '<ul class="getpaid-invoice-notes mt-4 p-0">';
1091 1091
 
1092
-    foreach( $notes as $note ) {
1093
-        wpinv_get_invoice_note_line_item( $note );
1092
+    foreach ($notes as $note) {
1093
+        wpinv_get_invoice_note_line_item($note);
1094 1094
     }
1095 1095
 
1096 1096
     echo '</ul>';
1097 1097
     echo '</div>';
1098 1098
 }
1099
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
1099
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
1100 1100
 
1101 1101
 /**
1102 1102
  * Loads scripts on our invoice templates.
@@ -1104,32 +1104,32 @@  discard block
 block discarded – undo
1104 1104
 function wpinv_display_style() {
1105 1105
 
1106 1106
     // Make sure that all scripts have been loaded.
1107
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
1108
-        do_action( 'wp_enqueue_scripts' );
1107
+    if (!did_action('wp_enqueue_scripts')) {
1108
+        do_action('wp_enqueue_scripts');
1109 1109
     }
1110 1110
 
1111 1111
     // Register the invoices style.
1112
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
1112
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
1113 1113
 
1114 1114
     // Load required styles
1115
-    wp_print_styles( 'open-sans' );
1116
-    wp_print_styles( 'wpinv-single-style' );
1117
-    wp_print_styles( 'ayecode-ui' );
1115
+    wp_print_styles('open-sans');
1116
+    wp_print_styles('wpinv-single-style');
1117
+    wp_print_styles('ayecode-ui');
1118 1118
 
1119 1119
     // Maybe load custom css.
1120
-    $custom_css = wpinv_get_option( 'template_custom_css' );
1120
+    $custom_css = wpinv_get_option('template_custom_css');
1121 1121
 
1122
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
1123
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1124
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1122
+    if (isset($custom_css) && !empty($custom_css)) {
1123
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1124
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1125 1125
         echo '<style type="text/css">';
1126 1126
         echo $custom_css;
1127 1127
         echo '</style>';
1128 1128
     }
1129 1129
 
1130 1130
 }
1131
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1132
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1131
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1132
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1133 1133
 
1134 1134
 
1135 1135
 /**
@@ -1141,41 +1141,41 @@  discard block
 block discarded – undo
1141 1141
     // Retrieve the current invoice.
1142 1142
     $invoice_id = getpaid_get_current_invoice_id();
1143 1143
 
1144
-    if ( empty( $invoice_id ) ) {
1144
+    if (empty($invoice_id)) {
1145 1145
 
1146 1146
         return aui()->alert(
1147 1147
             array(
1148 1148
                 'type'    => 'warning',
1149
-                'content' => __( 'Invalid invoice', 'invoicing' ),
1149
+                'content' => __('Invalid invoice', 'invoicing'),
1150 1150
             )
1151 1151
         );
1152 1152
 
1153 1153
     }
1154 1154
 
1155 1155
     // Can the user view this invoice?
1156
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
1156
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
1157 1157
 
1158 1158
         return aui()->alert(
1159 1159
             array(
1160 1160
                 'type'    => 'warning',
1161
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
1161
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
1162 1162
             )
1163 1163
         );
1164 1164
 
1165 1165
     }
1166 1166
 
1167 1167
     // Ensure that it is not yet paid for.
1168
-    $invoice = new WPInv_Invoice( $invoice_id );
1168
+    $invoice = new WPInv_Invoice($invoice_id);
1169 1169
 
1170 1170
     // Maybe mark it as viewed.
1171
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
1171
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
1172 1172
 
1173
-    if ( $invoice->is_paid() ) {
1173
+    if ($invoice->is_paid()) {
1174 1174
 
1175 1175
         return aui()->alert(
1176 1176
             array(
1177 1177
                 'type'    => 'success',
1178
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
1178
+                'content' => __('This invoice has already been paid.', 'invoicing'),
1179 1179
             )
1180 1180
         );
1181 1181
 
@@ -1185,14 +1185,14 @@  discard block
 block discarded – undo
1185 1185
     $wpi_checkout_id = $invoice_id;
1186 1186
 
1187 1187
     // We'll display this invoice via the default form.
1188
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1188
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1189 1189
 
1190
-    if ( 0 == $form->get_id() ) {
1190
+    if (0 == $form->get_id()) {
1191 1191
 
1192 1192
         return aui()->alert(
1193 1193
             array(
1194 1194
                 'type'    => 'warning',
1195
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1195
+                'content' => __('Error loading the payment form', 'invoicing'),
1196 1196
             )
1197 1197
         );
1198 1198
 
@@ -1200,7 +1200,7 @@  discard block
 block discarded – undo
1200 1200
 
1201 1201
     // Set the invoice.
1202 1202
     $form->invoice = $invoice;
1203
-    $form->set_items( $invoice->get_items() );
1203
+    $form->set_items($invoice->get_items());
1204 1204
 
1205 1205
     // Generate the html.
1206 1206
     return $form->get_html();
@@ -1208,7 +1208,7 @@  discard block
 block discarded – undo
1208 1208
 }
1209 1209
 
1210 1210
 function wpinv_empty_cart_message() {
1211
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1211
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1212 1212
 }
1213 1213
 
1214 1214
 /**
@@ -1225,38 +1225,38 @@  discard block
 block discarded – undo
1225 1225
         )
1226 1226
     );
1227 1227
 }
1228
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1228
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1229 1229
 
1230
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1231
-    $invoice = wpinv_get_invoice( $invoice_id );
1230
+function wpinv_receipt_billing_address($invoice_id = 0) {
1231
+    $invoice = wpinv_get_invoice($invoice_id);
1232 1232
 
1233
-    if ( empty( $invoice ) ) {
1233
+    if (empty($invoice)) {
1234 1234
         return NULL;
1235 1235
     }
1236 1236
 
1237 1237
     $billing_details = $invoice->get_user_info();
1238
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1238
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1239 1239
 
1240 1240
     ob_start();
1241 1241
     ?>
1242 1242
     <table class="table table-bordered table-sm wpi-billing-details">
1243 1243
         <tbody>
1244 1244
             <tr class="wpi-receipt-name">
1245
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1246
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1245
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1246
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1247 1247
             </tr>
1248 1248
             <tr class="wpi-receipt-email">
1249
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1250
-                <td><?php echo $billing_details['email'] ;?></td>
1249
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1250
+                <td><?php echo $billing_details['email']; ?></td>
1251 1251
             </tr>
1252 1252
             <tr class="wpi-receipt-address">
1253
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1254
-                <td><?php echo $address_row ;?></td>
1253
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1254
+                <td><?php echo $address_row; ?></td>
1255 1255
             </tr>
1256
-            <?php if ( $billing_details['phone'] ) { ?>
1256
+            <?php if ($billing_details['phone']) { ?>
1257 1257
             <tr class="wpi-receipt-phone">
1258
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1259
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1258
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1259
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1260 1260
             </tr>
1261 1261
             <?php } ?>
1262 1262
         </tbody>
@@ -1264,7 +1264,7 @@  discard block
 block discarded – undo
1264 1264
     <?php
1265 1265
     $output = ob_get_clean();
1266 1266
     
1267
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1267
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1268 1268
 
1269 1269
     echo $output;
1270 1270
 }
@@ -1272,56 +1272,56 @@  discard block
 block discarded – undo
1272 1272
 /**
1273 1273
  * Filters the receipt page.
1274 1274
  */
1275
-function wpinv_filter_success_page_content( $content ) {
1275
+function wpinv_filter_success_page_content($content) {
1276 1276
 
1277 1277
     // Ensure this is our page.
1278
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1278
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1279 1279
 
1280
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1281
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1280
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1281
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1282 1282
 
1283 1283
     }
1284 1284
 
1285 1285
     return $content;
1286 1286
 }
1287
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1287
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1288 1288
 
1289
-function wpinv_invoice_link( $invoice_id ) {
1290
-    $invoice = wpinv_get_invoice( $invoice_id );
1289
+function wpinv_invoice_link($invoice_id) {
1290
+    $invoice = wpinv_get_invoice($invoice_id);
1291 1291
 
1292
-    if ( empty( $invoice ) ) {
1292
+    if (empty($invoice)) {
1293 1293
         return NULL;
1294 1294
     }
1295 1295
 
1296
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1296
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1297 1297
 
1298
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1298
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1299 1299
 }
1300 1300
 
1301
-function wpinv_invoice_subscription_details( $invoice ) {
1302
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1303
-        $subscription = wpinv_get_subscription( $invoice, true );
1301
+function wpinv_invoice_subscription_details($invoice) {
1302
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1303
+        $subscription = wpinv_get_subscription($invoice, true);
1304 1304
 
1305
-        if ( empty( $subscription ) ) {
1305
+        if (empty($subscription)) {
1306 1306
             return;
1307 1307
         }
1308 1308
 
1309 1309
         $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
1310
-        $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency() ) . ' / ' . $frequency;
1311
-        $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), $invoice->get_currency() );
1310
+        $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), $invoice->get_currency()) . ' / ' . $frequency;
1311
+        $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), $invoice->get_currency());
1312 1312
 
1313 1313
         $payments = $subscription->get_child_payments();
1314 1314
         ?>
1315 1315
         <div class="wpinv-subscriptions-details">
1316
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1316
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1317 1317
             <table class="table">
1318 1318
                 <thead>
1319 1319
                     <tr>
1320
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1321
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1322
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1323
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1324
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1320
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1321
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1322
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1323
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1324
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1325 1325
                     </tr>
1326 1326
                 </thead>
1327 1327
                 <tbody>
@@ -1329,35 +1329,35 @@  discard block
 block discarded – undo
1329 1329
                         <td><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?></td>
1330 1330
                         <td><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?></td>
1331 1331
                         <td><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?></td>
1332
-                        <td class="text-center"><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __( 'Until Cancelled', 'invoicing' ) : $subscription->bill_times); ?></td>
1332
+                        <td class="text-center"><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? __('Until Cancelled', 'invoicing') : $subscription->bill_times); ?></td>
1333 1333
                         <td class="text-center wpi-sub-status"><?php echo $subscription->get_status_label(); ?></td>
1334 1334
                     </tr>
1335 1335
                 </tbody>
1336 1336
             </table>
1337 1337
         </div>
1338
-        <?php if ( !empty( $payments ) ) { ?>
1338
+        <?php if (!empty($payments)) { ?>
1339 1339
         <div class="wpinv-renewal-payments">
1340
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1340
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1341 1341
             <table class="table">
1342 1342
                 <thead>
1343 1343
                     <tr>
1344 1344
                         <th>#</th>
1345
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
1346
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
1347
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
1345
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
1346
+                        <th><?php _e('Date', 'invoicing'); ?></th>
1347
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
1348 1348
                     </tr>
1349 1349
                 </thead>
1350 1350
                 <tbody>
1351 1351
                     <?php
1352 1352
                         $i = 1;
1353
-                        foreach ( $payments as $payment ) {
1353
+                        foreach ($payments as $payment) {
1354 1354
                             $invoice_id = $payment->ID;
1355 1355
                     ?>
1356 1356
                     <tr>
1357
-                        <th scope="row"><?php echo $i;?></th>
1358
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
1357
+                        <th scope="row"><?php echo $i; ?></th>
1358
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
1359 1359
                         <td><?php echo$invoice->get_date_created(); ?></td>
1360
-                        <td class="text-right"><?php echo wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() ); ?></td>
1360
+                        <td class="text-right"><?php echo wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency()); ?></td>
1361 1361
                     </tr>
1362 1362
                     <?php $i++; } ?>
1363 1363
                 </tbody>
@@ -1367,64 +1367,64 @@  discard block
 block discarded – undo
1367 1367
         <?php
1368 1368
     }
1369 1369
 }
1370
-add_action( 'getpaid_invoice_line_items', 'wpinv_invoice_subscription_details', 20 );
1370
+add_action('getpaid_invoice_line_items', 'wpinv_invoice_subscription_details', 20);
1371 1371
 
1372
-function wpinv_cart_total_label( $label, $invoice ) {
1373
-    if ( empty( $invoice ) ) {
1372
+function wpinv_cart_total_label($label, $invoice) {
1373
+    if (empty($invoice)) {
1374 1374
         return $label;
1375 1375
     }
1376 1376
 
1377 1377
     $prefix_label = '';
1378
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
1379
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
1380
-    } else if ( $invoice->is_renewal() ) {
1381
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
1378
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
1379
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
1380
+    } else if ($invoice->is_renewal()) {
1381
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
1382 1382
     }
1383 1383
 
1384
-    if ( $prefix_label != '' ) {
1385
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1384
+    if ($prefix_label != '') {
1385
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
1386 1386
     }
1387 1387
 
1388 1388
     return $label;
1389 1389
 }
1390
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1391
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1392
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
1390
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1391
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1392
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
1393 1393
 
1394
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1395
-    if ( empty( $note ) ) {
1394
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1395
+    if (empty($note)) {
1396 1396
         return NULL;
1397 1397
     }
1398 1398
 
1399
-    if ( is_int( $note ) ) {
1400
-        $note = get_comment( $note );
1399
+    if (is_int($note)) {
1400
+        $note = get_comment($note);
1401 1401
     }
1402 1402
 
1403
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1403
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1404 1404
         return NULL;
1405 1405
     }
1406 1406
 
1407
-    $note_classes   = array( 'note' );
1408
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1407
+    $note_classes   = array('note');
1408
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1409 1409
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1410
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1411
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1410
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1411
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1412 1412
 
1413 1413
     ob_start();
1414 1414
     ?>
1415
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3">
1415
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3">
1416 1416
         <div class="note_content bg-light border position-relative p-4">
1417 1417
 
1418
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
1418
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
1419 1419
 
1420
-            <?php if ( ! is_admin() ) : ?>
1420
+            <?php if (!is_admin()) : ?>
1421 1421
                 <em class="meta position-absolute form-text">
1422 1422
                     <?php
1423 1423
                         printf(
1424
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1424
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1425 1425
                             $note->comment_author,
1426
-                            date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ),
1427
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1426
+                            date_i18n(get_option('date_format'), strtotime($note->comment_date)),
1427
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1428 1428
                         );
1429 1429
                     ?>
1430 1430
                 </em>
@@ -1432,12 +1432,12 @@  discard block
 block discarded – undo
1432 1432
 
1433 1433
         </div>
1434 1434
 
1435
-        <?php if ( is_admin() ) : ?>
1435
+        <?php if (is_admin()) : ?>
1436 1436
 
1437 1437
             <p class="meta px-4 py-2">
1438
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
1439
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1440
-                    <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
1438
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
1439
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1440
+                    <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
1441 1441
                 <?php } ?>
1442 1442
             </p>
1443 1443
 
@@ -1446,9 +1446,9 @@  discard block
 block discarded – undo
1446 1446
     </li>
1447 1447
     <?php
1448 1448
     $note_content = ob_get_clean();
1449
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1449
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1450 1450
 
1451
-    if ( $echo ) {
1451
+    if ($echo) {
1452 1452
         echo $note_content;
1453 1453
     } else {
1454 1454
         return $note_content;
@@ -1458,36 +1458,36 @@  discard block
 block discarded – undo
1458 1458
 function wpinv_invalid_invoice_content() {
1459 1459
     global $post;
1460 1460
 
1461
-    $invoice = wpinv_get_invoice( $post->ID );
1461
+    $invoice = wpinv_get_invoice($post->ID);
1462 1462
 
1463
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
1464
-    if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
1465
-        if ( is_user_logged_in() ) {
1466
-            if ( wpinv_require_login_to_checkout() ) {
1467
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1468
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
1463
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
1464
+    if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
1465
+        if (is_user_logged_in()) {
1466
+            if (wpinv_require_login_to_checkout()) {
1467
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1468
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
1469 1469
                 }
1470 1470
             }
1471 1471
         } else {
1472
-            if ( wpinv_require_login_to_checkout() ) {
1473
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1474
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
1472
+            if (wpinv_require_login_to_checkout()) {
1473
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1474
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
1475 1475
                 }
1476 1476
             }
1477 1477
         }
1478 1478
     } else {
1479
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
1479
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
1480 1480
     }
1481 1481
     ?>
1482 1482
     <div class="row wpinv-row-invalid">
1483 1483
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
1484
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
1484
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
1485 1485
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
1486 1486
         </div>
1487 1487
     </div>
1488 1488
     <?php
1489 1489
 }
1490
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
1490
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
1491 1491
 
1492 1492
 /**
1493 1493
  * Function to get privacy policy text.
@@ -1496,21 +1496,21 @@  discard block
 block discarded – undo
1496 1496
  * @return string
1497 1497
  */
1498 1498
 function wpinv_get_policy_text() {
1499
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1499
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1500 1500
 
1501
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
1501
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
1502 1502
 
1503
-    if(!$privacy_page_id){
1504
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1503
+    if (!$privacy_page_id) {
1504
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1505 1505
     }
1506 1506
 
1507
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
1507
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
1508 1508
 
1509 1509
     $find_replace = array(
1510 1510
         '[wpinv_privacy_policy]' => $privacy_link,
1511 1511
     );
1512 1512
 
1513
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1513
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1514 1514
 
1515 1515
     return wp_kses_post(wpautop($privacy_text));
1516 1516
 }
@@ -1519,25 +1519,25 @@  discard block
 block discarded – undo
1519 1519
 /**
1520 1520
  * Allows the user to set their own price for an invoice item
1521 1521
  */
1522
-function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) {
1522
+function wpinv_checkout_cart_item_name_your_price($cart_item, $key) {
1523 1523
     
1524 1524
     //Ensure we have an item id
1525
-    if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) {
1525
+    if (!is_array($cart_item) || empty($cart_item['id'])) {
1526 1526
         return;
1527 1527
     }
1528 1528
 
1529 1529
     //Fetch the item
1530 1530
     $item_id = $cart_item['id'];
1531
-    $item    = new WPInv_Item( $item_id );
1531
+    $item    = new WPInv_Item($item_id);
1532 1532
     
1533
-    if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) {
1533
+    if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) {
1534 1534
         return;
1535 1535
     }
1536 1536
 
1537 1537
     //Fetch the dynamic pricing "strings"
1538
-    $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) );
1539
-    $minimum_price_text   = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) );
1540
-    $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) );
1538
+    $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing')));
1539
+    $minimum_price_text   = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing')));
1540
+    $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing')));
1541 1541
 
1542 1542
     //Display a "name_your_price" button
1543 1543
     echo " &mdash; <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>";
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
     echo '<div class="name-your-price-miniform">';
1547 1547
     
1548 1548
     //Maybe display the recommended price
1549
-    if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) {
1549
+    if ($item->get_price() > 0 && !empty($suggested_price_text)) {
1550 1550
         $suggested_price = $item->get_the_price();
1551 1551
         echo "<div>$suggested_price_text &mdash; $suggested_price</div>";
1552 1552
     }
@@ -1554,52 +1554,52 @@  discard block
 block discarded – undo
1554 1554
     //Display the update price form
1555 1555
     $symbol         = wpinv_currency_symbol();
1556 1556
     $position       = wpinv_currency_position();
1557
-    $minimum        = esc_attr( $item->get_minimum_price() );
1558
-    $price          = esc_attr( $cart_item['item_price'] );
1559
-    $update         = esc_attr__( "Update", 'invoicing' );
1557
+    $minimum        = esc_attr($item->get_minimum_price());
1558
+    $price          = esc_attr($cart_item['item_price']);
1559
+    $update         = esc_attr__("Update", 'invoicing');
1560 1560
 
1561 1561
     //Ensure it supports dynamic prici
1562
-    if( $price < $minimum ) {
1562
+    if ($price < $minimum) {
1563 1563
         $price = $minimum;
1564 1564
     }
1565 1565
 
1566 1566
     echo '<label>';
1567 1567
     echo $position != 'right' ? $symbol . '&nbsp;' : '';
1568 1568
     echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />";
1569
-    echo $position == 'right' ? '&nbsp;' . $symbol : '' ;
1569
+    echo $position == 'right' ? '&nbsp;' . $symbol : '';
1570 1570
     echo "</label>";
1571 1571
     echo "<input type='hidden' value='$item_id' class='wpi-field-item' />";
1572 1572
     echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>";
1573 1573
 
1574 1574
     //Maybe display the minimum price
1575
-    if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) {
1576
-        $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) );
1575
+    if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) {
1576
+        $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price()));
1577 1577
         echo "<div>$minimum_price_text &mdash; $minimum_price</div>";
1578 1578
     }
1579 1579
 
1580 1580
     echo "</div>";
1581 1581
 
1582 1582
 }
1583
-add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 );
1583
+add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2);
1584 1584
 
1585 1585
 function wpinv_oxygen_fix_conflict() {
1586 1586
     global $ct_ignore_post_types;
1587 1587
 
1588
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1588
+    if (!is_array($ct_ignore_post_types)) {
1589 1589
         $ct_ignore_post_types = array();
1590 1590
     }
1591 1591
 
1592
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
1592
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
1593 1593
 
1594
-    foreach ( $post_types as $post_type ) {
1594
+    foreach ($post_types as $post_type) {
1595 1595
         $ct_ignore_post_types[] = $post_type;
1596 1596
 
1597 1597
         // Ignore post type
1598
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1598
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1599 1599
     }
1600 1600
 
1601
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1602
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1601
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1602
+    add_filter('template_include', 'wpinv_template', 999, 1);
1603 1603
 }
1604 1604
 
1605 1605
 /**
@@ -1607,10 +1607,10 @@  discard block
 block discarded – undo
1607 1607
  * 
1608 1608
  * @param GetPaid_Payment_Form $form
1609 1609
  */
1610
-function getpaid_display_payment_form( $form ) {
1610
+function getpaid_display_payment_form($form) {
1611 1611
 
1612
-    if ( is_numeric( $form ) ) {
1613
-        $form = new GetPaid_Payment_Form( $form );
1612
+    if (is_numeric($form)) {
1613
+        $form = new GetPaid_Payment_Form($form);
1614 1614
     }
1615 1615
 
1616 1616
     $form->display();
@@ -1620,124 +1620,124 @@  discard block
 block discarded – undo
1620 1620
 /**
1621 1621
  * Helper function to display a item payment form on the frontend.
1622 1622
  */
1623
-function getpaid_display_item_payment_form( $items ) {
1623
+function getpaid_display_item_payment_form($items) {
1624 1624
     global $invoicing;
1625 1625
 
1626
-    foreach ( array_keys( $items ) as $id ) {
1627
-	    if ( 'publish' != get_post_status( $id ) ) {
1628
-		    unset( $items[ $id ] );
1626
+    foreach (array_keys($items) as $id) {
1627
+	    if ('publish' != get_post_status($id)) {
1628
+		    unset($items[$id]);
1629 1629
 	    }
1630 1630
     }
1631 1631
 
1632
-    if ( empty( $items ) ) {
1632
+    if (empty($items)) {
1633 1633
 		return aui()->alert(
1634 1634
 			array(
1635 1635
 				'type'    => 'warning',
1636
-				'content' => __( 'No published items found', 'invoicing' ),
1636
+				'content' => __('No published items found', 'invoicing'),
1637 1637
 			)
1638 1638
 		);
1639 1639
     }
1640 1640
 
1641
-    $item_key = getpaid_convert_items_to_string( $items );
1641
+    $item_key = getpaid_convert_items_to_string($items);
1642 1642
 
1643 1643
     // Get the form elements and items.
1644 1644
     $form     = wpinv_get_default_payment_form();
1645
-	$elements = $invoicing->form_elements->get_form_elements( $form );
1646
-	$items    = $invoicing->form_elements->convert_normal_items( $items );
1645
+	$elements = $invoicing->form_elements->get_form_elements($form);
1646
+	$items    = $invoicing->form_elements->convert_normal_items($items);
1647 1647
 
1648 1648
 	ob_start();
1649 1649
 	echo "<form class='wpinv_payment_form'>";
1650
-	do_action( 'wpinv_payment_form_top' );
1650
+	do_action('wpinv_payment_form_top');
1651 1651
     echo "<input type='hidden' name='form_id' value='$form'/>";
1652 1652
     echo "<input type='hidden' name='form_items' value='$item_key'/>";
1653
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1654
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1653
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
1654
+	wp_nonce_field('vat_validation', '_wpi_nonce');
1655 1655
 
1656
-	foreach ( $elements as $element ) {
1657
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1658
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1656
+	foreach ($elements as $element) {
1657
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
1658
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
1659 1659
 	}
1660 1660
 
1661 1661
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1662
-	do_action( 'wpinv_payment_form_bottom' );
1662
+	do_action('wpinv_payment_form_bottom');
1663 1663
 	echo '</form>';
1664 1664
 
1665 1665
 	$content = ob_get_clean();
1666
-	return str_replace( 'sr-only', '', $content );
1666
+	return str_replace('sr-only', '', $content);
1667 1667
 }
1668 1668
 
1669 1669
 /**
1670 1670
  * Helper function to display an invoice payment form on the frontend.
1671 1671
  */
1672
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1672
+function getpaid_display_invoice_payment_form($invoice_id) {
1673 1673
     global $invoicing;
1674 1674
 
1675
-    $invoice = wpinv_get_invoice( $invoice_id );
1675
+    $invoice = wpinv_get_invoice($invoice_id);
1676 1676
 
1677
-    if ( empty( $invoice ) ) {
1677
+    if (empty($invoice)) {
1678 1678
 		return aui()->alert(
1679 1679
 			array(
1680 1680
 				'type'    => 'warning',
1681
-				'content' => __( 'Invoice not found', 'invoicing' ),
1681
+				'content' => __('Invoice not found', 'invoicing'),
1682 1682
 			)
1683 1683
 		);
1684 1684
     }
1685 1685
 
1686
-    if ( $invoice->is_paid() ) {
1686
+    if ($invoice->is_paid()) {
1687 1687
 		return aui()->alert(
1688 1688
 			array(
1689 1689
 				'type'    => 'warning',
1690
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1690
+				'content' => __('Invoice has already been paid', 'invoicing'),
1691 1691
 			)
1692 1692
 		);
1693 1693
     }
1694 1694
 
1695 1695
     // Get the form elements and items.
1696
-    $form     = wpinv_get_default_payment_form();
1697
-	$elements = $invoicing->form_elements->get_form_elements( $form );
1698
-	$items    = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1696
+    $form = wpinv_get_default_payment_form();
1697
+	$elements = $invoicing->form_elements->get_form_elements($form);
1698
+	$items    = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
1699 1699
 
1700 1700
 	ob_start();
1701 1701
 	echo "<form class='wpinv_payment_form'>";
1702
-	do_action( 'wpinv_payment_form_top' );
1702
+	do_action('wpinv_payment_form_top');
1703 1703
     echo "<input type='hidden' name='form_id' value='$form'/>";
1704 1704
     echo "<input type='hidden' name='invoice_id' value='$invoice_id'/>";
1705
-	wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
1706
-	wp_nonce_field( 'vat_validation', '_wpi_nonce' );
1705
+	wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
1706
+	wp_nonce_field('vat_validation', '_wpi_nonce');
1707 1707
 
1708
-	foreach ( $elements as $element ) {
1709
-		do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $form );
1710
-		do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form );
1708
+	foreach ($elements as $element) {
1709
+		do_action('wpinv_frontend_render_payment_form_element', $element, $items, $form);
1710
+		do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $form);
1711 1711
 	}
1712 1712
 
1713 1713
 	echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
1714
-	do_action( 'wpinv_payment_form_bottom' );
1714
+	do_action('wpinv_payment_form_bottom');
1715 1715
 	echo '</form>';
1716 1716
 
1717 1717
 	$content = ob_get_clean();
1718
-	return str_replace( 'sr-only', '', $content );
1718
+	return str_replace('sr-only', '', $content);
1719 1719
 }
1720 1720
 
1721 1721
 /**
1722 1722
  * Helper function to convert item string to array.
1723 1723
  */
1724
-function getpaid_convert_items_to_array( $items ) {
1725
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1724
+function getpaid_convert_items_to_array($items) {
1725
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1726 1726
     $prepared = array();
1727 1727
 
1728
-    foreach ( $items as $item ) {
1729
-        $data = array_map( 'trim', explode( '|', $item ) );
1728
+    foreach ($items as $item) {
1729
+        $data = array_map('trim', explode('|', $item));
1730 1730
 
1731
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1731
+        if (empty($data[0]) || !is_numeric($data[0])) {
1732 1732
             continue;
1733 1733
         }
1734 1734
 
1735 1735
         $quantity = 1;
1736
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1736
+        if (isset($data[1]) && is_numeric($data[1])) {
1737 1737
             $quantity = $data[1];
1738 1738
         }
1739 1739
 
1740
-        $prepared[ $data[0] ] = $quantity;
1740
+        $prepared[$data[0]] = $quantity;
1741 1741
 
1742 1742
     }
1743 1743
 
@@ -1747,13 +1747,13 @@  discard block
 block discarded – undo
1747 1747
 /**
1748 1748
  * Helper function to convert item array to string.
1749 1749
  */
1750
-function getpaid_convert_items_to_string( $items ) {
1750
+function getpaid_convert_items_to_string($items) {
1751 1751
     $prepared = array();
1752 1752
 
1753
-    foreach ( $items as $item => $quantity ) {
1753
+    foreach ($items as $item => $quantity) {
1754 1754
         $prepared[] = "$item|$quantity";
1755 1755
     }
1756
-    return implode( ',', $prepared );
1756
+    return implode(',', $prepared);
1757 1757
 }
1758 1758
 
1759 1759
 /**
@@ -1761,22 +1761,22 @@  discard block
 block discarded – undo
1761 1761
  * 
1762 1762
  * Provide a label and one of $form, $items or $invoice.
1763 1763
  */
1764
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1765
-    $label = sanitize_text_field( $label );
1764
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1765
+    $label = sanitize_text_field($label);
1766 1766
     $nonce = wp_create_nonce('getpaid_ajax_form');
1767 1767
 
1768
-    if ( ! empty( $form ) ) {
1769
-        $form  = esc_attr( $form );
1768
+    if (!empty($form)) {
1769
+        $form = esc_attr($form);
1770 1770
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-form='$form'>$label</button>"; 
1771 1771
     }
1772 1772
 	
1773
-	if ( ! empty( $items ) ) {
1774
-        $items  = esc_attr( $items );
1773
+	if (!empty($items)) {
1774
+        $items = esc_attr($items);
1775 1775
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-item='$items'>$label</button>"; 
1776 1776
     }
1777 1777
     
1778
-    if ( ! empty( $invoice ) ) {
1779
-        $invoice  = esc_attr( $invoice );
1778
+    if (!empty($invoice)) {
1779
+        $invoice = esc_attr($invoice);
1780 1780
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-nonce='$nonce' data-invoice='$invoice'>$label</button>"; 
1781 1781
     }
1782 1782
 
@@ -1787,17 +1787,17 @@  discard block
 block discarded – undo
1787 1787
  *
1788 1788
  * @param WPInv_Invoice $invoice
1789 1789
  */
1790
-function getpaid_the_invoice_description( $invoice ) {
1790
+function getpaid_the_invoice_description($invoice) {
1791 1791
     $description = $invoice->get_description();
1792 1792
 
1793
-    if ( empty( $description ) ) {
1793
+    if (empty($description)) {
1794 1794
         return;
1795 1795
     }
1796 1796
 
1797
-    $description = wp_kses_post( $description );
1797
+    $description = wp_kses_post($description);
1798 1798
     echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>";
1799 1799
 }
1800
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1800
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1801 1801
 
1802 1802
 /**
1803 1803
  * Render element on a form.
@@ -1805,41 +1805,41 @@  discard block
 block discarded – undo
1805 1805
  * @param array $element
1806 1806
  * @param GetPaid_Payment_Form $form
1807 1807
  */
1808
-function getpaid_payment_form_element( $element, $form ) {
1808
+function getpaid_payment_form_element($element, $form) {
1809 1809
 
1810 1810
     // Set up the args.
1811
-    $element_type    = trim( $element['type'] );
1811
+    $element_type    = trim($element['type']);
1812 1812
     $element['form'] = $form;
1813
-    extract( $element );
1813
+    extract($element);
1814 1814
 
1815 1815
     // Try to locate the appropriate template.
1816
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1816
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1817 1817
     
1818 1818
     // Abort if this is not our element.
1819
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1819
+    if (empty($located) || !file_exists($located)) {
1820 1820
         return;
1821 1821
     }
1822 1822
 
1823 1823
     // Generate the class and id of the element.
1824
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1825
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1824
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1825
+    $id            = isset($id) ? $id : uniqid('gp');
1826 1826
 
1827 1827
     // Echo the opening wrapper.
1828 1828
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
1829 1829
 
1830 1830
     // Fires before displaying a given element type's content.
1831
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1831
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1832 1832
 
1833 1833
     // Include the template for the element.
1834 1834
     include $located;
1835 1835
 
1836 1836
     // Fires after displaying a given element type's content.
1837
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1837
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1838 1838
 
1839 1839
     // Echo the closing wrapper.
1840 1840
     echo '</div>';
1841 1841
 }
1842
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1842
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1843 1843
 
1844 1844
 /**
1845 1845
  * Shows a list of gateways that support recurring payments.
@@ -1847,17 +1847,17 @@  discard block
 block discarded – undo
1847 1847
 function wpinv_get_recurring_gateways_text() {
1848 1848
     $gateways = array();
1849 1849
 
1850
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1851
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1852
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1850
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1851
+        if (wpinv_gateway_support_subscription($key)) {
1852
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1853 1853
         }
1854 1854
     }
1855 1855
 
1856
-    if ( empty( $gateways ) ) {
1857
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>";
1856
+    if (empty($gateways)) {
1857
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>";
1858 1858
     }
1859 1859
 
1860
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>";
1860
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>";
1861 1861
 
1862 1862
 }
1863 1863
 
@@ -1867,5 +1867,5 @@  discard block
 block discarded – undo
1867 1867
  * @return GetPaid_Template
1868 1868
  */
1869 1869
 function getpaid_template() {
1870
-    return getpaid()->get( 'template' );
1870
+    return getpaid()->get('template');
1871 1871
 }
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -7,86 +7,86 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool) apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double) $amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92 92
 /**
@@ -95,32 +95,32 @@  discard block
 block discarded – undo
95 95
  * @since 1.0.19
96 96
  * @return array
97 97
  */
98
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
98
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
99 99
 	$invoice_statuses = array(
100
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
101
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
102
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
103
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
104
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
105
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
106
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
107
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
100
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
101
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
102
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
103
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
104
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
105
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
106
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
107
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
108 108
     );
109 109
 
110
-    if ( $draft ) {
111
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
110
+    if ($draft) {
111
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
112 112
     }
113 113
 
114
-    if ( $trashed ) {
115
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
114
+    if ($trashed) {
115
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
116 116
     }
117 117
 
118
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
118
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
119 119
 }
120 120
 
121
-function wpinv_status_nicename( $status ) {
122
-    $statuses = wpinv_get_invoice_statuses( true, true );
123
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
121
+function wpinv_status_nicename($status) {
122
+    $statuses = wpinv_get_invoice_statuses(true, true);
123
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
124 124
 
125 125
     return $status;
126 126
 }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
  * Retrieves the default currency code.
130 130
  */
131 131
 function wpinv_get_currency() {
132
-    return apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
132
+    return apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
133 133
 }
134 134
 
135 135
 /**
@@ -137,61 +137,61 @@  discard block
 block discarded – undo
137 137
  * 
138 138
  * @param string|null $currency The currency code. Defaults to the default currency.
139 139
  */
140
-function wpinv_currency_symbol( $currency = null ) {
140
+function wpinv_currency_symbol($currency = null) {
141 141
 
142 142
     // Prepare the currency.
143
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
143
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
144 144
 
145 145
     // Fetch all symbols.
146 146
     $symbols = wpinv_get_currency_symbols();
147 147
 
148 148
     // Fetch this currencies symbol.
149
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
149
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
150 150
 
151 151
     // Filter the symbol.
152
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
152
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
153 153
 }
154 154
 
155 155
 function wpinv_currency_position() {
156
-    $position = wpinv_get_option( 'currency_position', 'left' );
156
+    $position = wpinv_get_option('currency_position', 'left');
157 157
     
158
-    return apply_filters( 'wpinv_currency_position', $position );
158
+    return apply_filters('wpinv_currency_position', $position);
159 159
 }
160 160
 
161 161
 function wpinv_thousands_separator() {
162
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
162
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
163 163
     
164
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
164
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
165 165
 }
166 166
 
167 167
 function wpinv_decimal_separator() {
168
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
168
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
169 169
     
170
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
170
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
171 171
 }
172 172
 
173 173
 function wpinv_decimals() {
174
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
174
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
175 175
     
176
-    return absint( $decimals );
176
+    return absint($decimals);
177 177
 }
178 178
 
179 179
 /**
180 180
  * Retrieves a list of all supported currencies.
181 181
  */
182 182
 function wpinv_get_currencies() {
183
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
183
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
184 184
 }
185 185
 
186 186
 /**
187 187
  * Retrieves a list of all currency symbols.
188 188
  */
189 189
 function wpinv_get_currency_symbols() {
190
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
190
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
191 191
 }
192 192
 
193
-function wpinv_price( $amount = '', $currency = '' ) {
194
-    if( empty( $currency ) ) {
193
+function wpinv_price($amount = '', $currency = '') {
194
+    if (empty($currency)) {
195 195
         $currency = wpinv_get_currency();
196 196
     }
197 197
 
@@ -199,14 +199,14 @@  discard block
 block discarded – undo
199 199
 
200 200
     $negative = $amount < 0;
201 201
 
202
-    if ( $negative ) {
203
-        $amount = substr( $amount, 1 );
202
+    if ($negative) {
203
+        $amount = substr($amount, 1);
204 204
     }
205 205
 
206
-    $symbol = wpinv_currency_symbol( $currency );
206
+    $symbol = wpinv_currency_symbol($currency);
207 207
 
208
-    if ( $position == 'left' || $position == 'left_space' ) {
209
-        switch ( $currency ) {
208
+    if ($position == 'left' || $position == 'left_space') {
209
+        switch ($currency) {
210 210
             case "GBP" :
211 211
             case "BRL" :
212 212
             case "EUR" :
@@ -218,15 +218,15 @@  discard block
 block discarded – undo
218 218
             case "NZD" :
219 219
             case "SGD" :
220 220
             case "JPY" :
221
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
221
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
222 222
                 break;
223 223
             default :
224 224
                 //$price = $currency . ' ' . $amount;
225
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
225
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
226 226
                 break;
227 227
         }
228 228
     } else {
229
-        switch ( $currency ) {
229
+        switch ($currency) {
230 230
             case "GBP" :
231 231
             case "BRL" :
232 232
             case "EUR" :
@@ -237,83 +237,83 @@  discard block
 block discarded – undo
237 237
             case "MXN" :
238 238
             case "SGD" :
239 239
             case "JPY" :
240
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
240
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
241 241
                 break;
242 242
             default :
243 243
                 //$price = $amount . ' ' . $currency;
244
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
244
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
245 245
                 break;
246 246
         }
247 247
     }
248 248
     
249
-    if ( $negative ) {
249
+    if ($negative) {
250 250
         $price = '-' . $price;
251 251
     }
252 252
     
253
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
253
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
254 254
 
255 255
     return $price;
256 256
 }
257 257
 
258
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
258
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
259 259
     $thousands_sep = wpinv_thousands_separator();
260 260
     $decimal_sep   = wpinv_decimal_separator();
261 261
 
262
-    if ( $decimals === NULL ) {
262
+    if ($decimals === NULL) {
263 263
         $decimals = wpinv_decimals();
264 264
     }
265 265
 
266
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
267
-        $whole = substr( $amount, 0, $sep_found );
268
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
266
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
267
+        $whole = substr($amount, 0, $sep_found);
268
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
269 269
         $amount = $whole . '.' . $part;
270 270
     }
271 271
 
272
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
273
-        $amount = str_replace( ',', '', $amount );
272
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
273
+        $amount = str_replace(',', '', $amount);
274 274
     }
275 275
 
276
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
277
-        $amount = str_replace( ' ', '', $amount );
276
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
277
+        $amount = str_replace(' ', '', $amount);
278 278
     }
279 279
 
280
-    if ( empty( $amount ) ) {
280
+    if (empty($amount)) {
281 281
         $amount = 0;
282 282
     }
283 283
     
284
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
285
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
284
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
285
+    $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep);
286 286
     
287
-    if ( $calculate ) {
288
-        if ( $thousands_sep === "," ) {
289
-            $formatted = str_replace( ",", "", $formatted );
287
+    if ($calculate) {
288
+        if ($thousands_sep === ",") {
289
+            $formatted = str_replace(",", "", $formatted);
290 290
         }
291 291
         
292
-        if ( $decimal_sep === "," ) {
293
-            $formatted = str_replace( ",", ".", $formatted );
292
+        if ($decimal_sep === ",") {
293
+            $formatted = str_replace(",", ".", $formatted);
294 294
         }
295 295
     }
296 296
 
297
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
297
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
298 298
 }
299
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
299
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
300 300
 
301
-function wpinv_sanitize_key( $key ) {
301
+function wpinv_sanitize_key($key) {
302 302
     $raw_key = $key;
303
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
303
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
304 304
 
305
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
305
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
306 306
 }
307 307
 
308
-function wpinv_get_file_extension( $str ) {
309
-    $parts = explode( '.', $str );
310
-    return end( $parts );
308
+function wpinv_get_file_extension($str) {
309
+    $parts = explode('.', $str);
310
+    return end($parts);
311 311
 }
312 312
 
313
-function wpinv_string_is_image_url( $str ) {
314
-    $ext = wpinv_get_file_extension( $str );
313
+function wpinv_string_is_image_url($str) {
314
+    $ext = wpinv_get_file_extension($str);
315 315
 
316
-    switch ( strtolower( $ext ) ) {
316
+    switch (strtolower($ext)) {
317 317
         case 'jpeg';
318 318
         case 'jpg';
319 319
             $return = true;
@@ -329,33 +329,33 @@  discard block
 block discarded – undo
329 329
             break;
330 330
     }
331 331
 
332
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
332
+    return (bool) apply_filters('wpinv_string_is_image', $return, $str);
333 333
 }
334 334
 
335
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
336
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
335
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
336
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
337 337
     
338
-    if ( true === $should_log ) {
338
+    if (true === $should_log) {
339 339
         $label = '';
340
-        if ( $file && $file !== '' ) {
341
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
340
+        if ($file && $file !== '') {
341
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
342 342
         }
343 343
         
344
-        if ( $title && $title !== '' ) {
344
+        if ($title && $title !== '') {
345 345
             $label = $label !== '' ? $label . ' ' : '';
346 346
             $label .= $title . ' ';
347 347
         }
348 348
         
349
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
349
+        $label = $label !== '' ? trim($label) . ' : ' : '';
350 350
         
351
-        if ( is_array( $log ) || is_object( $log ) ) {
352
-            error_log( $label . print_r( $log, true ) );
351
+        if (is_array($log) || is_object($log)) {
352
+            error_log($label . print_r($log, true));
353 353
         } else {
354
-            error_log( $label . $log );
354
+            error_log($label . $log);
355 355
         }
356 356
 
357
-        error_log( wp_debug_backtrace_summary() );
358
-        if ( $exit ) {
357
+        error_log(wp_debug_backtrace_summary());
358
+        if ($exit) {
359 359
             exit;
360 360
         }
361 361
     }
@@ -363,32 +363,32 @@  discard block
 block discarded – undo
363 363
 
364 364
 function wpinv_is_ajax_disabled() {
365 365
     $retval = false;
366
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
366
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
367 367
 }
368 368
 
369
-function wpinv_get_current_page_url( $nocache = false ) {
369
+function wpinv_get_current_page_url($nocache = false) {
370 370
     global $wp;
371 371
 
372
-    if ( get_option( 'permalink_structure' ) ) {
373
-        $base = trailingslashit( home_url( $wp->request ) );
372
+    if (get_option('permalink_structure')) {
373
+        $base = trailingslashit(home_url($wp->request));
374 374
     } else {
375
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
376
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
375
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
376
+        $base = remove_query_arg(array('post_type', 'name'), $base);
377 377
     }
378 378
 
379 379
     $scheme = is_ssl() ? 'https' : 'http';
380
-    $uri    = set_url_scheme( $base, $scheme );
380
+    $uri    = set_url_scheme($base, $scheme);
381 381
 
382
-    if ( is_front_page() ) {
383
-        $uri = home_url( '/' );
384
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
382
+    if (is_front_page()) {
383
+        $uri = home_url('/');
384
+    } elseif (wpinv_is_checkout(array(), false)) {
385 385
         $uri = wpinv_get_checkout_uri();
386 386
     }
387 387
 
388
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
388
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
389 389
 
390
-    if ( $nocache ) {
391
-        $uri = wpinv_add_cache_busting( $uri );
390
+    if ($nocache) {
391
+        $uri = wpinv_add_cache_busting($uri);
392 392
     }
393 393
 
394 394
     return $uri;
@@ -401,46 +401,46 @@  discard block
 block discarded – undo
401 401
  * @param string $name  Constant name.
402 402
  * @param mixed  $value Value.
403 403
  */
404
-function getpaid_maybe_define_constant( $name, $value ) {
405
-	if ( ! defined( $name ) ) {
406
-		define( $name, $value );
404
+function getpaid_maybe_define_constant($name, $value) {
405
+	if (!defined($name)) {
406
+		define($name, $value);
407 407
 	}
408 408
 }
409 409
 
410 410
 function wpinv_get_php_arg_separator_output() {
411
-	return ini_get( 'arg_separator.output' );
411
+	return ini_get('arg_separator.output');
412 412
 }
413 413
 
414
-function wpinv_rgb_from_hex( $color ) {
415
-    $color = str_replace( '#', '', $color );
414
+function wpinv_rgb_from_hex($color) {
415
+    $color = str_replace('#', '', $color);
416 416
 
417 417
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
418
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
419
-    if ( empty( $color ) ) {
418
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
419
+    if (empty($color)) {
420 420
         return NULL;
421 421
     }
422 422
 
423
-    $color = str_split( $color );
423
+    $color = str_split($color);
424 424
 
425 425
     $rgb      = array();
426
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
427
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
428
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
426
+    $rgb['R'] = hexdec($color[0] . $color[1]);
427
+    $rgb['G'] = hexdec($color[2] . $color[3]);
428
+    $rgb['B'] = hexdec($color[4] . $color[5]);
429 429
 
430 430
     return $rgb;
431 431
 }
432 432
 
433
-function wpinv_hex_darker( $color, $factor = 30 ) {
434
-    $base  = wpinv_rgb_from_hex( $color );
433
+function wpinv_hex_darker($color, $factor = 30) {
434
+    $base  = wpinv_rgb_from_hex($color);
435 435
     $color = '#';
436 436
 
437
-    foreach ( $base as $k => $v ) {
437
+    foreach ($base as $k => $v) {
438 438
         $amount      = $v / 100;
439
-        $amount      = round( $amount * $factor );
439
+        $amount      = round($amount * $factor);
440 440
         $new_decimal = $v - $amount;
441 441
 
442
-        $new_hex_component = dechex( $new_decimal );
443
-        if ( strlen( $new_hex_component ) < 2 ) {
442
+        $new_hex_component = dechex($new_decimal);
443
+        if (strlen($new_hex_component) < 2) {
444 444
             $new_hex_component = "0" . $new_hex_component;
445 445
         }
446 446
         $color .= $new_hex_component;
@@ -449,18 +449,18 @@  discard block
 block discarded – undo
449 449
     return $color;
450 450
 }
451 451
 
452
-function wpinv_hex_lighter( $color, $factor = 30 ) {
453
-    $base  = wpinv_rgb_from_hex( $color );
452
+function wpinv_hex_lighter($color, $factor = 30) {
453
+    $base  = wpinv_rgb_from_hex($color);
454 454
     $color = '#';
455 455
 
456
-    foreach ( $base as $k => $v ) {
456
+    foreach ($base as $k => $v) {
457 457
         $amount      = 255 - $v;
458 458
         $amount      = $amount / 100;
459
-        $amount      = round( $amount * $factor );
459
+        $amount      = round($amount * $factor);
460 460
         $new_decimal = $v + $amount;
461 461
 
462
-        $new_hex_component = dechex( $new_decimal );
463
-        if ( strlen( $new_hex_component ) < 2 ) {
462
+        $new_hex_component = dechex($new_decimal);
463
+        if (strlen($new_hex_component) < 2) {
464 464
             $new_hex_component = "0" . $new_hex_component;
465 465
         }
466 466
         $color .= $new_hex_component;
@@ -469,22 +469,22 @@  discard block
 block discarded – undo
469 469
     return $color;
470 470
 }
471 471
 
472
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
473
-    $hex = str_replace( '#', '', $color );
472
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
473
+    $hex = str_replace('#', '', $color);
474 474
 
475
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
476
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
477
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
475
+    $c_r = hexdec(substr($hex, 0, 2));
476
+    $c_g = hexdec(substr($hex, 2, 2));
477
+    $c_b = hexdec(substr($hex, 4, 2));
478 478
 
479
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
479
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
480 480
 
481 481
     return $brightness > 155 ? $dark : $light;
482 482
 }
483 483
 
484
-function wpinv_format_hex( $hex ) {
485
-    $hex = trim( str_replace( '#', '', $hex ) );
484
+function wpinv_format_hex($hex) {
485
+    $hex = trim(str_replace('#', '', $hex));
486 486
 
487
-    if ( strlen( $hex ) == 3 ) {
487
+    if (strlen($hex) == 3) {
488 488
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
489 489
     }
490 490
 
@@ -504,12 +504,12 @@  discard block
 block discarded – undo
504 504
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
505 505
  * @return string
506 506
  */
507
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
508
-    if ( function_exists( 'mb_strimwidth' ) ) {
509
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
507
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
508
+    if (function_exists('mb_strimwidth')) {
509
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
510 510
     }
511 511
     
512
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
512
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
513 513
 }
514 514
 
515 515
 /**
@@ -521,28 +521,28 @@  discard block
 block discarded – undo
521 521
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
522 522
  * @return int Returns the number of characters in string.
523 523
  */
524
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
525
-    if ( function_exists( 'mb_strlen' ) ) {
526
-        return mb_strlen( $str, $encoding );
524
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
525
+    if (function_exists('mb_strlen')) {
526
+        return mb_strlen($str, $encoding);
527 527
     }
528 528
         
529
-    return strlen( $str );
529
+    return strlen($str);
530 530
 }
531 531
 
532
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
533
-    if ( function_exists( 'mb_strtolower' ) ) {
534
-        return mb_strtolower( $str, $encoding );
532
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
533
+    if (function_exists('mb_strtolower')) {
534
+        return mb_strtolower($str, $encoding);
535 535
     }
536 536
     
537
-    return strtolower( $str );
537
+    return strtolower($str);
538 538
 }
539 539
 
540
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
541
-    if ( function_exists( 'mb_strtoupper' ) ) {
542
-        return mb_strtoupper( $str, $encoding );
540
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
541
+    if (function_exists('mb_strtoupper')) {
542
+        return mb_strtoupper($str, $encoding);
543 543
     }
544 544
     
545
-    return strtoupper( $str );
545
+    return strtoupper($str);
546 546
 }
547 547
 
548 548
 /**
@@ -556,12 +556,12 @@  discard block
 block discarded – undo
556 556
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
557 557
  * @return int Returns the position of the first occurrence of search in the string.
558 558
  */
559
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
560
-    if ( function_exists( 'mb_strpos' ) ) {
561
-        return mb_strpos( $str, $find, $offset, $encoding );
559
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
560
+    if (function_exists('mb_strpos')) {
561
+        return mb_strpos($str, $find, $offset, $encoding);
562 562
     }
563 563
         
564
-    return strpos( $str, $find, $offset );
564
+    return strpos($str, $find, $offset);
565 565
 }
566 566
 
567 567
 /**
@@ -575,12 +575,12 @@  discard block
 block discarded – undo
575 575
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
576 576
  * @return int Returns the position of the last occurrence of search.
577 577
  */
578
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
579
-    if ( function_exists( 'mb_strrpos' ) ) {
580
-        return mb_strrpos( $str, $find, $offset, $encoding );
578
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
579
+    if (function_exists('mb_strrpos')) {
580
+        return mb_strrpos($str, $find, $offset, $encoding);
581 581
     }
582 582
         
583
-    return strrpos( $str, $find, $offset );
583
+    return strrpos($str, $find, $offset);
584 584
 }
585 585
 
586 586
 /**
@@ -595,16 +595,16 @@  discard block
 block discarded – undo
595 595
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
596 596
  * @return string
597 597
  */
598
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
599
-    if ( function_exists( 'mb_substr' ) ) {
600
-        if ( $length === null ) {
601
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
598
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
599
+    if (function_exists('mb_substr')) {
600
+        if ($length === null) {
601
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
602 602
         } else {
603
-            return mb_substr( $str, $start, $length, $encoding );
603
+            return mb_substr($str, $start, $length, $encoding);
604 604
         }
605 605
     }
606 606
         
607
-    return substr( $str, $start, $length );
607
+    return substr($str, $start, $length);
608 608
 }
609 609
 
610 610
 /**
@@ -616,48 +616,48 @@  discard block
 block discarded – undo
616 616
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
617 617
  * @return string The width of string.
618 618
  */
619
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
620
-    if ( function_exists( 'mb_strwidth' ) ) {
621
-        return mb_strwidth( $str, $encoding );
619
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
620
+    if (function_exists('mb_strwidth')) {
621
+        return mb_strwidth($str, $encoding);
622 622
     }
623 623
     
624
-    return wpinv_utf8_strlen( $str, $encoding );
624
+    return wpinv_utf8_strlen($str, $encoding);
625 625
 }
626 626
 
627
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
628
-    if ( function_exists( 'mb_strlen' ) ) {
629
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
627
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
628
+    if (function_exists('mb_strlen')) {
629
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
630 630
         $str_end = "";
631 631
         
632
-        if ( $lower_str_end ) {
633
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
632
+        if ($lower_str_end) {
633
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
634 634
         } else {
635
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
635
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
636 636
         }
637 637
 
638 638
         return $first_letter . $str_end;
639 639
     }
640 640
     
641
-    return ucfirst( $str );
641
+    return ucfirst($str);
642 642
 }
643 643
 
644
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
645
-    if ( function_exists( 'mb_convert_case' ) ) {
646
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
644
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
645
+    if (function_exists('mb_convert_case')) {
646
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
647 647
     }
648 648
     
649
-    return ucwords( $str );
649
+    return ucwords($str);
650 650
 }
651 651
 
652
-function wpinv_period_in_days( $period, $unit ) {
653
-    $period = absint( $period );
652
+function wpinv_period_in_days($period, $unit) {
653
+    $period = absint($period);
654 654
     
655
-    if ( $period > 0 ) {
656
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
655
+    if ($period > 0) {
656
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
657 657
             $period = $period * 7;
658
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
658
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
659 659
             $period = $period * 30;
660
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
660
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
661 661
             $period = $period * 365;
662 662
         }
663 663
     }
@@ -665,14 +665,14 @@  discard block
 block discarded – undo
665 665
     return $period;
666 666
 }
667 667
 
668
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
669
-    if ( function_exists( 'cal_days_in_month' ) ) {
670
-        return cal_days_in_month( $calendar, $month, $year );
668
+function wpinv_cal_days_in_month($calendar, $month, $year) {
669
+    if (function_exists('cal_days_in_month')) {
670
+        return cal_days_in_month($calendar, $month, $year);
671 671
     }
672 672
 
673 673
     // Fallback in case the calendar extension is not loaded in PHP
674 674
     // Only supports Gregorian calendar
675
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
675
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
676 676
 }
677 677
 
678 678
 /**
@@ -683,11 +683,11 @@  discard block
 block discarded – undo
683 683
  *
684 684
  * @return string
685 685
  */
686
-function wpi_help_tip( $tip, $allow_html = false ) {
687
-    if ( $allow_html ) {
688
-        $tip = wpi_sanitize_tooltip( $tip );
686
+function wpi_help_tip($tip, $allow_html = false) {
687
+    if ($allow_html) {
688
+        $tip = wpi_sanitize_tooltip($tip);
689 689
     } else {
690
-        $tip = esc_attr( $tip );
690
+        $tip = esc_attr($tip);
691 691
     }
692 692
 
693 693
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
  * @param string $var
702 702
  * @return string
703 703
  */
704
-function wpi_sanitize_tooltip( $var ) {
705
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
704
+function wpi_sanitize_tooltip($var) {
705
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
706 706
         'br'     => array(),
707 707
         'em'     => array(),
708 708
         'strong' => array(),
@@ -712,7 +712,7 @@  discard block
 block discarded – undo
712 712
         'li'     => array(),
713 713
         'ol'     => array(),
714 714
         'p'      => array(),
715
-    ) ) );
715
+    )));
716 716
 }
717 717
 
718 718
 /**
@@ -722,7 +722,7 @@  discard block
 block discarded – undo
722 722
  */
723 723
 function wpinv_get_screen_ids() {
724 724
 
725
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
725
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
726 726
 
727 727
     $screen_ids = array(
728 728
         'toplevel_page_' . $screen_id,
@@ -740,7 +740,7 @@  discard block
 block discarded – undo
740 740
         'invoicing_page_wpi-addons',
741 741
     );
742 742
 
743
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
743
+    return apply_filters('wpinv_screen_ids', $screen_ids);
744 744
 }
745 745
 
746 746
 /**
@@ -751,14 +751,14 @@  discard block
 block discarded – undo
751 751
  * @param array|string $list List of values.
752 752
  * @return array Sanitized array of values.
753 753
  */
754
-function wpinv_parse_list( $list ) {
754
+function wpinv_parse_list($list) {
755 755
 
756
-    if ( empty( $list ) ) {
756
+    if (empty($list)) {
757 757
         $list = array();
758 758
     }
759 759
 
760
-	if ( ! is_array( $list ) ) {
761
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
760
+	if (!is_array($list)) {
761
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
762 762
 	}
763 763
 
764 764
 	return $list;
@@ -772,16 +772,16 @@  discard block
 block discarded – undo
772 772
  * @param string $key Type of data to fetch.
773 773
  * @return mixed Fetched data.
774 774
  */
775
-function wpinv_get_data( $key ) {
775
+function wpinv_get_data($key) {
776 776
 
777 777
     // Try fetching it from the cache.
778
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
779
-    if( $data ) {
778
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
779
+    if ($data) {
780 780
         return $data;
781 781
     }
782 782
 
783
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
784
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
783
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
784
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
785 785
 
786 786
 	return $data;
787 787
 }
@@ -795,10 +795,10 @@  discard block
 block discarded – undo
795 795
  * @param bool $first_empty Whether or not the first item in the list should be empty
796 796
  * @return mixed Fetched data.
797 797
  */
798
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
798
+function wpinv_maybe_add_empty_option($options, $first_empty) {
799 799
 
800
-    if ( ! empty( $options ) && $first_empty ) {
801
-        return array_merge( array( '' => '' ), $options );
800
+    if (!empty($options) && $first_empty) {
801
+        return array_merge(array('' => ''), $options);
802 802
     }
803 803
     return $options;
804 804
 
@@ -810,21 +810,21 @@  discard block
 block discarded – undo
810 810
  * @param mixed $var Data to sanitize.
811 811
  * @return string|array
812 812
  */
813
-function wpinv_clean( $var ) {
813
+function wpinv_clean($var) {
814 814
 
815
-	if ( is_array( $var ) ) {
816
-		return array_map( 'wpinv_clean', $var );
815
+	if (is_array($var)) {
816
+		return array_map('wpinv_clean', $var);
817 817
     }
818 818
 
819
-    if ( is_object( $var ) ) {
820
-		$object_vars = get_object_vars( $var );
821
-		foreach ( $object_vars as $property_name => $property_value ) {
822
-			$var->$property_name = wpinv_clean( $property_value );
819
+    if (is_object($var)) {
820
+		$object_vars = get_object_vars($var);
821
+		foreach ($object_vars as $property_name => $property_value) {
822
+			$var->$property_name = wpinv_clean($property_value);
823 823
         }
824 824
         return $var;
825 825
 	}
826 826
     
827
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
827
+    return is_string($var) ? sanitize_text_field($var) : $var;
828 828
 }
829 829
 
830 830
 /**
@@ -833,43 +833,43 @@  discard block
 block discarded – undo
833 833
  * @param string $str Data to convert.
834 834
  * @return string|array
835 835
  */
836
-function getpaid_convert_price_string_to_options( $str ) {
836
+function getpaid_convert_price_string_to_options($str) {
837 837
 
838
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
839
-    $options     = array();
838
+	$raw_options = array_map('trim', explode(',', $str));
839
+    $options = array();
840 840
 
841
-    foreach ( $raw_options as $option ) {
841
+    foreach ($raw_options as $option) {
842 842
 
843
-        if ( '' == $option ) {
843
+        if ('' == $option) {
844 844
             continue;
845 845
         }
846 846
 
847
-        $option = array_map( 'trim', explode( '|', $option ) );
847
+        $option = array_map('trim', explode('|', $option));
848 848
 
849 849
         $price = null;
850 850
         $label = null;
851 851
 
852
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
853
-            $label  = $option[0];
852
+        if (isset($option[0]) && '' != $option[0]) {
853
+            $label = $option[0];
854 854
         }
855 855
 
856
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
856
+        if (isset($option[1]) && '' != $option[1]) {
857 857
             $price = $option[1];
858 858
         }
859 859
 
860
-        if ( ! isset( $price ) ) {
860
+        if (!isset($price)) {
861 861
             $price = $label;
862 862
         }
863 863
 
864
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
864
+        if (!isset($price) || !is_numeric($price)) {
865 865
             continue;
866 866
         }
867 867
 
868
-        if ( ! isset( $label ) ) {
868
+        if (!isset($label)) {
869 869
             $label = $price;
870 870
         }
871 871
 
872
-        $options[ $price ] = $label;
872
+        $options[$price] = $label;
873 873
     }
874 874
 
875 875
     return $options;
@@ -878,23 +878,23 @@  discard block
 block discarded – undo
878 878
 /**
879 879
  * Returns the help tip.
880 880
  */
881
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
882
-    $additional_classes = sanitize_html_class( $additional_classes );
883
-    $tip                = esc_attr__( $tip );
881
+function getpaid_get_help_tip($tip, $additional_classes = '') {
882
+    $additional_classes = sanitize_html_class($additional_classes);
883
+    $tip                = esc_attr__($tip);
884 884
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
885 885
 }
886 886
 
887 887
 /**
888 888
  * Formats a date
889 889
  */
890
-function getpaid_format_date( $date ) {
890
+function getpaid_format_date($date) {
891 891
 
892
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
892
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
893 893
         return '';
894 894
     }
895 895
 
896 896
 
897
-    return date_i18n( get_option( 'date_format' ), strtotime( $date ) );
897
+    return date_i18n(get_option('date_format'), strtotime($date));
898 898
 
899 899
 }
900 900
 
@@ -905,16 +905,16 @@  discard block
 block discarded – undo
905 905
  * @param  integer $limit Limit size in characters.
906 906
  * @return string
907 907
  */
908
-function getpaid_limit_length( $string, $limit ) {
908
+function getpaid_limit_length($string, $limit) {
909 909
     $str_limit = $limit - 3;
910 910
 
911
-	if ( function_exists( 'mb_strimwidth' ) ) {
912
-		if ( mb_strlen( $string ) > $limit ) {
913
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
911
+	if (function_exists('mb_strimwidth')) {
912
+		if (mb_strlen($string) > $limit) {
913
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
914 914
 		}
915 915
 	} else {
916
-		if ( strlen( $string ) > $limit ) {
917
-			$string = substr( $string, 0, $str_limit ) . '...';
916
+		if (strlen($string) > $limit) {
917
+			$string = substr($string, 0, $str_limit) . '...';
918 918
 		}
919 919
 	}
920 920
     return $string;
@@ -928,7 +928,7 @@  discard block
 block discarded – undo
928 928
  * @since 1.0.19
929 929
  */
930 930
 function getpaid_api() {
931
-    return getpaid()->get( 'api' );
931
+    return getpaid()->get('api');
932 932
 }
933 933
 
934 934
 /**
@@ -938,7 +938,7 @@  discard block
 block discarded – undo
938 938
  * @since 1.0.19
939 939
  */
940 940
 function getpaid_post_types() {
941
-    return getpaid()->get( 'post_types' );
941
+    return getpaid()->get('post_types');
942 942
 }
943 943
 
944 944
 /**
@@ -948,7 +948,7 @@  discard block
 block discarded – undo
948 948
  * @since 1.0.19
949 949
  */
950 950
 function getpaid_session() {
951
-    return getpaid()->get( 'session' );
951
+    return getpaid()->get('session');
952 952
 }
953 953
 
954 954
 /**
@@ -958,5 +958,5 @@  discard block
 block discarded – undo
958 958
  * @since 1.0.19
959 959
  */
960 960
 function getpaid_notes() {
961
-    return getpaid()->get( 'notes' );
961
+    return getpaid()->get('notes');
962 962
 }
Please login to merge, or discard this patch.
includes/class-getpaid-template.php 2 patches
Indentation   +91 added lines, -91 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -20,23 +20,23 @@  discard block
 block discarded – undo
20 20
     public $templates_url;
21 21
 
22 22
     /**
23
-	 * Class constructor.
24
-	 *
25
-	 * @since 1.0.19
26
-	 */
27
-	public function __construct() {
23
+     * Class constructor.
24
+     *
25
+     * @since 1.0.19
26
+     */
27
+    public function __construct() {
28 28
 
29 29
         $this->templates_dir = apply_filters( 'getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates' );
30 30
         $this->templates_url = apply_filters( 'getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates' );
31 31
     }
32 32
 
33 33
     /**
34
-	 * Checks if this is a preview page
35
-	 *
36
-	 * @since 1.0.19
37
-	 * @return bool
38
-	 */
39
-	public function is_preview() {
34
+     * Checks if this is a preview page
35
+     *
36
+     * @since 1.0.19
37
+     * @return bool
38
+     */
39
+    public function is_preview() {
40 40
         return 
41 41
             $this->is_divi_preview() ||
42 42
             $this->is_elementor_preview() ||
@@ -48,73 +48,73 @@  discard block
 block discarded – undo
48 48
     }
49 49
 
50 50
     /**
51
-	 * Checks if this is an elementor preview page
52
-	 *
53
-	 * @since 1.0.19
54
-	 * @return bool
55
-	 */
56
-	public function is_elementor_preview() {
57
-		return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' );
58
-	}
59
-
60
-	/**
61
-	 * Checks if this is a DIVI preview page
62
-	 *
63
-	 * @since 1.0.19
64
-	 * @return bool
65
-	 */
66
-	public function is_divi_preview() {
67
-		return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' );
68
-	}
69
-
70
-	/**
71
-	 * Checks if this is a beaver builder preview page
72
-	 *
73
-	 * @since 1.0.19
74
-	 * @return bool
75
-	 */
76
-	public function is_beaver_preview() {
77
-		return isset( $_REQUEST['fl_builder'] );
78
-	}
79
-
80
-	/**
81
-	 * Checks if this is a siteorigin builder preview page
82
-	 *
83
-	 * @since 1.0.19
84
-	 * @return bool
85
-	 */
86
-	public function is_siteorigin_preview() {
87
-		return ! empty( $_REQUEST['siteorigin_panels_live_editor'] );
88
-	}
89
-
90
-	/**
91
-	 * Checks if this is a cornerstone builder preview page
92
-	 *
93
-	 * @since 1.0.19
94
-	 * @return bool
95
-	 */
96
-	public function is_cornerstone_preview() {
97
-		return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint';
98
-	}
99
-
100
-	/**
101
-	 * Checks if this is a fusion builder preview page
102
-	 *
103
-	 * @since 1.0.19
104
-	 * @return bool
105
-	 */
106
-	public function is_fusion_preview() {
107
-		return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] );
108
-	}
109
-
110
-	/**
111
-	 * Checks if this is an oxygen builder preview page
112
-	 *
113
-	 * @since 1.0.19
114
-	 * @return bool
115
-	 */
116
-	public function is_oxygen_preview() {
117
-		return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) );
51
+     * Checks if this is an elementor preview page
52
+     *
53
+     * @since 1.0.19
54
+     * @return bool
55
+     */
56
+    public function is_elementor_preview() {
57
+        return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' );
58
+    }
59
+
60
+    /**
61
+     * Checks if this is a DIVI preview page
62
+     *
63
+     * @since 1.0.19
64
+     * @return bool
65
+     */
66
+    public function is_divi_preview() {
67
+        return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' );
68
+    }
69
+
70
+    /**
71
+     * Checks if this is a beaver builder preview page
72
+     *
73
+     * @since 1.0.19
74
+     * @return bool
75
+     */
76
+    public function is_beaver_preview() {
77
+        return isset( $_REQUEST['fl_builder'] );
78
+    }
79
+
80
+    /**
81
+     * Checks if this is a siteorigin builder preview page
82
+     *
83
+     * @since 1.0.19
84
+     * @return bool
85
+     */
86
+    public function is_siteorigin_preview() {
87
+        return ! empty( $_REQUEST['siteorigin_panels_live_editor'] );
88
+    }
89
+
90
+    /**
91
+     * Checks if this is a cornerstone builder preview page
92
+     *
93
+     * @since 1.0.19
94
+     * @return bool
95
+     */
96
+    public function is_cornerstone_preview() {
97
+        return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint';
98
+    }
99
+
100
+    /**
101
+     * Checks if this is a fusion builder preview page
102
+     *
103
+     * @since 1.0.19
104
+     * @return bool
105
+     */
106
+    public function is_fusion_preview() {
107
+        return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] );
108
+    }
109
+
110
+    /**
111
+     * Checks if this is an oxygen builder preview page
112
+     *
113
+     * @since 1.0.19
114
+     * @return bool
115
+     */
116
+    public function is_oxygen_preview() {
117
+        return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) );
118 118
     }
119 119
 
120 120
     /**
@@ -124,13 +124,13 @@  discard block
 block discarded – undo
124 124
      * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
125 125
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
126 126
      */
127
-	public function locate_template( $template_name, $template_path = '', $default_path = '' ) {
127
+    public function locate_template( $template_name, $template_path = '', $default_path = '' ) {
128 128
 
129 129
         // Load the defaults for the template path and default path.
130 130
         $template_path = empty( $template_path ) ? 'invoicing' : $template_path;
131 131
         $default_path  = empty( $default_path ) ? $this->templates_dir : $default_path;
132 132
 
133
-         // Is it overidden?
133
+            // Is it overidden?
134 134
         $template = locate_template(
135 135
             array( trailingslashit( $template_path ) . $template_name ),
136 136
             array( 'wpinv-' . $template_name )
@@ -145,22 +145,22 @@  discard block
 block discarded – undo
145 145
     }
146 146
     
147 147
     /**
148
-	 * Loads a template
149
-	 *
150
-	 * @since 1.0.19
151
-	 * @return bool
152
-	 */
153
-	protected function load_template( $template_name, $template_path, $args ) {
148
+     * Loads a template
149
+     *
150
+     * @since 1.0.19
151
+     * @return bool
152
+     */
153
+    protected function load_template( $template_name, $template_path, $args ) {
154 154
 
155 155
         if ( is_array( $args ) ){
156 156
             extract( $args );
157 157
         }
158 158
 
159 159
         // Fires before loading a template.
160
-	    do_action( 'wpinv_before_template_part', $template_name, $template_path, $args );
160
+        do_action( 'wpinv_before_template_part', $template_name, $template_path, $args );
161 161
 
162 162
         // Load the template.
163
-	    include( $template_path );
163
+        include( $template_path );
164 164
 
165 165
         // Fires after loading a template.
166 166
         do_action( 'wpinv_after_template_part', $template_name, $template_path, $args );
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
178 178
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
179 179
      */
180
-	public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
180
+    public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
181 181
 
182 182
         // Locate the template.
183 183
         $located = wpinv_locate_template( $template_name, $template_path, $default_path );
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
      * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
203 203
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
204 204
      */
205
-	public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
205
+    public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
206 206
         ob_start();
207 207
         $this->display_template( $template_name, $args, $template_path, $default_path );
208 208
         return ob_get_clean();
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 	 */
27 27
 	public function __construct() {
28 28
 
29
-        $this->templates_dir = apply_filters( 'getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates' );
30
-        $this->templates_url = apply_filters( 'getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates' );
29
+        $this->templates_dir = apply_filters('getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates');
30
+        $this->templates_url = apply_filters('getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates');
31 31
     }
32 32
 
33 33
     /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @return bool
55 55
 	 */
56 56
 	public function is_elementor_preview() {
57
-		return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' );
57
+		return isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax');
58 58
 	}
59 59
 
60 60
 	/**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return bool
65 65
 	 */
66 66
 	public function is_divi_preview() {
67
-		return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' );
67
+		return isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'et_pb');
68 68
 	}
69 69
 
70 70
 	/**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 * @return bool
75 75
 	 */
76 76
 	public function is_beaver_preview() {
77
-		return isset( $_REQUEST['fl_builder'] );
77
+		return isset($_REQUEST['fl_builder']);
78 78
 	}
79 79
 
80 80
 	/**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @return bool
85 85
 	 */
86 86
 	public function is_siteorigin_preview() {
87
-		return ! empty( $_REQUEST['siteorigin_panels_live_editor'] );
87
+		return !empty($_REQUEST['siteorigin_panels_live_editor']);
88 88
 	}
89 89
 
90 90
 	/**
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @return bool
95 95
 	 */
96 96
 	public function is_cornerstone_preview() {
97
-		return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint';
97
+		return !empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint';
98 98
 	}
99 99
 
100 100
 	/**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @return bool
105 105
 	 */
106 106
 	public function is_fusion_preview() {
107
-		return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] );
107
+		return !empty($_REQUEST['fb-edit']) || !empty($_REQUEST['fusion_load_nonce']);
108 108
 	}
109 109
 
110 110
 	/**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @return bool
115 115
 	 */
116 116
 	public function is_oxygen_preview() {
117
-		return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) );
117
+		return !empty($_REQUEST['ct_builder']) || (!empty($_REQUEST['action']) && (substr($_REQUEST['action'], 0, 11) === "oxy_render_" || substr($_REQUEST['action'], 0, 10) === "ct_render_"));
118 118
     }
119 119
 
120 120
     /**
@@ -124,24 +124,24 @@  discard block
 block discarded – undo
124 124
      * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
125 125
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
126 126
      */
127
-	public function locate_template( $template_name, $template_path = '', $default_path = '' ) {
127
+	public function locate_template($template_name, $template_path = '', $default_path = '') {
128 128
 
129 129
         // Load the defaults for the template path and default path.
130
-        $template_path = empty( $template_path ) ? 'invoicing' : $template_path;
131
-        $default_path  = empty( $default_path ) ? $this->templates_dir : $default_path;
130
+        $template_path = empty($template_path) ? 'invoicing' : $template_path;
131
+        $default_path  = empty($default_path) ? $this->templates_dir : $default_path;
132 132
 
133 133
          // Is it overidden?
134 134
         $template = locate_template(
135
-            array( trailingslashit( $template_path ) . $template_name ),
136
-            array( 'wpinv-' . $template_name )
135
+            array(trailingslashit($template_path) . $template_name),
136
+            array('wpinv-' . $template_name)
137 137
         );
138 138
 
139 139
         // If not, load the default template.
140
-        if ( empty( $template ) ) {
141
-            $template = trailingslashit( $default_path ) . $template_name;
140
+        if (empty($template)) {
141
+            $template = trailingslashit($default_path) . $template_name;
142 142
         }
143 143
 
144
-        return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path, $default_path );
144
+        return apply_filters('wpinv_locate_template', $template, $template_name, $template_path, $default_path);
145 145
     }
146 146
     
147 147
     /**
@@ -150,20 +150,20 @@  discard block
 block discarded – undo
150 150
 	 * @since 1.0.19
151 151
 	 * @return bool
152 152
 	 */
153
-	protected function load_template( $template_name, $template_path, $args ) {
153
+	protected function load_template($template_name, $template_path, $args) {
154 154
 
155
-        if ( is_array( $args ) ){
156
-            extract( $args );
155
+        if (is_array($args)) {
156
+            extract($args);
157 157
         }
158 158
 
159 159
         // Fires before loading a template.
160
-	    do_action( 'wpinv_before_template_part', $template_name, $template_path, $args );
160
+	    do_action('wpinv_before_template_part', $template_name, $template_path, $args);
161 161
 
162 162
         // Load the template.
163
-	    include( $template_path );
163
+	    include($template_path);
164 164
 
165 165
         // Fires after loading a template.
166
-        do_action( 'wpinv_after_template_part', $template_name, $template_path, $args );
166
+        do_action('wpinv_after_template_part', $template_name, $template_path, $args);
167 167
 
168 168
     }
169 169
 
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
      * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
178 178
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
179 179
      */
180
-	public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
180
+	public function display_template($template_name, $args = array(), $template_path = '', $default_path = '') {
181 181
 
182 182
         // Locate the template.
183
-        $located = wpinv_locate_template( $template_name, $template_path, $default_path );
183
+        $located = wpinv_locate_template($template_name, $template_path, $default_path);
184 184
 
185 185
         // Abort if the file does not exist.
186
-        if ( ! file_exists( $located ) ) {
187
-            getpaid_doing_it_wrong( __CLASS__ . '::' .__METHOD__, sprintf( '<code>%s</code> does not exist.', $located ), '1.0.19' );
186
+        if (!file_exists($located)) {
187
+            getpaid_doing_it_wrong(__CLASS__ . '::' . __METHOD__, sprintf('<code>%s</code> does not exist.', $located), '1.0.19');
188 188
             return;
189 189
         }
190 190
 
191
-        $this->load_template( $template_name, $located, $args );
191
+        $this->load_template($template_name, $located, $args);
192 192
 
193 193
     }
194 194
     
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
      * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
203 203
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
204 204
      */
205
-	public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
205
+	public function get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
206 206
         ob_start();
207
-        $this->display_template( $template_name, $args, $template_path, $default_path );
207
+        $this->display_template($template_name, $args, $template_path, $default_path);
208 208
         return ob_get_clean();
209 209
     }
210 210
 
Please login to merge, or discard this patch.