Passed
Push — master ( 1f7e58...831686 )
by Brian
09:30 queued 04:44
created
includes/class-wpinv-ajax.php 1 patch
Spacing   +295 added lines, -295 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -78,39 +78,39 @@  discard block
 block discarded – undo
78 78
             'buy_items' => true,
79 79
         );
80 80
 
81
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
82
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
81
+        foreach ($ajax_events as $ajax_event => $nopriv) {
82
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
83 83
             
84
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
85
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
84
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
85
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
86 86
             }
87 87
 
88
-            if ( $nopriv ) {
89
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
88
+            if ($nopriv) {
89
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
90 90
 
91
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
91
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
92 92
             }
93 93
         }
94 94
     }
95 95
     
96 96
     public static function add_note() {
97
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
97
+        check_ajax_referer('add-invoice-note', '_nonce');
98 98
 
99
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
99
+        if (!wpinv_current_user_can_manage_invoicing()) {
100 100
             die(-1);
101 101
         }
102 102
 
103
-        $post_id   = absint( $_POST['post_id'] );
104
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
105
-        $note_type = sanitize_text_field( $_POST['note_type'] );
103
+        $post_id   = absint($_POST['post_id']);
104
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
105
+        $note_type = sanitize_text_field($_POST['note_type']);
106 106
 
107 107
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
108 108
 
109
-        if ( $post_id > 0 ) {
110
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
109
+        if ($post_id > 0) {
110
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
111 111
 
112
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
113
-                wpinv_get_invoice_note_line_item( $note_id );
112
+            if ($note_id > 0 && !is_wp_error($note_id)) {
113
+                wpinv_get_invoice_note_line_item($note_id);
114 114
             }
115 115
         }
116 116
 
@@ -118,16 +118,16 @@  discard block
 block discarded – undo
118 118
     }
119 119
 
120 120
     public static function delete_note() {
121
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
121
+        check_ajax_referer('delete-invoice-note', '_nonce');
122 122
 
123
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
123
+        if (!wpinv_current_user_can_manage_invoicing()) {
124 124
             die(-1);
125 125
         }
126 126
 
127
-        $note_id = (int)$_POST['note_id'];
127
+        $note_id = (int) $_POST['note_id'];
128 128
 
129
-        if ( $note_id > 0 ) {
130
-            wp_delete_comment( $note_id, true );
129
+        if ($note_id > 0) {
130
+            wp_delete_comment($note_id, true);
131 131
         }
132 132
 
133 133
         die();
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
     }
141 141
     
142 142
     public static function checkout() {
143
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
144
-            define( 'WPINV_CHECKOUT', true );
143
+        if (!defined('WPINV_CHECKOUT')) {
144
+            define('WPINV_CHECKOUT', true);
145 145
         }
146 146
 
147 147
         wpinv_process_checkout();
@@ -150,53 +150,53 @@  discard block
 block discarded – undo
150 150
     
151 151
     public static function add_invoice_item() {
152 152
         global $wpi_userID, $wpinv_ip_address_country;
153
-        check_ajax_referer( 'invoice-item', '_nonce' );
154
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
153
+        check_ajax_referer('invoice-item', '_nonce');
154
+        if (!wpinv_current_user_can_manage_invoicing()) {
155 155
             die(-1);
156 156
         }
157 157
         
158
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
159
-        $invoice_id = absint( $_POST['invoice_id'] );
158
+        $item_id    = sanitize_text_field($_POST['item_id']);
159
+        $invoice_id = absint($_POST['invoice_id']);
160 160
         
161
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
161
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
162 162
             die();
163 163
         }
164 164
         
165
-        $invoice    = wpinv_get_invoice( $invoice_id );
166
-        if ( empty( $invoice ) ) {
165
+        $invoice = wpinv_get_invoice($invoice_id);
166
+        if (empty($invoice)) {
167 167
             die();
168 168
         }
169 169
         
170
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
170
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
171 171
             die(); // Don't allow modify items for paid invoice.
172 172
         }
173 173
         
174
-        if ( !empty( $_POST['user_id'] ) ) {
175
-            $wpi_userID = absint( $_POST['user_id'] ); 
174
+        if (!empty($_POST['user_id'])) {
175
+            $wpi_userID = absint($_POST['user_id']); 
176 176
         }
177 177
 
178
-        $item = new WPInv_Item( $item_id );
179
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
178
+        $item = new WPInv_Item($item_id);
179
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
180 180
             die();
181 181
         }
182 182
         
183 183
         // Validate item before adding to invoice because recurring item must be paid individually.
184
-        if ( !empty( $invoice->cart_details ) ) {
184
+        if (!empty($invoice->cart_details)) {
185 185
             $valid = true;
186 186
             
187
-            if ( $recurring_item = $invoice->get_recurring() ) {
188
-                if ( $recurring_item != $item_id ) {
187
+            if ($recurring_item = $invoice->get_recurring()) {
188
+                if ($recurring_item != $item_id) {
189 189
                     $valid = false;
190 190
                 }
191
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
191
+            } else if (wpinv_is_recurring_item($item_id)) {
192 192
                 $valid = false;
193 193
             }
194 194
             
195
-            if ( !$valid ) {
195
+            if (!$valid) {
196 196
                 $response               = array();
197 197
                 $response['success']    = false;
198
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
199
-                wp_send_json( $response );
198
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
199
+                wp_send_json($response);
200 200
             }
201 201
         }
202 202
         
@@ -204,11 +204,11 @@  discard block
 block discarded – undo
204 204
         
205 205
         $data                   = array();
206 206
         $data['invoice_id']     = $invoice_id;
207
-        $data['cart_discounts'] = $invoice->get_discounts( true );
207
+        $data['cart_discounts'] = $invoice->get_discounts(true);
208 208
         
209
-        wpinv_set_checkout_session( $data );
209
+        wpinv_set_checkout_session($data);
210 210
         
211
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
211
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
212 212
 
213 213
         $args = array(
214 214
             'id'            => $item_id,
@@ -221,21 +221,21 @@  discard block
 block discarded – undo
221 221
             'fees'          => array()
222 222
         );
223 223
 
224
-        $invoice->add_item( $item_id, $args );
224
+        $invoice->add_item($item_id, $args);
225 225
         $invoice->save();
226 226
         
227
-        if ( empty( $_POST['country'] ) ) {
227
+        if (empty($_POST['country'])) {
228 228
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
229 229
         }
230
-        if ( empty( $_POST['state'] ) ) {
230
+        if (empty($_POST['state'])) {
231 231
             $_POST['state'] = $invoice->state;
232 232
         }
233 233
          
234
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
235
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
234
+        $invoice->country   = sanitize_text_field($_POST['country']);
235
+        $invoice->state     = sanitize_text_field($_POST['state']);
236 236
         
237
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
238
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
237
+        $invoice->set('country', sanitize_text_field($_POST['country']));
238
+        $invoice->set('state', sanitize_text_field($_POST['state']));
239 239
         
240 240
         $wpinv_ip_address_country = $invoice->country;
241 241
 
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
         
244 244
         $response                       = array();
245 245
         $response['success']            = true;
246
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
246
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
247 247
         $response['data']['subtotal']   = $invoice->get_subtotal();
248 248
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
249 249
         $response['data']['tax']        = $invoice->get_tax();
@@ -255,41 +255,41 @@  discard block
 block discarded – undo
255 255
         
256 256
         wpinv_set_checkout_session($checkout_session);
257 257
         
258
-        wp_send_json( $response );
258
+        wp_send_json($response);
259 259
     }
260 260
 
261 261
 
262 262
     public static function remove_invoice_item() {
263 263
         global $wpi_userID, $wpinv_ip_address_country;
264 264
         
265
-        check_ajax_referer( 'invoice-item', '_nonce' );
266
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
265
+        check_ajax_referer('invoice-item', '_nonce');
266
+        if (!wpinv_current_user_can_manage_invoicing()) {
267 267
             die(-1);
268 268
         }
269 269
         
270
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
271
-        $invoice_id = absint( $_POST['invoice_id'] );
272
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
270
+        $item_id    = sanitize_text_field($_POST['item_id']);
271
+        $invoice_id = absint($_POST['invoice_id']);
272
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
273 273
         
274
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
274
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
275 275
             die();
276 276
         }
277 277
 
278
-        $invoice    = wpinv_get_invoice( $invoice_id );
279
-        if ( empty( $invoice ) ) {
278
+        $invoice = wpinv_get_invoice($invoice_id);
279
+        if (empty($invoice)) {
280 280
             die();
281 281
         }
282 282
         
283
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
283
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
284 284
             die(); // Don't allow modify items for paid invoice.
285 285
         }
286 286
         
287
-        if ( !empty( $_POST['user_id'] ) ) {
288
-            $wpi_userID = absint( $_POST['user_id'] ); 
287
+        if (!empty($_POST['user_id'])) {
288
+            $wpi_userID = absint($_POST['user_id']); 
289 289
         }
290 290
 
291
-        $item       = new WPInv_Item( $item_id );
292
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
291
+        $item = new WPInv_Item($item_id);
292
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
293 293
             die();
294 294
         }
295 295
         
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
         
298 298
         $data                   = array();
299 299
         $data['invoice_id']     = $invoice_id;
300
-        $data['cart_discounts'] = $invoice->get_discounts( true );
300
+        $data['cart_discounts'] = $invoice->get_discounts(true);
301 301
         
302
-        wpinv_set_checkout_session( $data );
302
+        wpinv_set_checkout_session($data);
303 303
 
304 304
         $args = array(
305 305
             'id'         => $item_id,
@@ -307,21 +307,21 @@  discard block
 block discarded – undo
307 307
             'cart_index' => $cart_index
308 308
         );
309 309
 
310
-        $invoice->remove_item( $item_id, $args );
310
+        $invoice->remove_item($item_id, $args);
311 311
         $invoice->save();
312 312
         
313
-        if ( empty( $_POST['country'] ) ) {
313
+        if (empty($_POST['country'])) {
314 314
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
315 315
         }
316
-        if ( empty( $_POST['state'] ) ) {
316
+        if (empty($_POST['state'])) {
317 317
             $_POST['state'] = $invoice->state;
318 318
         }
319 319
          
320
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
321
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
320
+        $invoice->country   = sanitize_text_field($_POST['country']);
321
+        $invoice->state     = sanitize_text_field($_POST['state']);
322 322
         
323
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
324
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
323
+        $invoice->set('country', sanitize_text_field($_POST['country']));
324
+        $invoice->set('state', sanitize_text_field($_POST['state']));
325 325
         
326 326
         $wpinv_ip_address_country = $invoice->country;
327 327
         
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
         
330 330
         $response                       = array();
331 331
         $response['success']            = true;
332
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
332
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
333 333
         $response['data']['subtotal']   = $invoice->get_subtotal();
334 334
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
335 335
         $response['data']['tax']        = $invoice->get_tax();
@@ -341,55 +341,55 @@  discard block
 block discarded – undo
341 341
         
342 342
         wpinv_set_checkout_session($checkout_session);
343 343
         
344
-        wp_send_json( $response );
344
+        wp_send_json($response);
345 345
     }
346 346
     
347 347
     public static function create_invoice_item() {
348
-        check_ajax_referer( 'invoice-item', '_nonce' );
349
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
348
+        check_ajax_referer('invoice-item', '_nonce');
349
+        if (!wpinv_current_user_can_manage_invoicing()) {
350 350
             die(-1);
351 351
         }
352 352
         
353
-        $invoice_id = absint( $_POST['invoice_id'] );
353
+        $invoice_id = absint($_POST['invoice_id']);
354 354
 
355 355
         // Find the item
356
-        if ( !is_numeric( $invoice_id ) ) {
356
+        if (!is_numeric($invoice_id)) {
357 357
             die();
358 358
         }        
359 359
         
360
-        $invoice     = wpinv_get_invoice( $invoice_id );
361
-        if ( empty( $invoice ) ) {
360
+        $invoice = wpinv_get_invoice($invoice_id);
361
+        if (empty($invoice)) {
362 362
             die();
363 363
         }
364 364
         
365 365
         // Validate item before adding to invoice because recurring item must be paid individually.
366
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
366
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
367 367
             $response               = array();
368 368
             $response['success']    = false;
369
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
370
-            wp_send_json( $response );
369
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
370
+            wp_send_json($response);
371 371
         }        
372 372
         
373
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
373
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
374 374
         
375 375
         $meta               = array();
376 376
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
377
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
377
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
378 378
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
379 379
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
380 380
         
381 381
         $data                   = array();
382 382
         $data['post_title']     = sanitize_text_field($save_item['name']);
383 383
         $data['post_status']    = 'publish';
384
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
384
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
385 385
         $data['meta']           = $meta;
386 386
         
387 387
         $item = new WPInv_Item();
388
-        $item->create( $data );
388
+        $item->create($data);
389 389
         
390
-        if ( !empty( $item ) ) {
390
+        if (!empty($item)) {
391 391
             $_POST['item_id']   = $item->ID;
392
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
392
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
393 393
             
394 394
             self::add_invoice_item();
395 395
         }
@@ -397,15 +397,15 @@  discard block
 block discarded – undo
397 397
     }
398 398
     
399 399
     public static function get_billing_details() {
400
-        check_ajax_referer( 'get-billing-details', '_nonce' );
400
+        check_ajax_referer('get-billing-details', '_nonce');
401 401
         
402
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
402
+        if (!wpinv_current_user_can_manage_invoicing()) {
403 403
             die(-1);
404 404
         }
405 405
 
406
-        $user_id            = (int)$_POST['user_id'];
406
+        $user_id            = (int) $_POST['user_id'];
407 407
         $billing_details    = wpinv_get_user_address($user_id);
408
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
408
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
409 409
         
410 410
         if (isset($billing_details['user_id'])) {
411 411
             unset($billing_details['user_id']);
@@ -419,20 +419,20 @@  discard block
 block discarded – undo
419 419
         $response['success']                    = true;
420 420
         $response['data']['billing_details']    = $billing_details;
421 421
         
422
-        wp_send_json( $response );
422
+        wp_send_json($response);
423 423
     }
424 424
     
425 425
     public static function admin_recalculate_totals() {
426 426
         global $wpi_userID, $wpinv_ip_address_country;
427 427
         
428
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
429
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
428
+        check_ajax_referer('wpinv-nonce', '_nonce');
429
+        if (!wpinv_current_user_can_manage_invoicing()) {
430 430
             die(-1);
431 431
         }
432 432
         
433
-        $invoice_id = absint( $_POST['invoice_id'] );        
434
-        $invoice    = wpinv_get_invoice( $invoice_id );
435
-        if ( empty( $invoice ) ) {
433
+        $invoice_id = absint($_POST['invoice_id']);        
434
+        $invoice    = wpinv_get_invoice($invoice_id);
435
+        if (empty($invoice)) {
436 436
             die();
437 437
         }
438 438
         
@@ -440,23 +440,23 @@  discard block
 block discarded – undo
440 440
         
441 441
         $data                   = array();
442 442
         $data['invoice_id']     = $invoice_id;
443
-        $data['cart_discounts'] = $invoice->get_discounts( true );
443
+        $data['cart_discounts'] = $invoice->get_discounts(true);
444 444
         
445
-        wpinv_set_checkout_session( $data );
445
+        wpinv_set_checkout_session($data);
446 446
         
447
-        if ( !empty( $_POST['user_id'] ) ) {
448
-            $wpi_userID = absint( $_POST['user_id'] ); 
447
+        if (!empty($_POST['user_id'])) {
448
+            $wpi_userID = absint($_POST['user_id']); 
449 449
         }
450 450
         
451
-        if ( empty( $_POST['country'] ) ) {
451
+        if (empty($_POST['country'])) {
452 452
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
453 453
         }
454 454
             
455
-        $invoice->country = sanitize_text_field( $_POST['country'] );
456
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
457
-        if ( isset( $_POST['state'] ) ) {
458
-            $invoice->state = sanitize_text_field( $_POST['state'] );
459
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
455
+        $invoice->country = sanitize_text_field($_POST['country']);
456
+        $invoice->set('country', sanitize_text_field($_POST['country']));
457
+        if (isset($_POST['state'])) {
458
+            $invoice->state = sanitize_text_field($_POST['state']);
459
+            $invoice->set('state', sanitize_text_field($_POST['state']));
460 460
         }
461 461
         
462 462
         $wpinv_ip_address_country = $invoice->country;
@@ -465,7 +465,7 @@  discard block
 block discarded – undo
465 465
         
466 466
         $response                       = array();
467 467
         $response['success']            = true;
468
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
468
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
469 469
         $response['data']['subtotal']   = $invoice->get_subtotal();
470 470
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
471 471
         $response['data']['tax']        = $invoice->get_tax();
@@ -477,25 +477,25 @@  discard block
 block discarded – undo
477 477
         
478 478
         wpinv_set_checkout_session($checkout_session);
479 479
         
480
-        wp_send_json( $response );
480
+        wp_send_json($response);
481 481
     }
482 482
     
483 483
     public static function admin_apply_discount() {
484 484
         global $wpi_userID;
485 485
         
486
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
487
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
486
+        check_ajax_referer('wpinv-nonce', '_nonce');
487
+        if (!wpinv_current_user_can_manage_invoicing()) {
488 488
             die(-1);
489 489
         }
490 490
         
491
-        $invoice_id = absint( $_POST['invoice_id'] );
492
-        $discount_code = sanitize_text_field( $_POST['code'] );
493
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
491
+        $invoice_id = absint($_POST['invoice_id']);
492
+        $discount_code = sanitize_text_field($_POST['code']);
493
+        if (empty($invoice_id) || empty($discount_code)) {
494 494
             die();
495 495
         }
496 496
         
497
-        $invoice = wpinv_get_invoice( $invoice_id );
498
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
497
+        $invoice = wpinv_get_invoice($invoice_id);
498
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
499 499
             die();
500 500
         }
501 501
         
@@ -503,49 +503,49 @@  discard block
 block discarded – undo
503 503
         
504 504
         $data                   = array();
505 505
         $data['invoice_id']     = $invoice_id;
506
-        $data['cart_discounts'] = $invoice->get_discounts( true );
506
+        $data['cart_discounts'] = $invoice->get_discounts(true);
507 507
         
508
-        wpinv_set_checkout_session( $data );
508
+        wpinv_set_checkout_session($data);
509 509
         
510 510
         $response               = array();
511 511
         $response['success']    = false;
512
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
512
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
513 513
         $response['data']['code'] = $discount_code;
514 514
         
515
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
516
-            $discounts = wpinv_set_cart_discount( $discount_code );
515
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
516
+            $discounts = wpinv_set_cart_discount($discount_code);
517 517
             
518 518
             $response['success'] = true;
519
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
520
-        }  else {
519
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
520
+        } else {
521 521
             $errors = wpinv_get_errors();
522
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
522
+            if (!empty($errors['wpinv-discount-error'])) {
523 523
                 $response['msg'] = $errors['wpinv-discount-error'];
524 524
             }
525
-            wpinv_unset_error( 'wpinv-discount-error' );
525
+            wpinv_unset_error('wpinv-discount-error');
526 526
         }
527 527
         
528 528
         wpinv_set_checkout_session($checkout_session);
529 529
         
530
-        wp_send_json( $response );
530
+        wp_send_json($response);
531 531
     }
532 532
     
533 533
     public static function admin_remove_discount() {
534 534
         global $wpi_userID;
535 535
         
536
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
537
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
536
+        check_ajax_referer('wpinv-nonce', '_nonce');
537
+        if (!wpinv_current_user_can_manage_invoicing()) {
538 538
             die(-1);
539 539
         }
540 540
         
541
-        $invoice_id = absint( $_POST['invoice_id'] );
542
-        $discount_code = sanitize_text_field( $_POST['code'] );
543
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
541
+        $invoice_id = absint($_POST['invoice_id']);
542
+        $discount_code = sanitize_text_field($_POST['code']);
543
+        if (empty($invoice_id) || empty($discount_code)) {
544 544
             die();
545 545
         }
546 546
         
547
-        $invoice = wpinv_get_invoice( $invoice_id );
548
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
547
+        $invoice = wpinv_get_invoice($invoice_id);
548
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
549 549
             die();
550 550
         }
551 551
         
@@ -553,38 +553,38 @@  discard block
 block discarded – undo
553 553
         
554 554
         $data                   = array();
555 555
         $data['invoice_id']     = $invoice_id;
556
-        $data['cart_discounts'] = $invoice->get_discounts( true );
556
+        $data['cart_discounts'] = $invoice->get_discounts(true);
557 557
         
558
-        wpinv_set_checkout_session( $data );
558
+        wpinv_set_checkout_session($data);
559 559
         
560 560
         $response               = array();
561 561
         $response['success']    = false;
562 562
         $response['msg']        = NULL;
563 563
         
564
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
564
+        $discounts = wpinv_unset_cart_discount($discount_code);
565 565
         $response['success'] = true;
566
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
566
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
567 567
         
568 568
         wpinv_set_checkout_session($checkout_session);
569 569
         
570
-        wp_send_json( $response );
570
+        wp_send_json($response);
571 571
     }
572 572
     
573 573
     public static function check_email() {
574
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
575
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
574
+        check_ajax_referer('wpinv-nonce', '_nonce');
575
+        if (!wpinv_current_user_can_manage_invoicing()) {
576 576
             die(-1);
577 577
         }
578 578
         
579
-        $email = sanitize_text_field( $_POST['email'] );
579
+        $email = sanitize_text_field($_POST['email']);
580 580
         
581 581
         $response = array();
582
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
582
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
583 583
             $user_id            = $user_data->ID;
584 584
             $user_login         = $user_data->user_login;
585 585
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
586 586
             $billing_details    = wpinv_get_user_address($user_id);
587
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
587
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
588 588
             
589 589
             if (isset($billing_details['user_id'])) {
590 590
                 unset($billing_details['user_id']);
@@ -600,54 +600,54 @@  discard block
 block discarded – undo
600 600
             $response['data']['billing_details']    = $billing_details;
601 601
         }
602 602
         
603
-        wp_send_json( $response );
603
+        wp_send_json($response);
604 604
     }
605 605
     
606 606
     public static function run_tool() {
607
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
608
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
607
+        check_ajax_referer('wpinv-nonce', '_nonce');
608
+        if (!wpinv_current_user_can_manage_invoicing()) {
609 609
             die(-1);
610 610
         }
611 611
         
612
-        $tool = sanitize_text_field( $_POST['tool'] );
612
+        $tool = sanitize_text_field($_POST['tool']);
613 613
         
614
-        do_action( 'wpinv_run_tool' );
614
+        do_action('wpinv_run_tool');
615 615
         
616
-        if ( !empty( $tool ) ) {
617
-            do_action( 'wpinv_tool_' . $tool );
616
+        if (!empty($tool)) {
617
+            do_action('wpinv_tool_' . $tool);
618 618
         }
619 619
     }
620 620
     
621 621
     public static function apply_discount() {
622 622
         global $wpi_userID;
623 623
         
624
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
624
+        check_ajax_referer('wpinv-nonce', '_nonce');
625 625
         
626 626
         $response = array();
627 627
         
628
-        if ( isset( $_POST['code'] ) ) {
629
-            $discount_code = sanitize_text_field( $_POST['code'] );
628
+        if (isset($_POST['code'])) {
629
+            $discount_code = sanitize_text_field($_POST['code']);
630 630
 
631 631
             $response['success']        = false;
632 632
             $response['msg']            = '';
633 633
             $response['data']['code']   = $discount_code;
634 634
             
635 635
             $invoice = wpinv_get_invoice_cart();
636
-            if ( empty( $invoice->ID ) ) {
637
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
638
-                wp_send_json( $response );
636
+            if (empty($invoice->ID)) {
637
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
638
+                wp_send_json($response);
639 639
             }
640 640
 
641 641
             $wpi_userID = $invoice->get_user_id();
642 642
 
643
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
644
-                $discount       = wpinv_get_discount_by_code( $discount_code );
645
-                $discounts      = wpinv_set_cart_discount( $discount_code );
646
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
647
-                $total          = wpinv_get_cart_total( null, $discounts );
648
-                $cart_totals    = wpinv_recalculate_tax( true );
643
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
644
+                $discount       = wpinv_get_discount_by_code($discount_code);
645
+                $discounts      = wpinv_set_cart_discount($discount_code);
646
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
647
+                $total          = wpinv_get_cart_total(null, $discounts);
648
+                $cart_totals    = wpinv_recalculate_tax(true);
649 649
             
650
-                if ( !empty( $cart_totals ) ) {
650
+                if (!empty($cart_totals)) {
651 651
                     $response['success']        = true;
652 652
                     $response['data']           = $cart_totals;
653 653
                     $response['data']['code']   = $discount_code;
@@ -656,29 +656,29 @@  discard block
 block discarded – undo
656 656
                 }
657 657
             } else {
658 658
                 $errors = wpinv_get_errors();
659
-                $response['msg']  = $errors['wpinv-discount-error'];
660
-                wpinv_unset_error( 'wpinv-discount-error' );
659
+                $response['msg'] = $errors['wpinv-discount-error'];
660
+                wpinv_unset_error('wpinv-discount-error');
661 661
             }
662 662
 
663 663
             // Allow for custom discount code handling
664
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
664
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
665 665
         }
666 666
         
667
-        wp_send_json( $response );
667
+        wp_send_json($response);
668 668
     }
669 669
     
670 670
     public static function remove_discount() {
671
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
671
+        check_ajax_referer('wpinv-nonce', '_nonce');
672 672
         
673 673
         $response = array();
674 674
         
675
-        if ( isset( $_POST['code'] ) ) {
676
-            $discount_code  = sanitize_text_field( $_POST['code'] );
677
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
678
-            $total          = wpinv_get_cart_total( null, $discounts );
679
-            $cart_totals    = wpinv_recalculate_tax( true );
675
+        if (isset($_POST['code'])) {
676
+            $discount_code  = sanitize_text_field($_POST['code']);
677
+            $discounts      = wpinv_unset_cart_discount($discount_code);
678
+            $total          = wpinv_get_cart_total(null, $discounts);
679
+            $cart_totals    = wpinv_recalculate_tax(true);
680 680
             
681
-            if ( !empty( $cart_totals ) ) {
681
+            if (!empty($cart_totals)) {
682 682
                 $response['success']        = true;
683 683
                 $response['data']           = $cart_totals;
684 684
                 $response['data']['code']   = $discount_code;
@@ -687,10 +687,10 @@  discard block
 block discarded – undo
687 687
             }
688 688
             
689 689
             // Allow for custom discount code handling
690
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
690
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
691 691
         }
692 692
         
693
-        wp_send_json( $response );
693
+        wp_send_json($response);
694 694
     }
695 695
 
696 696
     /**
@@ -702,59 +702,59 @@  discard block
 block discarded – undo
702 702
         global $invoicing;
703 703
 
704 704
         // Check nonce.
705
-        if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) {
706
-            wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) );
705
+        if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) {
706
+            wp_send_json_error(__('Security checks failed.', 'invoicing'));
707 707
         }
708 708
 
709 709
         // Prepare submitted data...
710
-        $data = wp_unslash( $_POST );
710
+        $data = wp_unslash($_POST);
711 711
 
712 712
         // ... form fields...
713
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
714
-            wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) );
713
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
714
+            wp_send_json_error(__('This payment form is no longer active.', 'invoicing'));
715 715
         }
716 716
 
717
-        if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) {
718
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
717
+        if (empty($data['billing_email']) || !is_email($data['billing_email'])) {
718
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
719 719
         }
720 720
 
721 721
         $prepared = array(
722
-            'billing_email'                    => sanitize_email( $data['billing_email'] ),
723
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ),
724
-            __( 'Form Id', 'invoicing' )       => absint( $data['form_id'] ),
722
+            'billing_email'                    => sanitize_email($data['billing_email']),
723
+            __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']),
724
+            __('Form Id', 'invoicing')       => absint($data['form_id']),
725 725
         );
726 726
 
727
-        $prepared['billing_email'] = sanitize_email( $data['billing_email'] );
727
+        $prepared['billing_email'] = sanitize_email($data['billing_email']);
728 728
 
729
-        $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] );
729
+        $fields = $invoicing->form_elements->get_form_elements($data['form_id']);
730 730
 
731 731
         // ... and form items.
732
-        $items          = $invoicing->form_elements->get_form_items( $data['form_id'] );
732
+        $items          = $invoicing->form_elements->get_form_items($data['form_id']);
733 733
         $prepared_items = array();
734 734
 
735
-        if ( ! empty( $data['wpinv-items'] ) ) {
735
+        if (!empty($data['wpinv-items'])) {
736 736
 
737
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
737
+            $selected_items = wpinv_clean($data['wpinv-items']);
738 738
 
739
-            foreach ( $items as $item ) {
739
+            foreach ($items as $item) {
740 740
 
741
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
741
+                if (!isset($selected_items[$item['id']])) {
742 742
                     continue;
743 743
                 }
744 744
 
745 745
                 // Custom pricing.
746
-                if ( ! empty( $item['custom_price'] ) ) {
746
+                if (!empty($item['custom_price'])) {
747 747
 
748
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
749
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
748
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
749
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
750 750
 
751
-                    if ( $set_price < $minimum_price ) {
752
-                        wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) );
751
+                    if ($set_price < $minimum_price) {
752
+                        wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing'));
753 753
                     }
754 754
 
755 755
                     $prepared_items[] = array(
756 756
                         'id'           =>$item['id'],
757
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
757
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
758 758
                         'custom_price' => $set_price,
759 759
                         'name'         => $item['title'],
760 760
                     );
@@ -763,8 +763,8 @@  discard block
 block discarded – undo
763 763
 
764 764
                     $prepared_items[] = array(
765 765
                         'id'           => $item['id'],
766
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
767
-                        'custom_price' => wpinv_sanitize_amount( $item['price'] ),
766
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
767
+                        'custom_price' => wpinv_sanitize_amount($item['price']),
768 768
                         'name'         => $item['title'],
769 769
                     );
770 770
 
@@ -774,45 +774,45 @@  discard block
 block discarded – undo
774 774
 
775 775
         } else {
776 776
 
777
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
777
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
778 778
 
779 779
         }
780 780
 
781 781
         // Are all required fields provided?
782
-        foreach ( $fields as $field ) {
782
+        foreach ($fields as $field) {
783 783
 
784
-            if ( ! empty( $field['premade'] ) ) {
784
+            if (!empty($field['premade'])) {
785 785
                 continue;
786 786
             }
787 787
 
788
-            if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) {
789
-                wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
788
+            if (!empty($field['required']) && empty($data[$field['id']])) {
789
+                wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
790 790
             }
791 791
 
792
-            if ( isset( $data[ $field['id'] ] ) ) {
792
+            if (isset($data[$field['id']])) {
793 793
                 $label = $field['id'];
794 794
 
795
-                if ( isset( $field['label'] ) ) {
795
+                if (isset($field['label'])) {
796 796
                     $label = $field['label'];
797 797
                 }
798 798
 
799
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
799
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
800 800
             }
801 801
 
802 802
         }
803 803
         
804
-        $user = get_user_by( 'email', $prepared['billing_email'] );
804
+        $user = get_user_by('email', $prepared['billing_email']);
805 805
 
806
-        if ( empty( $user ) ) {
807
-            $user = wpinv_create_user( $prepared['billing_email'] );
806
+        if (empty($user)) {
807
+            $user = wpinv_create_user($prepared['billing_email']);
808 808
         }
809 809
 
810
-        if ( is_wp_error( $user ) ) {
811
-            wp_send_json_error( $user->get_error_message() );
810
+        if (is_wp_error($user)) {
811
+            wp_send_json_error($user->get_error_message());
812 812
         }
813 813
 
814
-        if ( is_numeric( $user ) ) {
815
-            $user = get_user_by( 'id', $user );
814
+        if (is_numeric($user)) {
815
+            $user = get_user_by('id', $user);
816 816
         }
817 817
 
818 818
         // Create the invoice.
@@ -826,18 +826,18 @@  discard block
 block discarded – undo
826 826
             true
827 827
         );
828 828
 
829
-        if ( is_wp_error( $created ) ) {
830
-            wp_send_json_error( $created->get_error_message() );
829
+        if (is_wp_error($created)) {
830
+            wp_send_json_error($created->get_error_message());
831 831
         }
832 832
 
833
-        if ( empty( $created ) ) {
834
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
833
+        if (empty($created)) {
834
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
835 835
         }
836 836
 
837
-        unset( $prepared['billing_email'] );
838
-        update_post_meta( $created->ID, 'payment_form_data', $prepared );
837
+        unset($prepared['billing_email']);
838
+        update_post_meta($created->ID, 'payment_form_data', $prepared);
839 839
 
840
-        wp_send_json_success( $created->get_view_url( true ) );
840
+        wp_send_json_success($created->get_view_url(true));
841 841
 
842 842
     }
843 843
 
@@ -849,53 +849,53 @@  discard block
 block discarded – undo
849 849
     public static function buy_items() {
850 850
         $user_id = get_current_user_id();
851 851
 
852
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
853
-            wp_send_json( array(
854
-                'success' => wp_login_url( wp_get_referer() )
855
-            ) );
852
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
853
+            wp_send_json(array(
854
+                'success' => wp_login_url(wp_get_referer())
855
+            ));
856 856
         } else {
857 857
             // Only check nonce if logged in as it could be cached when logged out.
858
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
859
-                wp_send_json( array(
860
-                    'error' => __( 'Security checks failed.', 'invoicing' )
861
-                ) );
858
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
859
+                wp_send_json(array(
860
+                    'error' => __('Security checks failed.', 'invoicing')
861
+                ));
862 862
                 wp_die();
863 863
             }
864 864
 
865 865
             // allow to set a custom price through post_id
866 866
             $items = $_POST['items'];
867
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
868
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
867
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
868
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
869 869
 
870 870
             $cart_items = array();
871
-            if ( $items ) {
872
-                $items = explode( ',', $items );
871
+            if ($items) {
872
+                $items = explode(',', $items);
873 873
 
874
-                foreach( $items as $item ) {
874
+                foreach ($items as $item) {
875 875
                     $item_id = $item;
876 876
                     $quantity = 1;
877 877
 
878
-                    if ( strpos( $item, '|' ) !== false ) {
879
-                        $item_parts = explode( '|', $item );
878
+                    if (strpos($item, '|') !== false) {
879
+                        $item_parts = explode('|', $item);
880 880
                         $item_id = $item_parts[0];
881 881
                         $quantity = $item_parts[1];
882 882
                     }
883 883
 
884
-                    if ( $item_id && $quantity ) {
884
+                    if ($item_id && $quantity) {
885 885
                         $cart_items_arr = array(
886
-                            'id'            => (int)$item_id,
887
-                            'quantity'      => (int)$quantity
886
+                            'id'            => (int) $item_id,
887
+                            'quantity'      => (int) $quantity
888 888
                         );
889 889
 
890 890
                         // If there is a related post id then add it to meta
891
-                        if ( $related_post_id ) {
891
+                        if ($related_post_id) {
892 892
                             $cart_items_arr['meta'] = array(
893 893
                                 'post_id'   => $related_post_id
894 894
                             );
895 895
                         }
896 896
 
897 897
                         // If there is a custom price then set it.
898
-                        if ( $custom_item_price ) {
898
+                        if ($custom_item_price) {
899 899
                             $cart_items_arr['custom_price'] = $custom_item_price;
900 900
                         }
901 901
 
@@ -911,37 +911,37 @@  discard block
 block discarded – undo
911 911
              * @param int $related_post_id The related post id if any.
912 912
              * @since 1.0.0
913 913
              */
914
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
914
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
915 915
 
916 916
             // Make sure its not in the cart already, if it is then redirect to checkout.
917 917
             $cart_invoice = wpinv_get_invoice_cart();
918 918
 
919
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
920
-                wp_send_json( array(
919
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
920
+                wp_send_json(array(
921 921
                     'success' =>  $cart_invoice->get_checkout_payment_url()
922
-                ) );
922
+                ));
923 923
                 wp_die();
924 924
             }
925 925
 
926 926
             // Check if user has invoice with same items waiting to be paid.
927
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
928
-            if ( !empty( $user_invoices ) ) {
929
-                foreach( $user_invoices as $user_invoice ) {
927
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
928
+            if (!empty($user_invoices)) {
929
+                foreach ($user_invoices as $user_invoice) {
930 930
                     $user_cart_details = array();
931
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
931
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
932 932
                     $cart_details = $invoice->get_cart_details();
933 933
 
934
-                    if ( !empty( $cart_details ) ) {
935
-                        foreach ( $cart_details as $invoice_item ) {
934
+                    if (!empty($cart_details)) {
935
+                        foreach ($cart_details as $invoice_item) {
936 936
                             $ii_arr = array();
937
-                            $ii_arr['id'] = (int)$invoice_item['id'];
938
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
937
+                            $ii_arr['id'] = (int) $invoice_item['id'];
938
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
939 939
 
940
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
940
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
941 941
                                 $ii_arr['meta'] = $invoice_item['meta'];
942 942
                             }
943 943
 
944
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
944
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
945 945
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
946 946
                             }
947 947
 
@@ -949,17 +949,17 @@  discard block
 block discarded – undo
949 949
                         }
950 950
                     }
951 951
 
952
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
953
-                        wp_send_json( array(
952
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
953
+                        wp_send_json(array(
954 954
                             'success' =>  $invoice->get_checkout_payment_url()
955
-                        ) );
955
+                        ));
956 956
                         wp_die();
957 957
                     }
958 958
                 }
959 959
             }
960 960
 
961 961
             // Create invoice and send user to checkout
962
-            if ( !empty( $cart_items ) ) {
962
+            if (!empty($cart_items)) {
963 963
                 $invoice_data = array(
964 964
                     'status'        =>  'wpi-pending',
965 965
                     'created_via'   =>  'wpi',
@@ -967,21 +967,21 @@  discard block
 block discarded – undo
967 967
                     'cart_details'  =>  $cart_items,
968 968
                 );
969 969
 
970
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
970
+                $invoice = wpinv_insert_invoice($invoice_data, true);
971 971
 
972
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
973
-                    wp_send_json( array(
972
+                if (!empty($invoice) && isset($invoice->ID)) {
973
+                    wp_send_json(array(
974 974
                         'success' =>  $invoice->get_checkout_payment_url()
975
-                    ) );
975
+                    ));
976 976
                 } else {
977
-                    wp_send_json( array(
978
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
979
-                    ) );
977
+                    wp_send_json(array(
978
+                        'error' => __('Invoice failed to create', 'invoicing')
979
+                    ));
980 980
                 }
981 981
             } else {
982
-                wp_send_json( array(
983
-                    'error' => __( 'Items not valid.', 'invoicing' )
984
-                ) );
982
+                wp_send_json(array(
983
+                    'error' => __('Items not valid.', 'invoicing')
984
+                ));
985 985
             }
986 986
         }
987 987
 
Please login to merge, or discard this patch.
includes/wpinv-user-functions.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
  */
160 160
 function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
161 161
 
162
-	if ( current_user_can( 'manage_options' ) ) {
163
-		return 'manage_options';
164
-	};
162
+    if ( current_user_can( 'manage_options' ) ) {
163
+        return 'manage_options';
164
+    };
165 165
 
166
-	return $capalibilty;
166
+    return $capalibilty;
167 167
 }
168 168
 
169 169
 /**
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 function wpinv_create_user( $email ) {
186 186
 
187 187
     // Prepare user values.
188
-	$args = array(
189
-		'user_login' => wpinv_generate_user_name( $email ),
190
-		'user_pass'  => wp_generate_password(),
191
-		'user_email' => $email,
192
-		'role'       => 'subscriber',
188
+    $args = array(
189
+        'user_login' => wpinv_generate_user_name( $email ),
190
+        'user_pass'  => wp_generate_password(),
191
+        'user_email' => $email,
192
+        'role'       => 'subscriber',
193 193
     );
194 194
         
195 195
     return wp_insert_user( $args );
@@ -205,20 +205,20 @@  discard block
 block discarded – undo
205 205
 function wpinv_generate_user_name( $prefix = '' ) {
206 206
 
207 207
     // If prefix is an email, retrieve the part before the email.
208
-	$prefix = strtok( $prefix, '@' );
208
+    $prefix = strtok( $prefix, '@' );
209 209
 
210
-	// Trim to 4 characters max.
211
-	$prefix = sanitize_user( substr( $prefix, 0, 4 ) );
210
+    // Trim to 4 characters max.
211
+    $prefix = sanitize_user( substr( $prefix, 0, 4 ) );
212 212
 
213
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
215
-		$prefix = 'paywp';
216
-	}
213
+    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
+    if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
215
+        $prefix = 'paywp';
216
+    }
217 217
 
218
-	$username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
-	if ( username_exists( $username ) ) {
220
-		return wpinv_generate_user_name( $username );
221
-	}
218
+    $username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
+    if ( username_exists( $username ) ) {
220
+        return wpinv_generate_user_name( $username );
221
+    }
222 222
 
223 223
     return $username;
224 224
 }
Please login to merge, or discard this patch.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -1,22 +1,22 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_users_invoices( $user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC' ) {
6
-    if ( empty( $user ) ) {
5
+function wpinv_get_users_invoices($user = 0, $number = 20, $pagination = false, $status = 'publish', $orderby = 'ID', $order = 'DESC') {
6
+    if (empty($user)) {
7 7
         $user = get_current_user_id();
8 8
     }
9 9
 
10
-    if ( empty( $user ) ) {
10
+    if (empty($user)) {
11 11
         return false;
12 12
     }
13 13
 
14
-    $args = apply_filters( 'wpinv_get_users_invoices_args', array( 'user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order ) );
14
+    $args = apply_filters('wpinv_get_users_invoices_args', array('user' => $user, 'limit' => $number, 'status' => $status, 'paginate' => $pagination, 'orderby' => $orderby, 'order' => $order));
15 15
     
16
-    return wpinv_get_invoices( $args );
16
+    return wpinv_get_invoices($args);
17 17
 }
18 18
 
19
-function wpinv_dropdown_users( $args = '' ) {
19
+function wpinv_dropdown_users($args = '') {
20 20
     $defaults = array(
21 21
         'show_option_all' => '', 'show_option_none' => '', 'hide_if_only_one_author' => '',
22 22
         'orderby' => 'display_name', 'order' => 'ASC',
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
         'option_none_value' => -1
28 28
     );
29 29
 
30
-    $defaults['selected'] = is_author() ? get_query_var( 'author' ) : 0;
30
+    $defaults['selected'] = is_author() ? get_query_var('author') : 0;
31 31
 
32
-    $r = wp_parse_args( $args, $defaults );
32
+    $r = wp_parse_args($args, $defaults);
33 33
 
34
-    $query_args = wp_array_slice_assoc( $r, array( 'blog_id', 'include', 'exclude', 'orderby', 'order', 'who' ) );
34
+    $query_args = wp_array_slice_assoc($r, array('blog_id', 'include', 'exclude', 'orderby', 'order', 'who'));
35 35
 
36
-    $fields = array( 'ID', 'user_login', 'user_email' );
36
+    $fields = array('ID', 'user_login', 'user_email');
37 37
 
38
-    $show = ! empty( $r['show'] ) ? $r['show'] : 'display_name';
39
-    if ( 'display_name_with_login' === $show ) {
38
+    $show = !empty($r['show']) ? $r['show'] : 'display_name';
39
+    if ('display_name_with_login' === $show) {
40 40
         $fields[] = 'display_name';
41
-    } else if ( 'display_name_with_email' === $show ) {
41
+    } else if ('display_name_with_email' === $show) {
42 42
         $fields[] = 'display_name';
43 43
     } else {
44 44
         $fields[] = $show;
@@ -50,99 +50,99 @@  discard block
 block discarded – undo
50 50
     $show_option_none = $r['show_option_none'];
51 51
     $option_none_value = $r['option_none_value'];
52 52
 
53
-    $query_args = apply_filters( 'wpinv_dropdown_users_args', $query_args, $r );
53
+    $query_args = apply_filters('wpinv_dropdown_users_args', $query_args, $r);
54 54
 
55
-    $users = get_users( $query_args );
55
+    $users = get_users($query_args);
56 56
 
57 57
     $output = '';
58
-    if ( ! empty( $users ) && ( empty( $r['hide_if_only_one_author'] ) || count( $users ) > 1 ) ) {
59
-        $name = esc_attr( $r['name'] );
60
-        if ( $r['multi'] && ! $r['id'] ) {
58
+    if (!empty($users) && (empty($r['hide_if_only_one_author']) || count($users) > 1)) {
59
+        $name = esc_attr($r['name']);
60
+        if ($r['multi'] && !$r['id']) {
61 61
             $id = '';
62 62
         } else {
63
-            $id = $r['id'] ? " id='" . esc_attr( $r['id'] ) . "'" : " id='$name'";
63
+            $id = $r['id'] ? " id='" . esc_attr($r['id']) . "'" : " id='$name'";
64 64
         }
65 65
         $output = "<select name='{$name}'{$id} class='" . $r['class'] . "'>\n";
66 66
 
67
-        if ( $show_option_all ) {
67
+        if ($show_option_all) {
68 68
             $output .= "\t<option value='0'>$show_option_all</option>\n";
69 69
         }
70 70
 
71
-        if ( $show_option_none ) {
72
-            $_selected = selected( $option_none_value, $r['selected'], false );
73
-            $output .= "\t<option value='" . esc_attr( $option_none_value ) . "'$_selected>$show_option_none</option>\n";
71
+        if ($show_option_none) {
72
+            $_selected = selected($option_none_value, $r['selected'], false);
73
+            $output .= "\t<option value='" . esc_attr($option_none_value) . "'$_selected>$show_option_none</option>\n";
74 74
         }
75 75
 
76
-        if ( $r['include_selected'] && ( $r['selected'] > 0 ) ) {
76
+        if ($r['include_selected'] && ($r['selected'] > 0)) {
77 77
             $found_selected = false;
78 78
             $r['selected'] = (int) $r['selected'];
79
-            foreach ( (array) $users as $user ) {
79
+            foreach ((array) $users as $user) {
80 80
                 $user->ID = (int) $user->ID;
81
-                if ( $user->ID === $r['selected'] ) {
81
+                if ($user->ID === $r['selected']) {
82 82
                     $found_selected = true;
83 83
                 }
84 84
             }
85 85
 
86
-            if ( ! $found_selected ) {
87
-                $users[] = get_userdata( $r['selected'] );
86
+            if (!$found_selected) {
87
+                $users[] = get_userdata($r['selected']);
88 88
             }
89 89
         }
90 90
 
91
-        foreach ( (array) $users as $user ) {
92
-            if ( 'display_name_with_login' === $show ) {
91
+        foreach ((array) $users as $user) {
92
+            if ('display_name_with_login' === $show) {
93 93
                 /* translators: 1: display name, 2: user_login */
94
-                $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_login );
95
-            } elseif ( 'display_name_with_email' === $show ) {
94
+                $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_login);
95
+            } elseif ('display_name_with_email' === $show) {
96 96
                 /* translators: 1: display name, 2: user_email */
97
-                if ( $user->display_name == $user->user_email ) {
97
+                if ($user->display_name == $user->user_email) {
98 98
                     $display = $user->display_name;
99 99
                 } else {
100
-                    $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown' ), $user->display_name, $user->user_email );
100
+                    $display = sprintf(_x('%1$s (%2$s)', 'user dropdown'), $user->display_name, $user->user_email);
101 101
                 }
102
-            } elseif ( ! empty( $user->$show ) ) {
102
+            } elseif (!empty($user->$show)) {
103 103
                 $display = $user->$show;
104 104
             } else {
105 105
                 $display = '(' . $user->user_login . ')';
106 106
             }
107 107
 
108
-            $_selected = selected( $user->ID, $r['selected'], false );
109
-            $output .= "\t<option value='$user->ID'$_selected>" . esc_html( $display ) . "</option>\n";
108
+            $_selected = selected($user->ID, $r['selected'], false);
109
+            $output .= "\t<option value='$user->ID'$_selected>" . esc_html($display) . "</option>\n";
110 110
         }
111 111
 
112 112
         $output .= "</select>";
113 113
     }
114 114
 
115
-    $html = apply_filters( 'wpinv_dropdown_users', $output );
115
+    $html = apply_filters('wpinv_dropdown_users', $output);
116 116
 
117
-    if ( $r['echo'] ) {
117
+    if ($r['echo']) {
118 118
         echo $html;
119 119
     }
120 120
     return $html;
121 121
 }
122 122
 
123
-function wpinv_guest_redirect( $redirect_to, $user_id = 0 ) {
124
-    if ( (int)wpinv_get_option( 'guest_checkout' ) && $user_id > 0 ) {
125
-        wpinv_login_user( $user_id );
123
+function wpinv_guest_redirect($redirect_to, $user_id = 0) {
124
+    if ((int) wpinv_get_option('guest_checkout') && $user_id > 0) {
125
+        wpinv_login_user($user_id);
126 126
     } else {
127
-        $redirect_to = wp_login_url( $redirect_to );
127
+        $redirect_to = wp_login_url($redirect_to);
128 128
     }
129 129
     
130
-    $redirect_to = apply_filters( 'wpinv_invoice_link_guest_redirect', $redirect_to, $user_id );
130
+    $redirect_to = apply_filters('wpinv_invoice_link_guest_redirect', $redirect_to, $user_id);
131 131
     
132
-    wp_redirect( $redirect_to );
132
+    wp_redirect($redirect_to);
133 133
 }
134 134
 
135
-function wpinv_login_user( $user_id ) {
136
-    if ( is_user_logged_in() ) {
135
+function wpinv_login_user($user_id) {
136
+    if (is_user_logged_in()) {
137 137
         return true;
138 138
     }
139 139
     
140
-    $user = get_user_by( 'id', $user_id );
140
+    $user = get_user_by('id', $user_id);
141 141
     
142
-    if ( !empty( $user ) && !is_wp_error( $user ) && !empty( $user->user_login ) ) {
143
-        wp_set_current_user( $user_id, $user->user_login );
144
-        wp_set_auth_cookie( $user_id );
145
-        do_action( 'wp_login', $user->user_login );
142
+    if (!empty($user) && !is_wp_error($user) && !empty($user->user_login)) {
143
+        wp_set_current_user($user_id, $user->user_login);
144
+        wp_set_auth_cookie($user_id);
145
+        do_action('wp_login', $user->user_login);
146 146
         
147 147
         return true;
148 148
     }
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
  * @return string capability to check against
158 158
  * @param string $capalibilty Optional. The alternative capability to check against.
159 159
  */
160
-function wpinv_get_capability( $capalibilty = 'manage_invoicing' ) {
160
+function wpinv_get_capability($capalibilty = 'manage_invoicing') {
161 161
 
162
-	if ( current_user_can( 'manage_options' ) ) {
162
+	if (current_user_can('manage_options')) {
163 163
 		return 'manage_options';
164 164
 	};
165 165
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
  * @return bool
174 174
  */
175 175
 function wpinv_current_user_can_manage_invoicing() {
176
-    return current_user_can( wpinv_get_capability() );
176
+    return current_user_can(wpinv_get_capability());
177 177
 }
178 178
 
179 179
 /**
@@ -182,17 +182,17 @@  discard block
 block discarded – undo
182 182
  * @since 1.0.19
183 183
  * @return int|WP_Error
184 184
  */
185
-function wpinv_create_user( $email ) {
185
+function wpinv_create_user($email) {
186 186
 
187 187
     // Prepare user values.
188 188
 	$args = array(
189
-		'user_login' => wpinv_generate_user_name( $email ),
189
+		'user_login' => wpinv_generate_user_name($email),
190 190
 		'user_pass'  => wp_generate_password(),
191 191
 		'user_email' => $email,
192 192
 		'role'       => 'subscriber',
193 193
     );
194 194
         
195
-    return wp_insert_user( $args );
195
+    return wp_insert_user($args);
196 196
 
197 197
 }
198 198
 
@@ -202,22 +202,22 @@  discard block
 block discarded – undo
202 202
  * @since 1.0.19
203 203
  * @return bool|WP_User
204 204
  */
205
-function wpinv_generate_user_name( $prefix = '' ) {
205
+function wpinv_generate_user_name($prefix = '') {
206 206
 
207 207
     // If prefix is an email, retrieve the part before the email.
208
-	$prefix = strtok( $prefix, '@' );
208
+	$prefix = strtok($prefix, '@');
209 209
 
210 210
 	// Trim to 4 characters max.
211
-	$prefix = sanitize_user( substr( $prefix, 0, 4 ) );
211
+	$prefix = sanitize_user(substr($prefix, 0, 4));
212 212
 
213
-	$illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );
214
-	if ( empty( $prefix ) || in_array( strtolower( $prefix ), array_map( 'strtolower', $illegal_logins ), true ) ) {
213
+	$illegal_logins = (array) apply_filters('illegal_user_logins', array());
214
+	if (empty($prefix) || in_array(strtolower($prefix), array_map('strtolower', $illegal_logins), true)) {
215 215
 		$prefix = 'paywp';
216 216
 	}
217 217
 
218
-	$username = $prefix . '_' . zeroise( wp_rand( 0, 9999 ), 4 );
219
-	if ( username_exists( $username ) ) {
220
-		return wpinv_generate_user_name( $username );
218
+	$username = $prefix . '_' . zeroise(wp_rand(0, 9999), 4);
219
+	if (username_exists($username)) {
220
+		return wpinv_generate_user_name($username);
221 221
 	}
222 222
 
223 223
     return $username;
Please login to merge, or discard this patch.