Passed
Pull Request — master (#462)
by Viktor
04:15
created
includes/class-wpinv-ajax.php 1 patch
Spacing   +199 added lines, -199 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
 
@@ -101,36 +101,36 @@  discard block
 block discarded – undo
101 101
             'payment_form_refresh_prices' => true,
102 102
         );
103 103
 
104
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
105
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
106
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
104
+        foreach ($ajax_events as $ajax_event => $nopriv) {
105
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
106
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
107 107
 
108
-            if ( $nopriv ) {
109
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
110
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
108
+            if ($nopriv) {
109
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
110
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
             }
113 113
         }
114 114
     }
115 115
     
116 116
     public static function add_note() {
117
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
117
+        check_ajax_referer('add-invoice-note', '_nonce');
118 118
 
119
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
119
+        if (!wpinv_current_user_can_manage_invoicing()) {
120 120
             die(-1);
121 121
         }
122 122
 
123
-        $post_id   = absint( $_POST['post_id'] );
124
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
125
-        $note_type = sanitize_text_field( $_POST['note_type'] );
123
+        $post_id   = absint($_POST['post_id']);
124
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
125
+        $note_type = sanitize_text_field($_POST['note_type']);
126 126
 
127 127
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
128 128
 
129
-        if ( $post_id > 0 ) {
130
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
129
+        if ($post_id > 0) {
130
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
131 131
 
132
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
133
-                wpinv_get_invoice_note_line_item( $note_id );
132
+            if ($note_id > 0 && !is_wp_error($note_id)) {
133
+                wpinv_get_invoice_note_line_item($note_id);
134 134
             }
135 135
         }
136 136
 
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
     }
139 139
 
140 140
     public static function delete_note() {
141
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
141
+        check_ajax_referer('delete-invoice-note', '_nonce');
142 142
 
143
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
143
+        if (!wpinv_current_user_can_manage_invoicing()) {
144 144
             die(-1);
145 145
         }
146 146
 
147
-        $note_id = (int)$_POST['note_id'];
147
+        $note_id = (int) $_POST['note_id'];
148 148
 
149
-        if ( $note_id > 0 ) {
150
-            wp_delete_comment( $note_id, true );
149
+        if ($note_id > 0) {
150
+            wp_delete_comment($note_id, true);
151 151
         }
152 152
 
153 153
         die();
@@ -165,34 +165,34 @@  discard block
 block discarded – undo
165 165
     public static function get_billing_details() {
166 166
 
167 167
         // Verify nonce.
168
-        check_ajax_referer( 'wpinv-nonce' );
168
+        check_ajax_referer('wpinv-nonce');
169 169
 
170 170
         // Can the user manage the plugin?
171
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
171
+        if (!wpinv_current_user_can_manage_invoicing()) {
172 172
             die(-1);
173 173
         }
174 174
 
175 175
         // Do we have a user id?
176 176
         $user_id = $_GET['user_id'];
177 177
 
178
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
178
+        if (empty($user_id) || !is_numeric($user_id)) {
179 179
             die(-1);
180 180
         }
181 181
 
182 182
         // Fetch the billing details.
183
-        $billing_details    = wpinv_get_user_address( $user_id );
184
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
183
+        $billing_details    = wpinv_get_user_address($user_id);
184
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
185 185
 
186 186
         // unset the user id and email.
187
-        $to_ignore = array( 'user_id', 'email' );
187
+        $to_ignore = array('user_id', 'email');
188 188
 
189
-        foreach ( $to_ignore as $key ) {
190
-            if ( isset( $billing_details[ $key ] ) ) {
191
-                unset( $billing_details[ $key ] );
189
+        foreach ($to_ignore as $key) {
190
+            if (isset($billing_details[$key])) {
191
+                unset($billing_details[$key]);
192 192
             }
193 193
         }
194 194
 
195
-        wp_send_json_success( $billing_details );
195
+        wp_send_json_success($billing_details);
196 196
 
197 197
     }
198 198
 
@@ -202,47 +202,47 @@  discard block
 block discarded – undo
202 202
     public static function check_new_user_email() {
203 203
 
204 204
         // Verify nonce.
205
-        check_ajax_referer( 'wpinv-nonce' );
205
+        check_ajax_referer('wpinv-nonce');
206 206
 
207 207
         // Can the user manage the plugin?
208
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
208
+        if (!wpinv_current_user_can_manage_invoicing()) {
209 209
             die(-1);
210 210
         }
211 211
 
212 212
         // We need an email address.
213
-        if ( empty( $_GET['email'] ) ) {
214
-            _e( "Provide the new user's email address", 'invoicing' );
213
+        if (empty($_GET['email'])) {
214
+            _e("Provide the new user's email address", 'invoicing');
215 215
             exit;
216 216
         }
217 217
 
218 218
         // Ensure the email is valid.
219
-        $email = sanitize_text_field( $_GET['email'] );
220
-        if ( ! is_email( $email ) ) {
221
-            _e( 'Invalid email address', 'invoicing' );
219
+        $email = sanitize_text_field($_GET['email']);
220
+        if (!is_email($email)) {
221
+            _e('Invalid email address', 'invoicing');
222 222
             exit;
223 223
         }
224 224
 
225 225
         // And it does not exist.
226
-        if ( email_exists( $email ) ) {
227
-            _e( 'A user with this email address already exists', 'invoicing' );
226
+        if (email_exists($email)) {
227
+            _e('A user with this email address already exists', 'invoicing');
228 228
             exit;
229 229
         }
230 230
 
231
-        wp_send_json_success( true );
231
+        wp_send_json_success(true);
232 232
     }
233 233
     
234 234
     public static function run_tool() {
235
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
236
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
235
+        check_ajax_referer('wpinv-nonce', '_nonce');
236
+        if (!wpinv_current_user_can_manage_invoicing()) {
237 237
             die(-1);
238 238
         }
239 239
         
240
-        $tool = sanitize_text_field( $_POST['tool'] );
240
+        $tool = sanitize_text_field($_POST['tool']);
241 241
         
242
-        do_action( 'wpinv_run_tool' );
242
+        do_action('wpinv_run_tool');
243 243
         
244
-        if ( !empty( $tool ) ) {
245
-            do_action( 'wpinv_tool_' . $tool );
244
+        if (!empty($tool)) {
245
+            do_action('wpinv_tool_' . $tool);
246 246
         }
247 247
     }
248 248
 
@@ -252,27 +252,27 @@  discard block
 block discarded – undo
252 252
     public static function get_payment_form() {
253 253
 
254 254
         // Check nonce.
255
-        check_ajax_referer( 'getpaid_form_nonce' );
255
+        check_ajax_referer('getpaid_form_nonce');
256 256
 
257 257
         // Is the request set up correctly?
258
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
258
+		if (empty($_GET['form']) && empty($_GET['item'])) {
259 259
 			echo aui()->alert(
260 260
 				array(
261 261
 					'type'    => 'warning',
262
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
262
+					'content' => __('No payment form or item provided', 'invoicing'),
263 263
 				)
264 264
             );
265 265
             exit;
266 266
         }
267 267
 
268 268
         // Payment form or button?
269
-		if ( ! empty( $_GET['form'] ) ) {
270
-            getpaid_display_payment_form( urldecode( $_GET['form'] ) );
271
-		} else if( ! empty( $_GET['invoice'] ) ) {
272
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
269
+		if (!empty($_GET['form'])) {
270
+            getpaid_display_payment_form(urldecode($_GET['form']));
271
+		} else if (!empty($_GET['invoice'])) {
272
+		    getpaid_display_invoice_payment_form(urldecode($_GET['invoice']));
273 273
         } else {
274
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
275
-		    getpaid_display_item_payment_form( $items );
274
+			$items = getpaid_convert_items_to_array(urldecode($_GET['item']));
275
+		    getpaid_display_item_payment_form($items);
276 276
         }
277 277
 
278 278
         exit;
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
     public static function payment_form() {
288 288
 
289 289
         // Check nonce.
290
-        check_ajax_referer( 'getpaid_form_nonce' );
290
+        check_ajax_referer('getpaid_form_nonce');
291 291
 
292 292
         // ... form fields...
293
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
294
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
293
+        if (empty($_POST['getpaid_payment_form_submission'])) {
294
+            _e('Error: Reload the page and try again.', 'invoicing');
295 295
             exit;
296 296
         }
297 297
 
298 298
         // Process the payment form.
299
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
300
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
299
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
300
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
301 301
         $checkout->process_checkout();
302 302
 
303 303
         exit;
@@ -310,55 +310,55 @@  discard block
 block discarded – undo
310 310
      */
311 311
     public static function get_payment_form_states_field() {
312 312
 
313
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
313
+        if (empty($_GET['country']) || empty($_GET['form'])) {
314 314
             exit;
315 315
         }
316 316
 
317
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
317
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
318 318
 
319
-        if ( empty( $elements ) ) {
319
+        if (empty($elements)) {
320 320
             exit;
321 321
         }
322 322
 
323 323
         $address_fields = array();
324
-        foreach ( $elements as $element ) {
325
-            if ( 'address' === $element['type'] ) {
324
+        foreach ($elements as $element) {
325
+            if ('address' === $element['type']) {
326 326
                 $address_fields = $element;
327 327
                 break;
328 328
             }
329 329
         }
330 330
 
331
-        if ( empty( $address_fields ) ) {
331
+        if (empty($address_fields)) {
332 332
             exit;
333 333
         }
334 334
 
335
-        foreach ( $address_fields['fields'] as $address_field ) {
335
+        foreach ($address_fields['fields'] as $address_field) {
336 336
 
337
-            if ( 'wpinv_state' == $address_field['name'] ) {
337
+            if ('wpinv_state' == $address_field['name']) {
338 338
 
339
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
340
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
341
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
342
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
343
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
344
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
339
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
340
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
341
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
342
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
343
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
344
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
345 345
 
346
-                if ( ! empty( $address_field['required'] ) ) {
346
+                if (!empty($address_field['required'])) {
347 347
                     $label .= "<span class='text-danger'> *</span>";
348 348
                 }
349 349
 
350
-                $html = getpaid_get_states_select_markup (
351
-                    sanitize_text_field( $_GET['country'] ),
350
+                $html = getpaid_get_states_select_markup(
351
+                    sanitize_text_field($_GET['country']),
352 352
                     $value,
353 353
                     $placeholder,
354 354
                     $label,
355 355
                     $description,
356
-                    ! empty( $address_field['required'] ),
356
+                    !empty($address_field['required']),
357 357
                     $wrap_class,
358
-                    wpinv_clean( $_GET['name'] )
358
+                    wpinv_clean($_GET['name'])
359 359
                 );
360 360
 
361
-                wp_send_json_success( $html );
361
+                wp_send_json_success($html);
362 362
                 exit;
363 363
 
364 364
             }
@@ -374,56 +374,56 @@  discard block
 block discarded – undo
374 374
     public static function recalculate_invoice_totals() {
375 375
 
376 376
         // Verify nonce.
377
-        check_ajax_referer( 'wpinv-nonce' );
377
+        check_ajax_referer('wpinv-nonce');
378 378
 
379
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
379
+        if (!wpinv_current_user_can_manage_invoicing()) {
380 380
             exit;
381 381
         }
382 382
 
383 383
         // We need an invoice.
384
-        if ( empty( $_POST['post_id'] ) ) {
384
+        if (empty($_POST['post_id'])) {
385 385
             exit;
386 386
         }
387 387
 
388 388
         // Fetch the invoice.
389
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
389
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
390 390
 
391 391
         // Ensure it exists.
392
-        if ( ! $invoice->get_id() ) {
392
+        if (!$invoice->get_id()) {
393 393
             exit;
394 394
         }
395 395
 
396 396
         // Maybe set the country, state, currency.
397
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
398
-            if ( isset( $_POST[ $key ] ) ) {
397
+        foreach (array('country', 'state', 'currency') as $key) {
398
+            if (isset($_POST[$key])) {
399 399
                 $method = "set_$key";
400
-                $invoice->$method( $_POST[ $key ] );
400
+                $invoice->$method($_POST[$key]);
401 401
             }
402 402
         }
403 403
 
404 404
         // Maybe disable taxes.
405
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
405
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
406 406
 
407 407
         // Recalculate totals.
408 408
         $invoice->recalculate_total();
409 409
 
410
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
410
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
411 411
 
412
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
413
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
414
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
412
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
413
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
414
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
415 415
         }
416 416
 
417 417
         $totals = array(
418
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
419
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
420
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
418
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
419
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
420
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
421 421
             'total'    => $total,
422 422
         );
423 423
 
424
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
424
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
425 425
 
426
-        wp_send_json_success( compact( 'totals' ) );
426
+        wp_send_json_success(compact('totals'));
427 427
     }
428 428
 
429 429
     /**
@@ -432,33 +432,33 @@  discard block
 block discarded – undo
432 432
     public static function get_invoice_items() {
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 and items.
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( trim( $_POST['post_id'] ) );
447
+        $invoice = new WPInv_Invoice(trim($_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
         // Return an array of invoice items.
455 455
         $items = array();
456 456
 
457
-        foreach ( $invoice->get_items() as $item_id => $item ) {
458
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
457
+        foreach ($invoice->get_items() as $item_id => $item) {
458
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
459 459
         }
460 460
 
461
-        wp_send_json_success( compact( 'items' ) );
461
+        wp_send_json_success(compact('items'));
462 462
     }
463 463
 
464 464
     /**
@@ -467,50 +467,50 @@  discard block
 block discarded – undo
467 467
     public static function edit_invoice_item() {
468 468
 
469 469
         // Verify nonce.
470
-        check_ajax_referer( 'wpinv-nonce' );
470
+        check_ajax_referer('wpinv-nonce');
471 471
 
472
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
472
+        if (!wpinv_current_user_can_manage_invoicing()) {
473 473
             exit;
474 474
         }
475 475
 
476 476
         // We need an invoice and item details.
477
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
477
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
478 478
             exit;
479 479
         }
480 480
 
481 481
         // Fetch the invoice.
482
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
482
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
483 483
 
484 484
         // Ensure it exists and its not been paid for.
485
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
485
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
486 486
             exit;
487 487
         }
488 488
 
489 489
         // Format the data.
490
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
490
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
491 491
 
492 492
         // Ensure that we have an item id.
493
-        if ( empty( $data['id'] ) ) {
493
+        if (empty($data['id'])) {
494 494
             exit;
495 495
         }
496 496
 
497 497
         // Abort if the invoice does not have the specified item.
498
-        $item = $invoice->get_item( (int) $data['id'] );
498
+        $item = $invoice->get_item((int) $data['id']);
499 499
 
500
-        if ( empty( $item ) ) {
500
+        if (empty($item)) {
501 501
             exit;
502 502
         }
503 503
 
504 504
         // Update the item.
505
-        $item->set_price( $data['price'] );
506
-        $item->set_name( $data['name'] );
507
-        $item->set_description( $data['description'] );
508
-        $item->set_quantity( $data['quantity'] );
505
+        $item->set_price($data['price']);
506
+        $item->set_name($data['name']);
507
+        $item->set_description($data['description']);
508
+        $item->set_quantity($data['quantity']);
509 509
 
510 510
         // Add it to the invoice.
511
-        $error = $invoice->add_item( $item );
511
+        $error = $invoice->add_item($item);
512 512
         $alert = false;
513
-        if ( is_wp_error( $error ) ) {
513
+        if (is_wp_error($error)) {
514 514
             $alert = $error->get_error_message();
515 515
         }
516 516
 
@@ -523,11 +523,11 @@  discard block
 block discarded – undo
523 523
         // Return an array of invoice items.
524 524
         $items = array();
525 525
 
526
-        foreach ( $invoice->get_items() as $item_id => $item ) {
527
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
526
+        foreach ($invoice->get_items() as $item_id => $item) {
527
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
528 528
         }
529 529
 
530
-        wp_send_json_success( compact( 'items', 'alert' ) );
530
+        wp_send_json_success(compact('items', 'alert'));
531 531
     }
532 532
 
533 533
     /**
@@ -536,33 +536,33 @@  discard block
 block discarded – undo
536 536
     public static function remove_invoice_item() {
537 537
 
538 538
         // Verify nonce.
539
-        check_ajax_referer( 'wpinv-nonce' );
539
+        check_ajax_referer('wpinv-nonce');
540 540
 
541
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
541
+        if (!wpinv_current_user_can_manage_invoicing()) {
542 542
             exit;
543 543
         }
544 544
 
545 545
         // We need an invoice and an item.
546
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
546
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
547 547
             exit;
548 548
         }
549 549
 
550 550
         // Fetch the invoice.
551
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
551
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
552 552
 
553 553
         // Ensure it exists and its not been paid for.
554
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
554
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
555 555
             exit;
556 556
         }
557 557
 
558 558
         // Abort if the invoice does not have the specified item.
559
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
559
+        $item = $invoice->get_item((int) $_POST['item_id']);
560 560
 
561
-        if ( empty( $item ) ) {
561
+        if (empty($item)) {
562 562
             exit;
563 563
         }
564 564
 
565
-        $invoice->remove_item( (int) $_POST['item_id'] );
565
+        $invoice->remove_item((int) $_POST['item_id']);
566 566
 
567 567
         // Update totals.
568 568
         $invoice->recalculate_total();
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
         // Return an array of invoice items.
574 574
         $items = array();
575 575
 
576
-        foreach ( $invoice->get_items() as $item_id => $item ) {
577
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
576
+        foreach ($invoice->get_items() as $item_id => $item) {
577
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
578 578
         }
579 579
 
580
-        wp_send_json_success( compact( 'items' ) );
580
+        wp_send_json_success(compact('items'));
581 581
     }
582 582
 
583 583
     /**
@@ -586,39 +586,39 @@  discard block
 block discarded – undo
586 586
     public static function add_invoice_items() {
587 587
 
588 588
         // Verify nonce.
589
-        check_ajax_referer( 'wpinv-nonce' );
589
+        check_ajax_referer('wpinv-nonce');
590 590
 
591
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
591
+        if (!wpinv_current_user_can_manage_invoicing()) {
592 592
             exit;
593 593
         }
594 594
 
595 595
         // We need an invoice and items.
596
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
596
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
597 597
             exit;
598 598
         }
599 599
 
600 600
         // Fetch the invoice.
601
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
601
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
602 602
         $alert   = false;
603 603
 
604 604
         // Ensure it exists and its not been paid for.
605
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
605
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
606 606
             exit;
607 607
         }
608 608
 
609 609
         // Add the items.
610
-        foreach ( $_POST['items'] as $data ) {
610
+        foreach ($_POST['items'] as $data) {
611 611
 
612
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
612
+            $item = new GetPaid_Form_Item($data['id']);
613 613
 
614
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
615
-                $item->set_quantity( $data[ 'qty' ] );
614
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
615
+                $item->set_quantity($data['qty']);
616 616
             }
617 617
 
618
-            if ( $item->get_id() > 0 ) {
619
-                $error = $invoice->add_item( $item );
618
+            if ($item->get_id() > 0) {
619
+                $error = $invoice->add_item($item);
620 620
 
621
-                if ( is_wp_error( $error ) ) {
621
+                if (is_wp_error($error)) {
622 622
                     $alert = $error->get_error_message();
623 623
                 }
624 624
 
@@ -633,11 +633,11 @@  discard block
 block discarded – undo
633 633
         // Return an array of invoice items.
634 634
         $items = array();
635 635
 
636
-        foreach ( $invoice->get_items() as $item_id => $item ) {
637
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
636
+        foreach ($invoice->get_items() as $item_id => $item) {
637
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
638 638
         }
639 639
 
640
-        wp_send_json_success( compact( 'items', 'alert' ) );
640
+        wp_send_json_success(compact('items', 'alert'));
641 641
     }
642 642
 
643 643
     /**
@@ -646,15 +646,15 @@  discard block
 block discarded – undo
646 646
     public static function get_invoicing_items() {
647 647
 
648 648
         // Verify nonce.
649
-        check_ajax_referer( 'wpinv-nonce' );
649
+        check_ajax_referer('wpinv-nonce');
650 650
 
651
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
651
+        if (!wpinv_current_user_can_manage_invoicing()) {
652 652
             exit;
653 653
         }
654 654
 
655 655
         // We need a search term.
656
-        if ( empty( $_GET['search'] ) ) {
657
-            wp_send_json_success( array() );
656
+        if (empty($_GET['search'])) {
657
+            wp_send_json_success(array());
658 658
         }
659 659
 
660 660
         // Retrieve items.
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
             'orderby'        => 'title',
664 664
             'order'          => 'ASC',
665 665
             'posts_per_page' => -1,
666
-            'post_status'    => array( 'publish' ),
667
-            's'              => trim( $_GET['search'] ),
666
+            'post_status'    => array('publish'),
667
+            's'              => trim($_GET['search']),
668 668
             'meta_query'     => array(
669 669
                 array(
670 670
                     'key'       => '_wpinv_type',
@@ -674,22 +674,22 @@  discard block
 block discarded – undo
674 674
             )
675 675
         );
676 676
 
677
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
677
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
678 678
         $data  = array();
679 679
 
680 680
 
681
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
681
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
682 682
 
683
-        foreach ( $items as $item ) {
684
-            $item      = new GetPaid_Form_Item( $item );
683
+        foreach ($items as $item) {
684
+            $item = new GetPaid_Form_Item($item);
685 685
             $data[] = array(
686 686
                 'id'        => (int) $item->get_id(),
687
-                'text'      => strip_tags( $item->get_name() ),
688
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
687
+                'text'      => strip_tags($item->get_name()),
688
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
689 689
             );
690 690
         }
691 691
 
692
-        wp_send_json_success( $data );
692
+        wp_send_json_success($data);
693 693
 
694 694
     }
695 695
 
@@ -699,26 +699,26 @@  discard block
 block discarded – undo
699 699
     public static function get_aui_states_field() {
700 700
 
701 701
         // Verify nonce.
702
-        check_ajax_referer( 'wpinv-nonce' );
702
+        check_ajax_referer('wpinv-nonce');
703 703
 
704 704
         // We need a country.
705
-        if ( empty( $_GET['country'] ) ) {
705
+        if (empty($_GET['country'])) {
706 706
             exit;
707 707
         }
708 708
 
709
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
710
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
709
+        $states = wpinv_get_country_states(trim($_GET['country']));
710
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
711 711
 
712
-        if ( empty( $states ) ) {
712
+        if (empty($states)) {
713 713
 
714 714
             $html = aui()->input(
715 715
                 array(
716 716
                     'type'        => 'text',
717 717
                     'id'          => 'wpinv_state',
718 718
                     'name'        => 'wpinv_state',
719
-                    'label'       => __( 'State', 'invoicing' ),
719
+                    'label'       => __('State', 'invoicing'),
720 720
                     'label_type'  => 'vertical',
721
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
721
+                    'placeholder' => __('Select a state', 'invoicing'),
722 722
                     'class'       => 'form-control-sm',
723 723
                     'value'       => $state,
724 724
                 )
@@ -730,9 +730,9 @@  discard block
 block discarded – undo
730 730
                 array(
731 731
                     'id'          => 'wpinv_state',
732 732
                     'name'        => 'wpinv_state',
733
-                    'label'       => __( 'State', 'invoicing' ),
733
+                    'label'       => __('State', 'invoicing'),
734 734
                     'label_type'  => 'vertical',
735
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
735
+                    'placeholder' => __('Select a state', 'invoicing'),
736 736
                     'class'       => 'form-control-sm',
737 737
                     'value'       => $state,
738 738
                     'options'     => $states,
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
         wp_send_json_success(
747 747
             array(
748 748
                 'html'   => $html,
749
-                'select' => ! empty ( $states )
749
+                'select' => !empty ($states)
750 750
             )
751 751
         );
752 752
 
@@ -760,11 +760,11 @@  discard block
 block discarded – undo
760 760
     public static function payment_form_refresh_prices() {
761 761
 
762 762
         // Check nonce.
763
-        check_ajax_referer( 'getpaid_form_nonce' );
763
+        check_ajax_referer('getpaid_form_nonce');
764 764
 
765 765
         // ... form fields...
766
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
767
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
766
+        if (empty($_POST['getpaid_payment_form_submission'])) {
767
+            _e('Error: Reload the page and try again.', 'invoicing');
768 768
             exit;
769 769
         }
770 770
 
@@ -772,18 +772,18 @@  discard block
 block discarded – undo
772 772
         $submission = new GetPaid_Payment_Form_Submission();
773 773
 
774 774
         // Do we have an error?
775
-        if ( ! empty( $submission->last_error ) ) {
775
+        if (!empty($submission->last_error)) {
776 776
             echo $submission->last_error;
777 777
             exit;
778 778
         }
779 779
 
780 780
         // Prepare the response.
781
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
781
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
782 782
         
783 783
         // Filter the response.
784
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
784
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
785 785
 
786
-        wp_send_json_success( $response );
786
+        wp_send_json_success($response);
787 787
     }
788 788
 
789 789
 }
Please login to merge, or discard this patch.