Passed
Push — master ( 42a3b4...9f729e )
by Brian
06:35
created
includes/class-wpinv-ajax.php 1 patch
Spacing   +326 added lines, -326 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
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -106,36 +106,36 @@  discard block
 block discarded – undo
106 106
             'file_upload'                 => true,
107 107
         );
108 108
 
109
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
110
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+        foreach ($ajax_events as $ajax_event => $nopriv) {
110
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
 
113
-            if ( $nopriv ) {
114
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
115
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
116
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
+            if ($nopriv) {
114
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
115
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
116
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
117 117
             }
118 118
         }
119 119
     }
120 120
     
121 121
     public static function add_note() {
122
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
122
+        check_ajax_referer('add-invoice-note', '_nonce');
123 123
 
124
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
124
+        if (!wpinv_current_user_can_manage_invoicing()) {
125 125
             die(-1);
126 126
         }
127 127
 
128
-        $post_id   = absint( $_POST['post_id'] );
129
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
130
-        $note_type = sanitize_text_field( $_POST['note_type'] );
128
+        $post_id   = absint($_POST['post_id']);
129
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
130
+        $note_type = sanitize_text_field($_POST['note_type']);
131 131
 
132 132
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
133 133
 
134
-        if ( $post_id > 0 ) {
135
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
134
+        if ($post_id > 0) {
135
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
136 136
 
137
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
138
-                wpinv_get_invoice_note_line_item( $note_id );
137
+            if ($note_id > 0 && !is_wp_error($note_id)) {
138
+                wpinv_get_invoice_note_line_item($note_id);
139 139
             }
140 140
         }
141 141
 
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
     }
144 144
 
145 145
     public static function delete_note() {
146
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
146
+        check_ajax_referer('delete-invoice-note', '_nonce');
147 147
 
148
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
148
+        if (!wpinv_current_user_can_manage_invoicing()) {
149 149
             die(-1);
150 150
         }
151 151
 
152
-        $note_id = (int)$_POST['note_id'];
152
+        $note_id = (int) $_POST['note_id'];
153 153
 
154
-        if ( $note_id > 0 ) {
155
-            wp_delete_comment( $note_id, true );
154
+        if ($note_id > 0) {
155
+            wp_delete_comment($note_id, true);
156 156
         }
157 157
 
158 158
         die();
@@ -170,34 +170,34 @@  discard block
 block discarded – undo
170 170
     public static function get_billing_details() {
171 171
 
172 172
         // Verify nonce.
173
-        check_ajax_referer( 'wpinv-nonce' );
173
+        check_ajax_referer('wpinv-nonce');
174 174
 
175 175
         // Can the user manage the plugin?
176
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
176
+        if (!wpinv_current_user_can_manage_invoicing()) {
177 177
             die(-1);
178 178
         }
179 179
 
180 180
         // Do we have a user id?
181 181
         $user_id = $_GET['user_id'];
182 182
 
183
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
183
+        if (empty($user_id) || !is_numeric($user_id)) {
184 184
             die(-1);
185 185
         }
186 186
 
187 187
         // Fetch the billing details.
188
-        $billing_details    = wpinv_get_user_address( $user_id );
189
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
188
+        $billing_details    = wpinv_get_user_address($user_id);
189
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
190 190
 
191 191
         // unset the user id and email.
192
-        $to_ignore = array( 'user_id', 'email' );
192
+        $to_ignore = array('user_id', 'email');
193 193
 
194
-        foreach ( $to_ignore as $key ) {
195
-            if ( isset( $billing_details[ $key ] ) ) {
196
-                unset( $billing_details[ $key ] );
194
+        foreach ($to_ignore as $key) {
195
+            if (isset($billing_details[$key])) {
196
+                unset($billing_details[$key]);
197 197
             }
198 198
         }
199 199
 
200
-        wp_send_json_success( $billing_details );
200
+        wp_send_json_success($billing_details);
201 201
 
202 202
     }
203 203
 
@@ -207,47 +207,47 @@  discard block
 block discarded – undo
207 207
     public static function check_new_user_email() {
208 208
 
209 209
         // Verify nonce.
210
-        check_ajax_referer( 'wpinv-nonce' );
210
+        check_ajax_referer('wpinv-nonce');
211 211
 
212 212
         // Can the user manage the plugin?
213
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
213
+        if (!wpinv_current_user_can_manage_invoicing()) {
214 214
             die(-1);
215 215
         }
216 216
 
217 217
         // We need an email address.
218
-        if ( empty( $_GET['email'] ) ) {
219
-            _e( "Provide the new user's email address", 'invoicing' );
218
+        if (empty($_GET['email'])) {
219
+            _e("Provide the new user's email address", 'invoicing');
220 220
             exit;
221 221
         }
222 222
 
223 223
         // Ensure the email is valid.
224
-        $email = sanitize_text_field( $_GET['email'] );
225
-        if ( ! is_email( $email ) ) {
226
-            _e( 'Invalid email address', 'invoicing' );
224
+        $email = sanitize_text_field($_GET['email']);
225
+        if (!is_email($email)) {
226
+            _e('Invalid email address', 'invoicing');
227 227
             exit;
228 228
         }
229 229
 
230 230
         // And it does not exist.
231
-        $id = email_exists( $email );
232
-        if ( $id ) {
233
-            wp_send_json_success( compact( 'id' ) );
231
+        $id = email_exists($email);
232
+        if ($id) {
233
+            wp_send_json_success(compact('id'));
234 234
         }
235 235
 
236
-        wp_send_json_success( true );
236
+        wp_send_json_success(true);
237 237
     }
238 238
     
239 239
     public static function run_tool() {
240
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
241
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
240
+        check_ajax_referer('wpinv-nonce', '_nonce');
241
+        if (!wpinv_current_user_can_manage_invoicing()) {
242 242
             die(-1);
243 243
         }
244 244
         
245
-        $tool = sanitize_text_field( $_POST['tool'] );
245
+        $tool = sanitize_text_field($_POST['tool']);
246 246
         
247
-        do_action( 'wpinv_run_tool' );
247
+        do_action('wpinv_run_tool');
248 248
         
249
-        if ( !empty( $tool ) ) {
250
-            do_action( 'wpinv_tool_' . $tool );
249
+        if (!empty($tool)) {
250
+            do_action('wpinv_tool_' . $tool);
251 251
         }
252 252
     }
253 253
 
@@ -258,43 +258,43 @@  discard block
 block discarded – undo
258 258
         global $getpaid_force_checkbox;
259 259
 
260 260
         // Check nonce.
261
-        check_ajax_referer( 'getpaid_form_nonce' );
261
+        check_ajax_referer('getpaid_form_nonce');
262 262
 
263 263
         // Is the request set up correctly?
264
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
264
+		if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) {
265 265
 			echo aui()->alert(
266 266
 				array(
267 267
 					'type'    => 'warning',
268
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
268
+					'content' => __('No payment form or item provided', 'invoicing'),
269 269
 				)
270 270
             );
271 271
             exit;
272 272
         }
273 273
 
274 274
         // Payment form or button?
275
-		if ( ! empty( $_GET['form'] ) ) {
276
-            $form = urldecode( $_GET['form'] );
275
+		if (!empty($_GET['form'])) {
276
+            $form = urldecode($_GET['form']);
277 277
 
278
-            if ( false !== strpos( $form, '|' ) ) {
279
-                $form_pos = strpos( $form, '|' );
280
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
281
-                $form     = substr( $form, 0, $form_pos );
278
+            if (false !== strpos($form, '|')) {
279
+                $form_pos = strpos($form, '|');
280
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
281
+                $form     = substr($form, 0, $form_pos);
282 282
 
283 283
                 // Retrieve appropriate payment form.
284
-                $payment_form = new GetPaid_Payment_Form( $form );
285
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
284
+                $payment_form = new GetPaid_Payment_Form($form);
285
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
286 286
 
287 287
                 $items    = array();
288 288
                 $item_ids = array();
289 289
 
290
-                foreach ( $_items as $item_id => $qty ) {
291
-                    if ( ! in_array( $item_id, $item_ids ) ) {
292
-                        $item = new GetPaid_Form_Item( $item_id );
293
-                        $item->set_quantity( $qty );
290
+                foreach ($_items as $item_id => $qty) {
291
+                    if (!in_array($item_id, $item_ids)) {
292
+                        $item = new GetPaid_Form_Item($item_id);
293
+                        $item->set_quantity($qty);
294 294
 
295
-                        if ( 0 == $qty ) {
296
-                            $item->set_allow_quantities( true );
297
-                            $item->set_is_required( false );
295
+                        if (0 == $qty) {
296
+                            $item->set_allow_quantities(true);
297
+                            $item->set_is_required(false);
298 298
                             $getpaid_force_checkbox = true;
299 299
                         }
300 300
 
@@ -303,10 +303,10 @@  discard block
 block discarded – undo
303 303
                     }
304 304
                 }
305 305
 
306
-                if ( ! $payment_form->is_default() ) {
306
+                if (!$payment_form->is_default()) {
307 307
 
308
-                    foreach ( $payment_form->get_items() as $item ) {
309
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
308
+                    foreach ($payment_form->get_items() as $item) {
309
+                        if (!in_array($item->get_id(), $item_ids)) {
310 310
                             $item_ids[] = $item->get_id();
311 311
                             $items[]    = $item;
312 312
                         }
@@ -314,23 +314,23 @@  discard block
 block discarded – undo
314 314
 
315 315
                 }
316 316
 
317
-                $payment_form->set_items( $items );
318
-                $extra_items     = esc_attr( getpaid_convert_items_to_string( $_items ) );
319
-                $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
317
+                $payment_form->set_items($items);
318
+                $extra_items     = esc_attr(getpaid_convert_items_to_string($_items));
319
+                $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
320 320
                 $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
321 321
                 $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
322
-                $payment_form->display( $extra_items );
322
+                $payment_form->display($extra_items);
323 323
                 $getpaid_force_checkbox = false;
324 324
 
325 325
             } else {
326
-                getpaid_display_payment_form( $form );
326
+                getpaid_display_payment_form($form);
327 327
             }
328 328
 
329
-		} else if( ! empty( $_GET['invoice'] ) ) {
330
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
329
+		} else if (!empty($_GET['invoice'])) {
330
+		    getpaid_display_invoice_payment_form(urldecode($_GET['invoice']));
331 331
         } else {
332
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
333
-		    getpaid_display_item_payment_form( $items );
332
+			$items = getpaid_convert_items_to_array(urldecode($_GET['item']));
333
+		    getpaid_display_item_payment_form($items);
334 334
         }
335 335
 
336 336
         exit;
@@ -345,17 +345,17 @@  discard block
 block discarded – undo
345 345
     public static function payment_form() {
346 346
 
347 347
         // Check nonce.
348
-        check_ajax_referer( 'getpaid_form_nonce' );
348
+        check_ajax_referer('getpaid_form_nonce');
349 349
 
350 350
         // ... form fields...
351
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
352
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
351
+        if (empty($_POST['getpaid_payment_form_submission'])) {
352
+            _e('Error: Reload the page and try again.', 'invoicing');
353 353
             exit;
354 354
         }
355 355
 
356 356
         // Process the payment form.
357
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
358
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
357
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
358
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
359 359
         $checkout->process_checkout();
360 360
 
361 361
         exit;
@@ -368,55 +368,55 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public static function get_payment_form_states_field() {
370 370
 
371
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
371
+        if (empty($_GET['country']) || empty($_GET['form'])) {
372 372
             exit;
373 373
         }
374 374
 
375
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
375
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
376 376
 
377
-        if ( empty( $elements ) ) {
377
+        if (empty($elements)) {
378 378
             exit;
379 379
         }
380 380
 
381 381
         $address_fields = array();
382
-        foreach ( $elements as $element ) {
383
-            if ( 'address' === $element['type'] ) {
382
+        foreach ($elements as $element) {
383
+            if ('address' === $element['type']) {
384 384
                 $address_fields = $element;
385 385
                 break;
386 386
             }
387 387
         }
388 388
 
389
-        if ( empty( $address_fields ) ) {
389
+        if (empty($address_fields)) {
390 390
             exit;
391 391
         }
392 392
 
393
-        foreach ( $address_fields['fields'] as $address_field ) {
393
+        foreach ($address_fields['fields'] as $address_field) {
394 394
 
395
-            if ( 'wpinv_state' == $address_field['name'] ) {
395
+            if ('wpinv_state' == $address_field['name']) {
396 396
 
397
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
398
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
399
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
400
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
401
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
402
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
397
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
398
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
399
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
400
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
401
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
402
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
403 403
 
404
-                if ( ! empty( $address_field['required'] ) ) {
404
+                if (!empty($address_field['required'])) {
405 405
                     $label .= "<span class='text-danger'> *</span>";
406 406
                 }
407 407
 
408
-                $html = getpaid_get_states_select_markup (
409
-                    sanitize_text_field( $_GET['country'] ),
408
+                $html = getpaid_get_states_select_markup(
409
+                    sanitize_text_field($_GET['country']),
410 410
                     $value,
411 411
                     $placeholder,
412 412
                     $label,
413 413
                     $description,
414
-                    ! empty( $address_field['required'] ),
414
+                    !empty($address_field['required']),
415 415
                     $wrap_class,
416
-                    wpinv_clean( $_GET['name'] )
416
+                    wpinv_clean($_GET['name'])
417 417
                 );
418 418
 
419
-                wp_send_json_success( $html );
419
+                wp_send_json_success($html);
420 420
                 exit;
421 421
 
422 422
             }
@@ -432,66 +432,66 @@  discard block
 block discarded – undo
432 432
     public static function recalculate_invoice_totals() {
433 433
 
434 434
         // Verify nonce.
435
-        check_ajax_referer( 'wpinv-nonce' );
435
+        check_ajax_referer('wpinv-nonce');
436 436
 
437
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
437
+        if (!wpinv_current_user_can_manage_invoicing()) {
438 438
             exit;
439 439
         }
440 440
 
441 441
         // We need an invoice.
442
-        if ( empty( $_POST['post_id'] ) ) {
442
+        if (empty($_POST['post_id'])) {
443 443
             exit;
444 444
         }
445 445
 
446 446
         // Fetch the invoice.
447
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
447
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
448 448
 
449 449
         // Ensure it exists.
450
-        if ( ! $invoice->get_id() ) {
450
+        if (!$invoice->get_id()) {
451 451
             exit;
452 452
         }
453 453
 
454 454
         // Maybe set the country, state, currency.
455
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
456
-            if ( isset( $_POST[ $key ] ) ) {
455
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
456
+            if (isset($_POST[$key])) {
457 457
                 $method = "set_$key";
458
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
458
+                $invoice->$method(sanitize_text_field($_POST[$key]));
459 459
             }
460 460
         }
461 461
 
462 462
         // Maybe disable taxes.
463
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
463
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
464 464
 
465 465
         // Discount code.
466
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
467
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
468
-            if ( $discount->exists() ) {
469
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
466
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
467
+            $discount = new WPInv_Discount($invoice->get_discount_code());
468
+            if ($discount->exists()) {
469
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
470 470
             } else {
471
-                $invoice->remove_discount( 'discount_code' );
471
+                $invoice->remove_discount('discount_code');
472 472
             }
473 473
         }
474 474
 
475 475
         // Recalculate totals.
476 476
         $invoice->recalculate_total();
477 477
 
478
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
479
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
480
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
481
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
482
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
478
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
479
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
480
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
481
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
482
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
483 483
         }
484 484
 
485 485
         $totals = array(
486
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
487
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
488
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
486
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
487
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
488
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
489 489
             'total'    => $total,
490 490
         );
491 491
 
492
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
492
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
493 493
 
494
-        wp_send_json_success( compact( 'totals' ) );
494
+        wp_send_json_success(compact('totals'));
495 495
     }
496 496
 
497 497
     /**
@@ -500,33 +500,33 @@  discard block
 block discarded – undo
500 500
     public static function get_invoice_items() {
501 501
 
502 502
         // Verify nonce.
503
-        check_ajax_referer( 'wpinv-nonce' );
503
+        check_ajax_referer('wpinv-nonce');
504 504
 
505
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
505
+        if (!wpinv_current_user_can_manage_invoicing()) {
506 506
             exit;
507 507
         }
508 508
 
509 509
         // We need an invoice and items.
510
-        if ( empty( $_POST['post_id'] ) ) {
510
+        if (empty($_POST['post_id'])) {
511 511
             exit;
512 512
         }
513 513
 
514 514
         // Fetch the invoice.
515
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
515
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
516 516
 
517 517
         // Ensure it exists.
518
-        if ( ! $invoice->get_id() ) {
518
+        if (!$invoice->get_id()) {
519 519
             exit;
520 520
         }
521 521
 
522 522
         // Return an array of invoice items.
523 523
         $items = array();
524 524
 
525
-        foreach ( $invoice->get_items() as $item ) {
526
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency(), $invoice->is_renewal()  );
525
+        foreach ($invoice->get_items() as $item) {
526
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
527 527
         }
528 528
 
529
-        wp_send_json_success( compact( 'items' ) );
529
+        wp_send_json_success(compact('items'));
530 530
     }
531 531
 
532 532
     /**
@@ -535,50 +535,50 @@  discard block
 block discarded – undo
535 535
     public static function edit_invoice_item() {
536 536
 
537 537
         // Verify nonce.
538
-        check_ajax_referer( 'wpinv-nonce' );
538
+        check_ajax_referer('wpinv-nonce');
539 539
 
540
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
540
+        if (!wpinv_current_user_can_manage_invoicing()) {
541 541
             exit;
542 542
         }
543 543
 
544 544
         // We need an invoice and item details.
545
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
545
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
546 546
             exit;
547 547
         }
548 548
 
549 549
         // Fetch the invoice.
550
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
550
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
551 551
 
552 552
         // Ensure it exists and its not been paid for.
553
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
553
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
554 554
             exit;
555 555
         }
556 556
 
557 557
         // Format the data.
558
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
558
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
559 559
 
560 560
         // Ensure that we have an item id.
561
-        if ( empty( $data['id'] ) ) {
561
+        if (empty($data['id'])) {
562 562
             exit;
563 563
         }
564 564
 
565 565
         // Abort if the invoice does not have the specified item.
566
-        $item = $invoice->get_item( (int) $data['id'] );
566
+        $item = $invoice->get_item((int) $data['id']);
567 567
 
568
-        if ( empty( $item ) ) {
568
+        if (empty($item)) {
569 569
             exit;
570 570
         }
571 571
 
572 572
         // Update the item.
573
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
574
-        $item->set_name( sanitize_text_field( $data['name'] ) );
575
-        $item->set_description( wp_kses_post( $data['description'] ) );
576
-        $item->set_quantity( floatval( $data['quantity'] ) );
573
+        $item->set_price(getpaid_standardize_amount($data['price']));
574
+        $item->set_name(sanitize_text_field($data['name']));
575
+        $item->set_description(wp_kses_post($data['description']));
576
+        $item->set_quantity(floatval($data['quantity']));
577 577
 
578 578
         // Add it to the invoice.
579
-        $error = $invoice->add_item( $item );
579
+        $error = $invoice->add_item($item);
580 580
         $alert = false;
581
-        if ( is_wp_error( $error ) ) {
581
+        if (is_wp_error($error)) {
582 582
             $alert = $error->get_error_message();
583 583
         }
584 584
 
@@ -591,11 +591,11 @@  discard block
 block discarded – undo
591 591
         // Return an array of invoice items.
592 592
         $items = array();
593 593
 
594
-        foreach ( $invoice->get_items() as $item ) {
595
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
594
+        foreach ($invoice->get_items() as $item) {
595
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
596 596
         }
597 597
 
598
-        wp_send_json_success( compact( 'items', 'alert' ) );
598
+        wp_send_json_success(compact('items', 'alert'));
599 599
     }
600 600
 
601 601
     /**
@@ -604,53 +604,53 @@  discard block
 block discarded – undo
604 604
     public static function create_invoice_item() {
605 605
 
606 606
         // Verify nonce.
607
-        check_ajax_referer( 'wpinv-nonce' );
607
+        check_ajax_referer('wpinv-nonce');
608 608
 
609
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
609
+        if (!wpinv_current_user_can_manage_invoicing()) {
610 610
             exit;
611 611
         }
612 612
 
613 613
         // We need an invoice and item details.
614
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
614
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
615 615
             exit;
616 616
         }
617 617
 
618 618
         // Fetch the invoice.
619
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['invoice_id'] ) );
619
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['invoice_id']));
620 620
 
621 621
         // Ensure it exists and its not been paid for.
622
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
622
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
623 623
             exit;
624 624
         }
625 625
 
626 626
         // Format the data.
627
-        $data = wp_unslash( $_POST['_wpinv_quick'] );
627
+        $data = wp_unslash($_POST['_wpinv_quick']);
628 628
 
629 629
         $item = new WPInv_Item();
630
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
631
-        $item->set_name( sanitize_text_field( $data['name'] ) );
632
-        $item->set_description( wp_kses_post( $data['description'] ) );
633
-        $item->set_type( sanitize_text_field( $data['type'] ) );
634
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
635
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
636
-        $item->set_status( 'publish' );
630
+        $item->set_price(getpaid_standardize_amount($data['price']));
631
+        $item->set_name(sanitize_text_field($data['name']));
632
+        $item->set_description(wp_kses_post($data['description']));
633
+        $item->set_type(sanitize_text_field($data['type']));
634
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
635
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
636
+        $item->set_status('publish');
637 637
         $item->save();
638 638
 
639
-        if ( ! $item->exists() ) {
640
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
641
-            wp_send_json_success( compact( 'alert' ) );
639
+        if (!$item->exists()) {
640
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
641
+            wp_send_json_success(compact('alert'));
642 642
         }
643 643
 
644
-        $item = new GetPaid_Form_Item( $item->get_id() );
645
-        $item->set_quantity( floatval( $data['qty'] ) );
644
+        $item = new GetPaid_Form_Item($item->get_id());
645
+        $item->set_quantity(floatval($data['qty']));
646 646
 
647 647
         // Add it to the invoice.
648
-        $error = $invoice->add_item( $item );
648
+        $error = $invoice->add_item($item);
649 649
         $alert = false;
650 650
 
651
-        if ( is_wp_error( $error ) ) {
651
+        if (is_wp_error($error)) {
652 652
             $alert = $error->get_error_message();
653
-            wp_send_json_success( compact( 'alert' ) );
653
+            wp_send_json_success(compact('alert'));
654 654
          }
655 655
 
656 656
         // Update totals.
@@ -663,9 +663,9 @@  discard block
 block discarded – undo
663 663
         $invoice->recalculate_total();
664 664
         $invoice->save();
665 665
         ob_start();
666
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
666
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
667 667
         $row = ob_get_clean();
668
-        wp_send_json_success( compact( 'row' ) );
668
+        wp_send_json_success(compact('row'));
669 669
     }
670 670
 
671 671
     /**
@@ -674,33 +674,33 @@  discard block
 block discarded – undo
674 674
     public static function remove_invoice_item() {
675 675
 
676 676
         // Verify nonce.
677
-        check_ajax_referer( 'wpinv-nonce' );
677
+        check_ajax_referer('wpinv-nonce');
678 678
 
679
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
679
+        if (!wpinv_current_user_can_manage_invoicing()) {
680 680
             exit;
681 681
         }
682 682
 
683 683
         // We need an invoice and an item.
684
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
684
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
685 685
             exit;
686 686
         }
687 687
 
688 688
         // Fetch the invoice.
689
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
689
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
690 690
 
691 691
         // Ensure it exists and its not been paid for.
692
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
692
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
693 693
             exit;
694 694
         }
695 695
 
696 696
         // Abort if the invoice does not have the specified item.
697
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
697
+        $item = $invoice->get_item((int) $_POST['item_id']);
698 698
 
699
-        if ( empty( $item ) ) {
699
+        if (empty($item)) {
700 700
             exit;
701 701
         }
702 702
 
703
-        $invoice->remove_item( (int) $_POST['item_id'] );
703
+        $invoice->remove_item((int) $_POST['item_id']);
704 704
 
705 705
         // Update totals.
706 706
         $invoice->recalculate_total();
@@ -711,11 +711,11 @@  discard block
 block discarded – undo
711 711
         // Return an array of invoice items.
712 712
         $items = array();
713 713
 
714
-        foreach ( $invoice->get_items() as $item ) {
715
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
714
+        foreach ($invoice->get_items() as $item) {
715
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
716 716
         }
717 717
 
718
-        wp_send_json_success( compact( 'items' ) );
718
+        wp_send_json_success(compact('items'));
719 719
     }
720 720
 
721 721
     /**
@@ -724,69 +724,69 @@  discard block
 block discarded – undo
724 724
     public static function recalculate_full_prices() {
725 725
 
726 726
         // Verify nonce.
727
-        check_ajax_referer( 'wpinv-nonce' );
727
+        check_ajax_referer('wpinv-nonce');
728 728
 
729
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
729
+        if (!wpinv_current_user_can_manage_invoicing()) {
730 730
             exit;
731 731
         }
732 732
 
733 733
         // We need an invoice and item.
734
-        if ( empty( $_POST['post_id'] ) ) {
734
+        if (empty($_POST['post_id'])) {
735 735
             exit;
736 736
         }
737 737
 
738 738
         // Fetch the invoice.
739
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
739
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
740 740
         $alert   = false;
741 741
 
742 742
         // Ensure it exists and its not been paid for.
743
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
743
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
744 744
             exit;
745 745
         }
746 746
 
747
-        $invoice->set_items( array() );
747
+        $invoice->set_items(array());
748 748
 
749
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
749
+        if (!empty($_POST['getpaid_items'])) {
750 750
 
751
-            foreach ( $_POST['getpaid_items'] as $item_id => $args ) {
752
-                $item = new GetPaid_Form_Item( $item_id );
751
+            foreach ($_POST['getpaid_items'] as $item_id => $args) {
752
+                $item = new GetPaid_Form_Item($item_id);
753 753
 
754
-                if ( $item->exists() ) {
755
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
756
-                    $item->set_quantity( floatval( $args['quantity'] ) );
757
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
758
-                    $item->set_description( wp_kses_post( $args['description'] ) );
759
-                    $invoice->add_item( $item );
754
+                if ($item->exists()) {
755
+                    $item->set_price(getpaid_standardize_amount($args['price']));
756
+                    $item->set_quantity(floatval($args['quantity']));
757
+                    $item->set_name(sanitize_text_field($args['name']));
758
+                    $item->set_description(wp_kses_post($args['description']));
759
+                    $invoice->add_item($item);
760 760
                 }
761 761
             }
762 762
 
763 763
         }
764 764
 
765
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
765
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
766 766
 
767 767
         // Maybe set the country, state, currency.
768
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
769
-            if ( isset( $_POST[ $key ] ) ) {
770
-                $_key   = str_replace( 'wpinv_', '', $key );
768
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
769
+            if (isset($_POST[$key])) {
770
+                $_key   = str_replace('wpinv_', '', $key);
771 771
                 $method = "set_$_key";
772
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
772
+                $invoice->$method(sanitize_text_field($_POST[$key]));
773 773
             }
774 774
         }
775 775
 
776
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
777
-        if ( $discount->exists() ) {
778
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
776
+        $discount = new WPInv_Discount($invoice->get_discount_code());
777
+        if ($discount->exists()) {
778
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
779 779
         } else {
780
-            $invoice->remove_discount( 'discount_code' );
780
+            $invoice->remove_discount('discount_code');
781 781
         }
782 782
 
783 783
         // Save the invoice.
784 784
         $invoice->recalculate_total();
785 785
         $invoice->save();
786 786
         ob_start();
787
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
787
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
788 788
         $table = ob_get_clean();
789
-        wp_send_json_success( compact( 'table' ) );
789
+        wp_send_json_success(compact('table'));
790 790
     }
791 791
 
792 792
     /**
@@ -795,42 +795,42 @@  discard block
 block discarded – undo
795 795
     public static function admin_add_invoice_item() {
796 796
 
797 797
         // Verify nonce.
798
-        check_ajax_referer( 'wpinv-nonce' );
798
+        check_ajax_referer('wpinv-nonce');
799 799
 
800
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
800
+        if (!wpinv_current_user_can_manage_invoicing()) {
801 801
             exit;
802 802
         }
803 803
 
804 804
         // We need an invoice and item.
805
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
805
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
806 806
             exit;
807 807
         }
808 808
 
809 809
         // Fetch the invoice.
810
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
810
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
811 811
         $alert   = false;
812 812
 
813 813
         // Ensure it exists and its not been paid for.
814
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
814
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
815 815
             exit;
816 816
         }
817 817
 
818 818
         // Add the item.
819
-        $item  = new GetPaid_Form_Item( (int) $_POST['item_id'] );
820
-        $error = $invoice->add_item( $item );
819
+        $item  = new GetPaid_Form_Item((int) $_POST['item_id']);
820
+        $error = $invoice->add_item($item);
821 821
 
822
-        if ( is_wp_error( $error ) ) {
822
+        if (is_wp_error($error)) {
823 823
             $alert = $error->get_error_message();
824
-            wp_send_json_success( compact( 'alert' ) );
824
+            wp_send_json_success(compact('alert'));
825 825
         }
826 826
 
827 827
         // Save the invoice.
828 828
         $invoice->recalculate_total();
829 829
         $invoice->save();
830 830
         ob_start();
831
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
831
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
832 832
         $row = ob_get_clean();
833
-        wp_send_json_success( compact( 'row' ) );
833
+        wp_send_json_success(compact('row'));
834 834
     }
835 835
 
836 836
     /**
@@ -839,39 +839,39 @@  discard block
 block discarded – undo
839 839
     public static function add_invoice_items() {
840 840
 
841 841
         // Verify nonce.
842
-        check_ajax_referer( 'wpinv-nonce' );
842
+        check_ajax_referer('wpinv-nonce');
843 843
 
844
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
844
+        if (!wpinv_current_user_can_manage_invoicing()) {
845 845
             exit;
846 846
         }
847 847
 
848 848
         // We need an invoice and items.
849
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
849
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
850 850
             exit;
851 851
         }
852 852
 
853 853
         // Fetch the invoice.
854
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
854
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
855 855
         $alert   = false;
856 856
 
857 857
         // Ensure it exists and its not been paid for.
858
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
858
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
859 859
             exit;
860 860
         }
861 861
 
862 862
         // Add the items.
863
-        foreach ( $_POST['items'] as $data ) {
863
+        foreach ($_POST['items'] as $data) {
864 864
 
865
-            $item = new GetPaid_Form_Item( (int) $data[ 'id' ] );
865
+            $item = new GetPaid_Form_Item((int) $data['id']);
866 866
 
867
-            if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) {
868
-                $item->set_quantity( floatval( $data[ 'qty' ] ) );
867
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
868
+                $item->set_quantity(floatval($data['qty']));
869 869
             }
870 870
 
871
-            if ( $item->get_id() > 0 ) {
872
-                $error = $invoice->add_item( $item );
871
+            if ($item->get_id() > 0) {
872
+                $error = $invoice->add_item($item);
873 873
 
874
-                if ( is_wp_error( $error ) ) {
874
+                if (is_wp_error($error)) {
875 875
                     $alert = $error->get_error_message();
876 876
                 }
877 877
 
@@ -886,11 +886,11 @@  discard block
 block discarded – undo
886 886
         // Return an array of invoice items.
887 887
         $items = array();
888 888
 
889
-        foreach ( $invoice->get_items() as $item ) {
890
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
889
+        foreach ($invoice->get_items() as $item) {
890
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
891 891
         }
892 892
 
893
-        wp_send_json_success( compact( 'items', 'alert' ) );
893
+        wp_send_json_success(compact('items', 'alert'));
894 894
     }
895 895
 
896 896
     /**
@@ -899,15 +899,15 @@  discard block
 block discarded – undo
899 899
     public static function get_invoicing_items() {
900 900
 
901 901
         // Verify nonce.
902
-        check_ajax_referer( 'wpinv-nonce' );
902
+        check_ajax_referer('wpinv-nonce');
903 903
 
904
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
904
+        if (!wpinv_current_user_can_manage_invoicing()) {
905 905
             exit;
906 906
         }
907 907
 
908 908
         // We need a search term.
909
-        if ( empty( $_GET['search'] ) ) {
910
-            wp_send_json_success( array() );
909
+        if (empty($_GET['search'])) {
910
+            wp_send_json_success(array());
911 911
         }
912 912
 
913 913
         // Retrieve items.
@@ -916,8 +916,8 @@  discard block
 block discarded – undo
916 916
             'orderby'        => 'title',
917 917
             'order'          => 'ASC',
918 918
             'posts_per_page' => -1,
919
-            'post_status'    => array( 'publish' ),
920
-            's'              => trim( $_GET['search'] ),
919
+            'post_status'    => array('publish'),
920
+            's'              => trim($_GET['search']),
921 921
             'meta_query'     => array(
922 922
                 array(
923 923
                     'key'       => '_wpinv_type',
@@ -927,25 +927,25 @@  discard block
 block discarded – undo
927 927
             )
928 928
         );
929 929
 
930
-        if ( ! empty( $_GET['ignore'] ) ) {
931
-            $item_args['exclude'] = wp_parse_id_list( $_GET['ignore'] );
930
+        if (!empty($_GET['ignore'])) {
931
+            $item_args['exclude'] = wp_parse_id_list($_GET['ignore']);
932 932
         }
933 933
 
934
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
934
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
935 935
         $data  = array();
936 936
 
937
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
937
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
938 938
 
939
-        foreach ( $items as $item ) {
940
-            $item      = new GetPaid_Form_Item( $item );
939
+        foreach ($items as $item) {
940
+            $item = new GetPaid_Form_Item($item);
941 941
             $data[] = array(
942 942
                 'id'        => (int) $item->get_id(),
943
-                'text'      => strip_tags( $item->get_name() ),
944
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
943
+                'text'      => strip_tags($item->get_name()),
944
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
945 945
             );
946 946
         }
947 947
 
948
-        wp_send_json_success( $data );
948
+        wp_send_json_success($data);
949 949
 
950 950
     }
951 951
 
@@ -955,37 +955,37 @@  discard block
 block discarded – undo
955 955
     public static function get_customers() {
956 956
 
957 957
         // Verify nonce.
958
-        check_ajax_referer( 'wpinv-nonce' );
958
+        check_ajax_referer('wpinv-nonce');
959 959
 
960
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
960
+        if (!wpinv_current_user_can_manage_invoicing()) {
961 961
             exit;
962 962
         }
963 963
 
964 964
         // We need a search term.
965
-        if ( empty( $_GET['search'] ) ) {
966
-            wp_send_json_success( array() );
965
+        if (empty($_GET['search'])) {
966
+            wp_send_json_success(array());
967 967
         }
968 968
 
969 969
         // Retrieve customers.
970 970
     
971 971
         $customer_args = array(
972
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
972
+            'fields'         => array('ID', 'user_email', 'display_name'),
973 973
             'orderby'        => 'display_name',
974
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
975
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
974
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
975
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
976 976
         );
977 977
 
978
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
978
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
979 979
         $data      = array();
980 980
 
981
-        foreach ( $customers as $customer ) {
981
+        foreach ($customers as $customer) {
982 982
             $data[] = array(
983 983
                 'id'        => (int) $customer->ID,
984
-                'text'      => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
984
+                'text'      => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
985 985
             );
986 986
         }
987 987
 
988
-        wp_send_json_success( $data );
988
+        wp_send_json_success($data);
989 989
 
990 990
     }
991 991
 
@@ -995,28 +995,28 @@  discard block
 block discarded – undo
995 995
     public static function get_aui_states_field() {
996 996
 
997 997
         // Verify nonce.
998
-        check_ajax_referer( 'wpinv-nonce' );
998
+        check_ajax_referer('wpinv-nonce');
999 999
 
1000 1000
         // We need a country.
1001
-        if ( empty( $_GET['country'] ) ) {
1001
+        if (empty($_GET['country'])) {
1002 1002
             exit;
1003 1003
         }
1004 1004
 
1005
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1006
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1007
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1008
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1005
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1006
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1007
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1008
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1009 1009
 
1010
-        if ( empty( $states ) ) {
1010
+        if (empty($states)) {
1011 1011
 
1012 1012
             $html = aui()->input(
1013 1013
                 array(
1014 1014
                     'type'        => 'text',
1015 1015
                     'id'          => 'wpinv_state',
1016 1016
                     'name'        => $name,
1017
-                    'label'       => __( 'State', 'invoicing' ),
1017
+                    'label'       => __('State', 'invoicing'),
1018 1018
                     'label_type'  => 'vertical',
1019
-                    'placeholder' => __( 'State', 'invoicing' ),
1019
+                    'placeholder' => __('State', 'invoicing'),
1020 1020
                     'class'       => $class,
1021 1021
                     'value'       => $state,
1022 1022
                 )
@@ -1028,9 +1028,9 @@  discard block
 block discarded – undo
1028 1028
                 array(
1029 1029
                     'id'          => 'wpinv_state',
1030 1030
                     'name'        => $name,
1031
-                    'label'       => __( 'State', 'invoicing' ),
1031
+                    'label'       => __('State', 'invoicing'),
1032 1032
                     'label_type'  => 'vertical',
1033
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
1033
+                    'placeholder' => __('Select a state', 'invoicing'),
1034 1034
                     'class'       => $class,
1035 1035
                     'value'       => $state,
1036 1036
                     'options'     => $states,
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
         wp_send_json_success(
1045 1045
             array(
1046 1046
                 'html'   => $html,
1047
-                'select' => ! empty ( $states )
1047
+                'select' => !empty ($states)
1048 1048
             )
1049 1049
         );
1050 1050
 
@@ -1058,11 +1058,11 @@  discard block
 block discarded – undo
1058 1058
     public static function payment_form_refresh_prices() {
1059 1059
 
1060 1060
         // Check nonce.
1061
-        check_ajax_referer( 'getpaid_form_nonce' );
1061
+        check_ajax_referer('getpaid_form_nonce');
1062 1062
 
1063 1063
         // ... form fields...
1064
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1065
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
1064
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1065
+            _e('Error: Reload the page and try again.', 'invoicing');
1066 1066
             exit;
1067 1067
         }
1068 1068
 
@@ -1070,7 +1070,7 @@  discard block
 block discarded – undo
1070 1070
         $submission = new GetPaid_Payment_Form_Submission();
1071 1071
 
1072 1072
         // Do we have an error?
1073
-        if ( ! empty( $submission->last_error ) ) {
1073
+        if (!empty($submission->last_error)) {
1074 1074
             wp_send_json_error(
1075 1075
                 array(
1076 1076
                     'code'  => $submission->last_error_code,
@@ -1080,12 +1080,12 @@  discard block
 block discarded – undo
1080 1080
         }
1081 1081
 
1082 1082
         // Prepare the response.
1083
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1083
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1084 1084
 
1085 1085
         // Filter the response.
1086
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1086
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1087 1087
 
1088
-        wp_send_json_success( $response );
1088
+        wp_send_json_success($response);
1089 1089
     }
1090 1090
 
1091 1091
     /**
@@ -1097,63 +1097,63 @@  discard block
 block discarded – undo
1097 1097
 	public static function file_upload() {
1098 1098
 
1099 1099
         // Check nonce.
1100
-        check_ajax_referer( 'getpaid_form_nonce' );
1100
+        check_ajax_referer('getpaid_form_nonce');
1101 1101
 
1102
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1103
-            wp_die( __( 'Bad Request', 'invoicing' ), 400 );
1102
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1103
+            wp_die(__('Bad Request', 'invoicing'), 400);
1104 1104
         }
1105 1105
 
1106 1106
         // Fetch form.
1107
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1107
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1108 1108
 
1109
-        if ( ! $form->is_active() ) {
1110
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1109
+        if (!$form->is_active()) {
1110
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1111 1111
         }
1112 1112
 
1113 1113
         // Fetch appropriate field.
1114
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1115
-        if ( empty( $upload_field ) ) {
1116
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1114
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1115
+        if (empty($upload_field)) {
1116
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1117 1117
         }
1118 1118
 
1119 1119
         // Prepare allowed file types.
1120
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1120
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1121 1121
         $all_types  = getpaid_get_allowed_mime_types();
1122 1122
         $mime_types = array();
1123 1123
 
1124
-        foreach ( $file_types as $file_type ) {
1125
-            if ( isset( $all_types[ $file_type ] ) ) {
1126
-                $mime_types[] = $all_types[ $file_type ];
1124
+        foreach ($file_types as $file_type) {
1125
+            if (isset($all_types[$file_type])) {
1126
+                $mime_types[] = $all_types[$file_type];
1127 1127
             }
1128 1128
         }
1129 1129
 
1130
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1131
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1130
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1131
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1132 1132
         }
1133 1133
 
1134 1134
         // Upload file.
1135
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1136
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1135
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1136
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1137 1137
 
1138 1138
         $uploaded = wp_upload_bits(
1139 1139
             $file_name,
1140 1140
             null,
1141
-            file_get_contents( $_FILES["file"]["tmp_name"] )
1141
+            file_get_contents($_FILES["file"]["tmp_name"])
1142 1142
         );
1143 1143
 
1144
-        if ( ! empty( $uploaded['error'] ) ) {
1145
-            wp_send_json_error( $uploaded['error'] );
1144
+        if (!empty($uploaded['error'])) {
1145
+            wp_send_json_error($uploaded['error']);
1146 1146
         }
1147 1147
 
1148 1148
         // Retrieve response.
1149 1149
         $response = sprintf(
1150 1150
             '<input type="hidden" name="%s[%s]" value="%s" />',
1151
-            esc_attr( $_POST['field_name'] ),
1152
-            esc_attr( $uploaded['url'] ),
1153
-            esc_attr( strtolower( $_FILES['file']['name'] ) )
1151
+            esc_attr($_POST['field_name']),
1152
+            esc_attr($uploaded['url']),
1153
+            esc_attr(strtolower($_FILES['file']['name']))
1154 1154
         );
1155 1155
 
1156
-        wp_send_json_success( $response );
1156
+        wp_send_json_success($response);
1157 1157
 
1158 1158
 	}
1159 1159
 
Please login to merge, or discard this patch.