Passed
Push — master ( 97dd81...9ee829 )
by Brian
04:32
created
includes/class-wpinv-ajax.php 1 patch
Spacing   +325 added lines, -325 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 = (int) $_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
-            esc_html_e( "Provide the new user's email address", 'invoicing' );
218
+        if (empty($_GET['email'])) {
219
+            esc_html_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_email( $_GET['email'] );
225
-        if ( ! is_email( $email ) ) {
226
-            esc_html_e( 'Invalid email address', 'invoicing' );
224
+        $email = sanitize_email($_GET['email']);
225
+        if (!is_email($email)) {
226
+            esc_html_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,14 +258,14 @@  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
 			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
                 true
271 271
             );
@@ -273,29 +273,29 @@  discard block
 block discarded – undo
273 273
         }
274 274
 
275 275
         // Payment form or button?
276
-		if ( ! empty( $_GET['form'] ) ) {
277
-            $form = sanitize_text_field( urldecode( $_GET['form'] ) );
276
+		if (!empty($_GET['form'])) {
277
+            $form = sanitize_text_field(urldecode($_GET['form']));
278 278
 
279
-            if ( false !== strpos( $form, '|' ) ) {
280
-                $form_pos = strpos( $form, '|' );
281
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
282
-                $form     = substr( $form, 0, $form_pos );
279
+            if (false !== strpos($form, '|')) {
280
+                $form_pos = strpos($form, '|');
281
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
282
+                $form     = substr($form, 0, $form_pos);
283 283
 
284 284
                 // Retrieve appropriate payment form.
285
-                $payment_form = new GetPaid_Payment_Form( $form );
286
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
285
+                $payment_form = new GetPaid_Payment_Form($form);
286
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
287 287
 
288 288
                 $items    = array();
289 289
                 $item_ids = array();
290 290
 
291
-                foreach ( $_items as $item_id => $qty ) {
292
-                    if ( ! in_array( $item_id, $item_ids ) ) {
293
-                        $item = new GetPaid_Form_Item( $item_id );
294
-                        $item->set_quantity( $qty );
291
+                foreach ($_items as $item_id => $qty) {
292
+                    if (!in_array($item_id, $item_ids)) {
293
+                        $item = new GetPaid_Form_Item($item_id);
294
+                        $item->set_quantity($qty);
295 295
 
296
-                        if ( 0 == $qty ) {
297
-                            $item->set_allow_quantities( true );
298
-                            $item->set_is_required( false );
296
+                        if (0 == $qty) {
297
+                            $item->set_allow_quantities(true);
298
+                            $item->set_is_required(false);
299 299
                             $getpaid_force_checkbox = true;
300 300
                         }
301 301
 
@@ -304,32 +304,32 @@  discard block
 block discarded – undo
304 304
                     }
305 305
                 }
306 306
 
307
-                if ( ! $payment_form->is_default() ) {
307
+                if (!$payment_form->is_default()) {
308 308
 
309
-                    foreach ( $payment_form->get_items() as $item ) {
310
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
309
+                    foreach ($payment_form->get_items() as $item) {
310
+                        if (!in_array($item->get_id(), $item_ids)) {
311 311
                             $item_ids[] = $item->get_id();
312 312
                             $items[]    = $item;
313 313
                         }
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
-} elseif ( ! empty( $_GET['invoice'] ) ) {
329
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
328
+} elseif (!empty($_GET['invoice'])) {
329
+		    getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice']));
330 330
         } else {
331
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
332
-		    getpaid_display_item_payment_form( $items );
331
+			$items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item'])));
332
+		    getpaid_display_item_payment_form($items);
333 333
         }
334 334
 
335 335
         exit;
@@ -344,17 +344,17 @@  discard block
 block discarded – undo
344 344
     public static function payment_form() {
345 345
 
346 346
         // Check nonce.
347
-        check_ajax_referer( 'getpaid_form_nonce' );
347
+        check_ajax_referer('getpaid_form_nonce');
348 348
 
349 349
         // ... form fields...
350
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
351
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
350
+        if (empty($_POST['getpaid_payment_form_submission'])) {
351
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
352 352
             exit;
353 353
         }
354 354
 
355 355
         // Process the payment form.
356
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
357
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
356
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
357
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
358 358
         $checkout->process_checkout();
359 359
 
360 360
         exit;
@@ -367,55 +367,55 @@  discard block
 block discarded – undo
367 367
      */
368 368
     public static function get_payment_form_states_field() {
369 369
 
370
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
370
+        if (empty($_GET['country']) || empty($_GET['form'])) {
371 371
             exit;
372 372
         }
373 373
 
374
-        $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] );
374
+        $elements = getpaid_get_payment_form_elements((int) $_GET['form']);
375 375
 
376
-        if ( empty( $elements ) ) {
376
+        if (empty($elements)) {
377 377
             exit;
378 378
         }
379 379
 
380 380
         $address_fields = array();
381
-        foreach ( $elements as $element ) {
382
-            if ( 'address' === $element['type'] ) {
381
+        foreach ($elements as $element) {
382
+            if ('address' === $element['type']) {
383 383
                 $address_fields = $element;
384 384
                 break;
385 385
             }
386 386
         }
387 387
 
388
-        if ( empty( $address_fields ) ) {
388
+        if (empty($address_fields)) {
389 389
             exit;
390 390
         }
391 391
 
392
-        foreach ( $address_fields['fields'] as $address_field ) {
392
+        foreach ($address_fields['fields'] as $address_field) {
393 393
 
394
-            if ( 'wpinv_state' == $address_field['name'] ) {
394
+            if ('wpinv_state' == $address_field['name']) {
395 395
 
396
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
397
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
398
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
399
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
400
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
401
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
396
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
397
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
398
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
399
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
400
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
401
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
402 402
 
403
-                if ( ! empty( $address_field['required'] ) ) {
403
+                if (!empty($address_field['required'])) {
404 404
                     $label .= "<span class='text-danger'> *</span>";
405 405
                 }
406 406
 
407 407
                 $html = getpaid_get_states_select_markup(
408
-                    sanitize_text_field( $_GET['country'] ),
408
+                    sanitize_text_field($_GET['country']),
409 409
                     $value,
410 410
                     $placeholder,
411 411
                     $label,
412 412
                     $description,
413
-                    ! empty( $address_field['required'] ),
413
+                    !empty($address_field['required']),
414 414
                     $wrap_class,
415
-                    sanitize_text_field( $_GET['name'] )
415
+                    sanitize_text_field($_GET['name'])
416 416
                 );
417 417
 
418
-                wp_send_json_success( $html );
418
+                wp_send_json_success($html);
419 419
                 exit;
420 420
 
421 421
             }
@@ -430,66 +430,66 @@  discard block
 block discarded – undo
430 430
     public static function recalculate_invoice_totals() {
431 431
 
432 432
         // Verify nonce.
433
-        check_ajax_referer( 'wpinv-nonce' );
433
+        check_ajax_referer('wpinv-nonce');
434 434
 
435
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
435
+        if (!wpinv_current_user_can_manage_invoicing()) {
436 436
             exit;
437 437
         }
438 438
 
439 439
         // We need an invoice.
440
-        if ( empty( $_POST['post_id'] ) ) {
440
+        if (empty($_POST['post_id'])) {
441 441
             exit;
442 442
         }
443 443
 
444 444
         // Fetch the invoice.
445
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
445
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
446 446
 
447 447
         // Ensure it exists.
448
-        if ( ! $invoice->get_id() ) {
448
+        if (!$invoice->get_id()) {
449 449
             exit;
450 450
         }
451 451
 
452 452
         // Maybe set the country, state, currency.
453
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
454
-            if ( isset( $_POST[ $key ] ) ) {
453
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
454
+            if (isset($_POST[$key])) {
455 455
                 $method = "set_$key";
456
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
456
+                $invoice->$method(sanitize_text_field($_POST[$key]));
457 457
             }
458 458
         }
459 459
 
460 460
         // Maybe disable taxes.
461
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
461
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
462 462
 
463 463
         // Discount code.
464
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
465
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
466
-            if ( $discount->exists() ) {
467
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
464
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
465
+            $discount = new WPInv_Discount($invoice->get_discount_code());
466
+            if ($discount->exists()) {
467
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
468 468
             } else {
469
-                $invoice->remove_discount( 'discount_code' );
469
+                $invoice->remove_discount('discount_code');
470 470
             }
471 471
         }
472 472
 
473 473
         // Recalculate totals.
474 474
         $invoice->recalculate_total();
475 475
 
476
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
477
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
478
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
479
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
480
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
476
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
477
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
478
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
479
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
480
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
481 481
         }
482 482
 
483 483
         $totals = array(
484
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
485
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
486
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
484
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
485
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
486
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
487 487
             'total'    => $total,
488 488
         );
489 489
 
490
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
490
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
491 491
 
492
-        wp_send_json_success( compact( 'totals' ) );
492
+        wp_send_json_success(compact('totals'));
493 493
     }
494 494
 
495 495
     /**
@@ -498,33 +498,33 @@  discard block
 block discarded – undo
498 498
     public static function get_invoice_items() {
499 499
 
500 500
         // Verify nonce.
501
-        check_ajax_referer( 'wpinv-nonce' );
501
+        check_ajax_referer('wpinv-nonce');
502 502
 
503
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
503
+        if (!wpinv_current_user_can_manage_invoicing()) {
504 504
             exit;
505 505
         }
506 506
 
507 507
         // We need an invoice and items.
508
-        if ( empty( $_POST['post_id'] ) ) {
508
+        if (empty($_POST['post_id'])) {
509 509
             exit;
510 510
         }
511 511
 
512 512
         // Fetch the invoice.
513
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
513
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
514 514
 
515 515
         // Ensure it exists.
516
-        if ( ! $invoice->get_id() ) {
516
+        if (!$invoice->get_id()) {
517 517
             exit;
518 518
         }
519 519
 
520 520
         // Return an array of invoice items.
521 521
         $items = array();
522 522
 
523
-        foreach ( $invoice->get_items() as $item ) {
524
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() );
523
+        foreach ($invoice->get_items() as $item) {
524
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
525 525
         }
526 526
 
527
-        wp_send_json_success( compact( 'items' ) );
527
+        wp_send_json_success(compact('items'));
528 528
     }
529 529
 
530 530
     /**
@@ -533,50 +533,50 @@  discard block
 block discarded – undo
533 533
     public static function edit_invoice_item() {
534 534
 
535 535
         // Verify nonce.
536
-        check_ajax_referer( 'wpinv-nonce' );
536
+        check_ajax_referer('wpinv-nonce');
537 537
 
538
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
538
+        if (!wpinv_current_user_can_manage_invoicing()) {
539 539
             exit;
540 540
         }
541 541
 
542 542
         // We need an invoice and item details.
543
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
543
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
544 544
             exit;
545 545
         }
546 546
 
547 547
         // Fetch the invoice.
548
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
548
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
549 549
 
550 550
         // Ensure it exists and its not been paid for.
551
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
551
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
552 552
             exit;
553 553
         }
554 554
 
555 555
         // Format the data.
556
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
556
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
557 557
 
558 558
         // Ensure that we have an item id.
559
-        if ( empty( $data['id'] ) ) {
559
+        if (empty($data['id'])) {
560 560
             exit;
561 561
         }
562 562
 
563 563
         // Abort if the invoice does not have the specified item.
564
-        $item = $invoice->get_item( (int) $data['id'] );
564
+        $item = $invoice->get_item((int) $data['id']);
565 565
 
566
-        if ( empty( $item ) ) {
566
+        if (empty($item)) {
567 567
             exit;
568 568
         }
569 569
 
570 570
         // Update the item.
571
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
572
-        $item->set_name( sanitize_text_field( $data['name'] ) );
573
-        $item->set_description( wp_kses_post( $data['description'] ) );
574
-        $item->set_quantity( floatval( $data['quantity'] ) );
571
+        $item->set_price(getpaid_standardize_amount($data['price']));
572
+        $item->set_name(sanitize_text_field($data['name']));
573
+        $item->set_description(wp_kses_post($data['description']));
574
+        $item->set_quantity(floatval($data['quantity']));
575 575
 
576 576
         // Add it to the invoice.
577
-        $error = $invoice->add_item( $item );
577
+        $error = $invoice->add_item($item);
578 578
         $alert = false;
579
-        if ( is_wp_error( $error ) ) {
579
+        if (is_wp_error($error)) {
580 580
             $alert = $error->get_error_message();
581 581
         }
582 582
 
@@ -589,11 +589,11 @@  discard block
 block discarded – undo
589 589
         // Return an array of invoice items.
590 590
         $items = array();
591 591
 
592
-        foreach ( $invoice->get_items() as $item ) {
593
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
592
+        foreach ($invoice->get_items() as $item) {
593
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
594 594
         }
595 595
 
596
-        wp_send_json_success( compact( 'items', 'alert' ) );
596
+        wp_send_json_success(compact('items', 'alert'));
597 597
     }
598 598
 
599 599
     /**
@@ -602,53 +602,53 @@  discard block
 block discarded – undo
602 602
     public static function create_invoice_item() {
603 603
 
604 604
         // Verify nonce.
605
-        check_ajax_referer( 'wpinv-nonce' );
605
+        check_ajax_referer('wpinv-nonce');
606 606
 
607
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
607
+        if (!wpinv_current_user_can_manage_invoicing()) {
608 608
             exit;
609 609
         }
610 610
 
611 611
         // We need an invoice and item details.
612
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
612
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
613 613
             exit;
614 614
         }
615 615
 
616 616
         // Fetch the invoice.
617
-        $invoice = new WPInv_Invoice( intval( $_POST['invoice_id'] ) );
617
+        $invoice = new WPInv_Invoice(intval($_POST['invoice_id']));
618 618
 
619 619
         // Ensure it exists and its not been paid for.
620
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
620
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
621 621
             exit;
622 622
         }
623 623
 
624 624
         // Format the data.
625
-        $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) );
625
+        $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick']));
626 626
 
627 627
         $item = new WPInv_Item();
628
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
629
-        $item->set_name( sanitize_text_field( $data['name'] ) );
630
-        $item->set_description( wp_kses_post( $data['description'] ) );
631
-        $item->set_type( sanitize_text_field( $data['type'] ) );
632
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
633
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
634
-        $item->set_status( 'publish' );
628
+        $item->set_price(getpaid_standardize_amount($data['price']));
629
+        $item->set_name(sanitize_text_field($data['name']));
630
+        $item->set_description(wp_kses_post($data['description']));
631
+        $item->set_type(sanitize_text_field($data['type']));
632
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
633
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
634
+        $item->set_status('publish');
635 635
         $item->save();
636 636
 
637
-        if ( ! $item->exists() ) {
638
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
639
-            wp_send_json_success( compact( 'alert' ) );
637
+        if (!$item->exists()) {
638
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
639
+            wp_send_json_success(compact('alert'));
640 640
         }
641 641
 
642
-        $item = new GetPaid_Form_Item( $item->get_id() );
643
-        $item->set_quantity( floatval( $data['qty'] ) );
642
+        $item = new GetPaid_Form_Item($item->get_id());
643
+        $item->set_quantity(floatval($data['qty']));
644 644
 
645 645
         // Add it to the invoice.
646
-        $error = $invoice->add_item( $item );
646
+        $error = $invoice->add_item($item);
647 647
         $alert = false;
648 648
 
649
-        if ( is_wp_error( $error ) ) {
649
+        if (is_wp_error($error)) {
650 650
             $alert = $error->get_error_message();
651
-            wp_send_json_success( compact( 'alert' ) );
651
+            wp_send_json_success(compact('alert'));
652 652
          }
653 653
 
654 654
         // Update totals.
@@ -661,9 +661,9 @@  discard block
 block discarded – undo
661 661
         $invoice->recalculate_total();
662 662
         $invoice->save();
663 663
         ob_start();
664
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
664
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
665 665
         $row = ob_get_clean();
666
-        wp_send_json_success( compact( 'row' ) );
666
+        wp_send_json_success(compact('row'));
667 667
     }
668 668
 
669 669
     /**
@@ -672,33 +672,33 @@  discard block
 block discarded – undo
672 672
     public static function remove_invoice_item() {
673 673
 
674 674
         // Verify nonce.
675
-        check_ajax_referer( 'wpinv-nonce' );
675
+        check_ajax_referer('wpinv-nonce');
676 676
 
677
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
677
+        if (!wpinv_current_user_can_manage_invoicing()) {
678 678
             exit;
679 679
         }
680 680
 
681 681
         // We need an invoice and an item.
682
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
682
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
683 683
             exit;
684 684
         }
685 685
 
686 686
         // Fetch the invoice.
687
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
687
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
688 688
 
689 689
         // Ensure it exists and its not been paid for.
690
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
690
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
691 691
             exit;
692 692
         }
693 693
 
694 694
         // Abort if the invoice does not have the specified item.
695
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
695
+        $item = $invoice->get_item((int) $_POST['item_id']);
696 696
 
697
-        if ( empty( $item ) ) {
697
+        if (empty($item)) {
698 698
             exit;
699 699
         }
700 700
 
701
-        $invoice->remove_item( (int) $_POST['item_id'] );
701
+        $invoice->remove_item((int) $_POST['item_id']);
702 702
 
703 703
         // Update totals.
704 704
         $invoice->recalculate_total();
@@ -709,11 +709,11 @@  discard block
 block discarded – undo
709 709
         // Return an array of invoice items.
710 710
         $items = array();
711 711
 
712
-        foreach ( $invoice->get_items() as $item ) {
713
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
712
+        foreach ($invoice->get_items() as $item) {
713
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
714 714
         }
715 715
 
716
-        wp_send_json_success( compact( 'items' ) );
716
+        wp_send_json_success(compact('items'));
717 717
     }
718 718
 
719 719
     /**
@@ -722,68 +722,68 @@  discard block
 block discarded – undo
722 722
     public static function recalculate_full_prices() {
723 723
 
724 724
         // Verify nonce.
725
-        check_ajax_referer( 'wpinv-nonce' );
725
+        check_ajax_referer('wpinv-nonce');
726 726
 
727
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
727
+        if (!wpinv_current_user_can_manage_invoicing()) {
728 728
             exit;
729 729
         }
730 730
 
731 731
         // We need an invoice and item.
732
-        if ( empty( $_POST['post_id'] ) ) {
732
+        if (empty($_POST['post_id'])) {
733 733
             exit;
734 734
         }
735 735
 
736 736
         // Fetch the invoice.
737
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
737
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
738 738
         $alert   = false;
739 739
 
740 740
         // Ensure it exists and its not been paid for.
741
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
741
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
742 742
             exit;
743 743
         }
744 744
 
745
-        $invoice->set_items( array() );
745
+        $invoice->set_items(array());
746 746
 
747
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
747
+        if (!empty($_POST['getpaid_items'])) {
748 748
 
749
-            foreach ( wp_kses_post_deep( $_POST['getpaid_items'] ) as $item_id => $args ) {
750
-                $item = new GetPaid_Form_Item( $item_id );
749
+            foreach (wp_kses_post_deep($_POST['getpaid_items']) as $item_id => $args) {
750
+                $item = new GetPaid_Form_Item($item_id);
751 751
 
752
-                if ( $item->exists() ) {
753
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
754
-                    $item->set_quantity( floatval( $args['quantity'] ) );
755
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
756
-                    $item->set_description( wp_kses_post( $args['description'] ) );
757
-                    $invoice->add_item( $item );
752
+                if ($item->exists()) {
753
+                    $item->set_price(getpaid_standardize_amount($args['price']));
754
+                    $item->set_quantity(floatval($args['quantity']));
755
+                    $item->set_name(sanitize_text_field($args['name']));
756
+                    $item->set_description(wp_kses_post($args['description']));
757
+                    $invoice->add_item($item);
758 758
                 }
759 759
             }
760 760
 }
761 761
 
762
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
762
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
763 763
 
764 764
         // Maybe set the country, state, currency.
765
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
766
-            if ( isset( $_POST[ $key ] ) ) {
767
-                $_key   = str_replace( 'wpinv_', '', $key );
765
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
766
+            if (isset($_POST[$key])) {
767
+                $_key   = str_replace('wpinv_', '', $key);
768 768
                 $method = "set_$_key";
769
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
769
+                $invoice->$method(sanitize_text_field($_POST[$key]));
770 770
             }
771 771
         }
772 772
 
773
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
774
-        if ( $discount->exists() ) {
775
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
773
+        $discount = new WPInv_Discount($invoice->get_discount_code());
774
+        if ($discount->exists()) {
775
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
776 776
         } else {
777
-            $invoice->remove_discount( 'discount_code' );
777
+            $invoice->remove_discount('discount_code');
778 778
         }
779 779
 
780 780
         // Save the invoice.
781 781
         $invoice->recalculate_total();
782 782
         $invoice->save();
783 783
         ob_start();
784
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
784
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
785 785
         $table = ob_get_clean();
786
-        wp_send_json_success( compact( 'table' ) );
786
+        wp_send_json_success(compact('table'));
787 787
     }
788 788
 
789 789
     /**
@@ -792,42 +792,42 @@  discard block
 block discarded – undo
792 792
     public static function admin_add_invoice_item() {
793 793
 
794 794
         // Verify nonce.
795
-        check_ajax_referer( 'wpinv-nonce' );
795
+        check_ajax_referer('wpinv-nonce');
796 796
 
797
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
797
+        if (!wpinv_current_user_can_manage_invoicing()) {
798 798
             exit;
799 799
         }
800 800
 
801 801
         // We need an invoice and item.
802
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
802
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
803 803
             exit;
804 804
         }
805 805
 
806 806
         // Fetch the invoice.
807
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
807
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
808 808
         $alert   = false;
809 809
 
810 810
         // Ensure it exists and its not been paid for.
811
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
811
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
812 812
             exit;
813 813
         }
814 814
 
815 815
         // Add the item.
816
-        $item  = new GetPaid_Form_Item( (int) $_POST['item_id'] );
817
-        $error = $invoice->add_item( $item );
816
+        $item  = new GetPaid_Form_Item((int) $_POST['item_id']);
817
+        $error = $invoice->add_item($item);
818 818
 
819
-        if ( is_wp_error( $error ) ) {
819
+        if (is_wp_error($error)) {
820 820
             $alert = $error->get_error_message();
821
-            wp_send_json_success( compact( 'alert' ) );
821
+            wp_send_json_success(compact('alert'));
822 822
         }
823 823
 
824 824
         // Save the invoice.
825 825
         $invoice->recalculate_total();
826 826
         $invoice->save();
827 827
         ob_start();
828
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
828
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
829 829
         $row = ob_get_clean();
830
-        wp_send_json_success( compact( 'row' ) );
830
+        wp_send_json_success(compact('row'));
831 831
     }
832 832
 
833 833
     /**
@@ -836,39 +836,39 @@  discard block
 block discarded – undo
836 836
     public static function add_invoice_items() {
837 837
 
838 838
         // Verify nonce.
839
-        check_ajax_referer( 'wpinv-nonce' );
839
+        check_ajax_referer('wpinv-nonce');
840 840
 
841
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
841
+        if (!wpinv_current_user_can_manage_invoicing()) {
842 842
             exit;
843 843
         }
844 844
 
845 845
         // We need an invoice and items.
846
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
846
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
847 847
             exit;
848 848
         }
849 849
 
850 850
         // Fetch the invoice.
851
-        $invoice = new WPInv_Invoice( intval( $_POST['post_id'] ) );
851
+        $invoice = new WPInv_Invoice(intval($_POST['post_id']));
852 852
         $alert   = false;
853 853
 
854 854
         // Ensure it exists and its not been paid for.
855
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
855
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
856 856
             exit;
857 857
         }
858 858
 
859 859
         // Add the items.
860
-        foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) {
860
+        foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) {
861 861
 
862
-            $item = new GetPaid_Form_Item( (int) $data['id'] );
862
+            $item = new GetPaid_Form_Item((int) $data['id']);
863 863
 
864
-            if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) {
865
-                $item->set_quantity( floatval( $data['qty'] ) );
864
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
865
+                $item->set_quantity(floatval($data['qty']));
866 866
             }
867 867
 
868
-            if ( $item->get_id() > 0 ) {
869
-                $error = $invoice->add_item( $item );
868
+            if ($item->get_id() > 0) {
869
+                $error = $invoice->add_item($item);
870 870
 
871
-                if ( is_wp_error( $error ) ) {
871
+                if (is_wp_error($error)) {
872 872
                     $alert = $error->get_error_message();
873 873
                 }
874 874
 }
@@ -881,11 +881,11 @@  discard block
 block discarded – undo
881 881
         // Return an array of invoice items.
882 882
         $items = array();
883 883
 
884
-        foreach ( $invoice->get_items() as $item ) {
885
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
884
+        foreach ($invoice->get_items() as $item) {
885
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
886 886
         }
887 887
 
888
-        wp_send_json_success( compact( 'items', 'alert' ) );
888
+        wp_send_json_success(compact('items', 'alert'));
889 889
     }
890 890
 
891 891
     /**
@@ -894,15 +894,15 @@  discard block
 block discarded – undo
894 894
     public static function get_invoicing_items() {
895 895
 
896 896
         // Verify nonce.
897
-        check_ajax_referer( 'wpinv-nonce' );
897
+        check_ajax_referer('wpinv-nonce');
898 898
 
899
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
899
+        if (!wpinv_current_user_can_manage_invoicing()) {
900 900
             exit;
901 901
         }
902 902
 
903 903
         // We need a search term.
904
-        if ( empty( $_GET['search'] ) ) {
905
-            wp_send_json_success( array() );
904
+        if (empty($_GET['search'])) {
905
+            wp_send_json_success(array());
906 906
         }
907 907
 
908 908
         // Retrieve items.
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
             'orderby'        => 'title',
912 912
             'order'          => 'ASC',
913 913
             'posts_per_page' => -1,
914
-            'post_status'    => array( 'publish' ),
915
-            's'              => sanitize_text_field( urldecode( $_GET['search'] ) ),
914
+            'post_status'    => array('publish'),
915
+            's'              => sanitize_text_field(urldecode($_GET['search'])),
916 916
             'meta_query'     => array(
917 917
                 array(
918 918
                     'key'     => '_wpinv_type',
@@ -922,25 +922,25 @@  discard block
 block discarded – undo
922 922
             ),
923 923
         );
924 924
 
925
-        if ( ! empty( $_GET['ignore'] ) ) {
926
-            $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) );
925
+        if (!empty($_GET['ignore'])) {
926
+            $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore']));
927 927
         }
928 928
 
929
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
929
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
930 930
         $data  = array();
931 931
 
932
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) );
932
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id']));
933 933
 
934
-        foreach ( $items as $item ) {
935
-            $item      = new GetPaid_Form_Item( $item );
934
+        foreach ($items as $item) {
935
+            $item = new GetPaid_Form_Item($item);
936 936
             $data[] = array(
937 937
                 'id'        => (int) $item->get_id(),
938
-                'text'      => strip_tags( $item->get_name() ),
939
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
938
+                'text'      => strip_tags($item->get_name()),
939
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
940 940
             );
941 941
         }
942 942
 
943
-        wp_send_json_success( $data );
943
+        wp_send_json_success($data);
944 944
 
945 945
     }
946 946
 
@@ -950,37 +950,37 @@  discard block
 block discarded – undo
950 950
     public static function get_customers() {
951 951
 
952 952
         // Verify nonce.
953
-        check_ajax_referer( 'wpinv-nonce' );
953
+        check_ajax_referer('wpinv-nonce');
954 954
 
955
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
955
+        if (!wpinv_current_user_can_manage_invoicing()) {
956 956
             exit;
957 957
         }
958 958
 
959 959
         // We need a search term.
960
-        if ( empty( $_GET['search'] ) ) {
961
-            wp_send_json_success( array() );
960
+        if (empty($_GET['search'])) {
961
+            wp_send_json_success(array());
962 962
         }
963 963
 
964 964
         // Retrieve customers.
965 965
 
966 966
         $customer_args = array(
967
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
967
+            'fields'         => array('ID', 'user_email', 'display_name'),
968 968
             'orderby'        => 'display_name',
969
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
970
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
969
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
970
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
971 971
         );
972 972
 
973
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
973
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
974 974
         $data      = array();
975 975
 
976
-        foreach ( $customers as $customer ) {
976
+        foreach ($customers as $customer) {
977 977
             $data[] = array(
978 978
                 'id'   => (int) $customer->ID,
979
-                'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
979
+                'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
980 980
             );
981 981
         }
982 982
 
983
-        wp_send_json_success( $data );
983
+        wp_send_json_success($data);
984 984
 
985 985
     }
986 986
 
@@ -990,28 +990,28 @@  discard block
 block discarded – undo
990 990
     public static function get_aui_states_field() {
991 991
 
992 992
         // Verify nonce.
993
-        check_ajax_referer( 'wpinv-nonce' );
993
+        check_ajax_referer('wpinv-nonce');
994 994
 
995 995
         // We need a country.
996
-        if ( empty( $_GET['country'] ) ) {
996
+        if (empty($_GET['country'])) {
997 997
             exit;
998 998
         }
999 999
 
1000
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1001
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1002
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1003
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1000
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1001
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1002
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1003
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1004 1004
 
1005
-        if ( empty( $states ) ) {
1005
+        if (empty($states)) {
1006 1006
 
1007 1007
             $html = aui()->input(
1008 1008
                 array(
1009 1009
                     'type'        => 'text',
1010 1010
                     'id'          => 'wpinv_state',
1011 1011
                     'name'        => $name,
1012
-                    'label'       => __( 'State', 'invoicing' ),
1012
+                    'label'       => __('State', 'invoicing'),
1013 1013
                     'label_type'  => 'vertical',
1014
-                    'placeholder' => __( 'State', 'invoicing' ),
1014
+                    'placeholder' => __('State', 'invoicing'),
1015 1015
                     'class'       => $class,
1016 1016
                     'value'       => $state,
1017 1017
                 )
@@ -1023,9 +1023,9 @@  discard block
 block discarded – undo
1023 1023
                 array(
1024 1024
                     'id'               => 'wpinv_state',
1025 1025
                     'name'             => $name,
1026
-                    'label'            => __( 'State', 'invoicing' ),
1026
+                    'label'            => __('State', 'invoicing'),
1027 1027
                     'label_type'       => 'vertical',
1028
-                    'placeholder'      => __( 'Select a state', 'invoicing' ),
1028
+                    'placeholder'      => __('Select a state', 'invoicing'),
1029 1029
                     'class'            => $class,
1030 1030
                     'value'            => $state,
1031 1031
                     'options'          => $states,
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
         wp_send_json_success(
1040 1040
             array(
1041 1041
                 'html'   => $html,
1042
-                'select' => ! empty( $states ),
1042
+                'select' => !empty($states),
1043 1043
             )
1044 1044
         );
1045 1045
 
@@ -1053,11 +1053,11 @@  discard block
 block discarded – undo
1053 1053
     public static function payment_form_refresh_prices() {
1054 1054
 
1055 1055
         // Check nonce.
1056
-        check_ajax_referer( 'getpaid_form_nonce' );
1056
+        check_ajax_referer('getpaid_form_nonce');
1057 1057
 
1058 1058
         // ... form fields...
1059
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1060
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
1059
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1060
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
1061 1061
             exit;
1062 1062
         }
1063 1063
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
         $submission = new GetPaid_Payment_Form_Submission();
1066 1066
 
1067 1067
         // Do we have an error?
1068
-        if ( ! empty( $submission->last_error ) ) {
1068
+        if (!empty($submission->last_error)) {
1069 1069
             wp_send_json_error(
1070 1070
                 array(
1071 1071
                     'code'  => $submission->last_error_code,
@@ -1075,12 +1075,12 @@  discard block
 block discarded – undo
1075 1075
         }
1076 1076
 
1077 1077
         // Prepare the response.
1078
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1078
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1079 1079
 
1080 1080
         // Filter the response.
1081
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1081
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1082 1082
 
1083
-        wp_send_json_success( $response );
1083
+        wp_send_json_success($response);
1084 1084
     }
1085 1085
 
1086 1086
     /**
@@ -1092,63 +1092,63 @@  discard block
 block discarded – undo
1092 1092
 	public static function file_upload() {
1093 1093
 
1094 1094
         // Check nonce.
1095
-        check_ajax_referer( 'getpaid_form_nonce' );
1095
+        check_ajax_referer('getpaid_form_nonce');
1096 1096
 
1097
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1098
-            wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 );
1097
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1098
+            wp_die(esc_html_e('Bad Request', 'invoicing'), 400);
1099 1099
         }
1100 1100
 
1101 1101
         // Fetch form.
1102
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1102
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1103 1103
 
1104
-        if ( ! $form->is_active() ) {
1105
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1104
+        if (!$form->is_active()) {
1105
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1106 1106
         }
1107 1107
 
1108 1108
         // Fetch appropriate field.
1109
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1110
-        if ( empty( $upload_field ) ) {
1111
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1109
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1110
+        if (empty($upload_field)) {
1111
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1112 1112
         }
1113 1113
 
1114 1114
         // Prepare allowed file types.
1115
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1115
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1116 1116
         $all_types  = getpaid_get_allowed_mime_types();
1117 1117
         $mime_types = array();
1118 1118
 
1119
-        foreach ( $file_types as $file_type ) {
1120
-            if ( isset( $all_types[ $file_type ] ) ) {
1121
-                $mime_types[] = $all_types[ $file_type ];
1119
+        foreach ($file_types as $file_type) {
1120
+            if (isset($all_types[$file_type])) {
1121
+                $mime_types[] = $all_types[$file_type];
1122 1122
             }
1123 1123
         }
1124 1124
 
1125
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1126
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1125
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1126
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1127 1127
         }
1128 1128
 
1129 1129
         // Upload file.
1130
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1131
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1130
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1131
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1132 1132
 
1133 1133
         $uploaded = wp_upload_bits(
1134 1134
             $file_name,
1135 1135
             null,
1136
-            file_get_contents( $_FILES['file']['tmp_name'] )
1136
+            file_get_contents($_FILES['file']['tmp_name'])
1137 1137
         );
1138 1138
 
1139
-        if ( ! empty( $uploaded['error'] ) ) {
1140
-            wp_send_json_error( $uploaded['error'] );
1139
+        if (!empty($uploaded['error'])) {
1140
+            wp_send_json_error($uploaded['error']);
1141 1141
         }
1142 1142
 
1143 1143
         // Retrieve response.
1144 1144
         $response = sprintf(
1145 1145
             '<input type="hidden" name="%s[%s]" value="%s" />',
1146
-            esc_attr( sanitize_text_field( $_POST['field_name'] ) ),
1147
-            esc_url( $uploaded['url'] ),
1148
-            esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) )
1146
+            esc_attr(sanitize_text_field($_POST['field_name'])),
1147
+            esc_url($uploaded['url']),
1148
+            esc_attr(sanitize_text_field(strtolower($_FILES['file']['name'])))
1149 1149
         );
1150 1150
 
1151
-        wp_send_json_success( $response );
1151
+        wp_send_json_success($response);
1152 1152
 
1153 1153
 	}
1154 1154
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 2 patches
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -12,38 +12,38 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
36
-
37
-		// (Maybe) set form items.
38
-		if ( isset( $data['getpaid-form-items'] ) ) {
39
-
40
-			// Confirm items key.
41
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
42
-			if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
44
-			}
45
-
46
-			$items    = array();
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36
+
37
+        // (Maybe) set form items.
38
+        if ( isset( $data['getpaid-form-items'] ) ) {
39
+
40
+            // Confirm items key.
41
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
42
+            if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
+                throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
44
+            }
45
+
46
+            $items    = array();
47 47
             $item_ids = array();
48 48
 
49 49
             foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
@@ -69,61 +69,61 @@  discard block
 block discarded – undo
69 69
                         $items[]    = $item;
70 70
                     }
71 71
                 }
72
-			}
72
+            }
73 73
 
74 74
             $payment_form->set_items( $items );
75 75
 
76
-		}
77
-
78
-		// Process each individual item.
79
-		foreach ( $payment_form->get_items() as $item ) {
80
-			$this->process_item( $item, $selected_items, $submission );
81
-		}
82
-
83
-	}
76
+        }
84 77
 
85
-	/**
86
-	 * Process a single item.
87
-	 *
88
-	 * @param GetPaid_Form_Item $item
89
-	 * @param array $selected_items
90
-	 * @param GetPaid_Payment_Form_Submission $submission
91
-	 */
92
-	public function process_item( $item, $selected_items, $submission ) {
78
+        // Process each individual item.
79
+        foreach ( $payment_form->get_items() as $item ) {
80
+            $this->process_item( $item, $selected_items, $submission );
81
+        }
93 82
 
94
-		// Abort if this is an optional item and it has not been selected.
95
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
96
-			return;
97
-		}
83
+    }
98 84
 
99
-		// (maybe) let customers change the quantities and prices.
100
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
101
-
102
-			// Maybe change the quantities.
103
-			if ( $item->allows_quantities() ) {
104
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
105
-			}
85
+    /**
86
+     * Process a single item.
87
+     *
88
+     * @param GetPaid_Form_Item $item
89
+     * @param array $selected_items
90
+     * @param GetPaid_Payment_Form_Submission $submission
91
+     */
92
+    public function process_item( $item, $selected_items, $submission ) {
93
+
94
+        // Abort if this is an optional item and it has not been selected.
95
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
96
+            return;
97
+        }
98
+
99
+        // (maybe) let customers change the quantities and prices.
100
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
101
+
102
+            // Maybe change the quantities.
103
+            if ( $item->allows_quantities() ) {
104
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
105
+            }
106 106
 
107
-			// Maybe change the price.
108
-			if ( $item->user_can_set_their_price() ) {
109
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
107
+            // Maybe change the price.
108
+            if ( $item->user_can_set_their_price() ) {
109
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
110 110
 
111
-				if ( $item->get_minimum_price() > $price ) {
112
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
113
-				}
111
+                if ( $item->get_minimum_price() > $price ) {
112
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
113
+                }
114 114
 
115
-				$item->set_price( $price );
115
+                $item->set_price( $price );
116 116
 
117
-			}
118
-		}
117
+            }
118
+        }
119 119
 
120
-		if ( 0 == $item->get_quantity() ) {
121
-			return;
122
-		}
120
+        if ( 0 == $item->get_quantity() ) {
121
+            return;
122
+        }
123 123
 
124
-		// Save the item.
125
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
124
+        // Save the item.
125
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
126 126
 
127
-	}
127
+    }
128 128
 
129 129
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission itemss class
@@ -23,37 +23,37 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$data         = $submission->get_data();
29 29
 		$payment_form = $submission->get_payment_form();
30 30
 
31 31
 		// Prepare the selected items.
32 32
 		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
33
+		if (!empty($data['getpaid-items'])) {
34
+			$selected_items = wpinv_clean($data['getpaid-items']);
35 35
 		}
36 36
 
37 37
 		// (Maybe) set form items.
38
-		if ( isset( $data['getpaid-form-items'] ) ) {
38
+		if (isset($data['getpaid-form-items'])) {
39 39
 
40 40
 			// Confirm items key.
41
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
42
-			if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
41
+			$form_items = wpinv_clean($data['getpaid-form-items']);
42
+			if (!isset($data['getpaid-form-items-key']) || $data['getpaid-form-items-key'] !== md5(NONCE_KEY . AUTH_KEY . $form_items)) {
43
+				throw new Exception(__('We could not validate the form items. Please reload the page and try again.', 'invoicing'));
44 44
 			}
45 45
 
46
-			$items    = array();
46
+			$items = array();
47 47
             $item_ids = array();
48 48
 
49
-            foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
50
-                if ( ! in_array( $item_id, $item_ids ) ) {
51
-                    $item = new GetPaid_Form_Item( $item_id );
52
-                    $item->set_quantity( $qty );
49
+            foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) {
50
+                if (!in_array($item_id, $item_ids)) {
51
+                    $item = new GetPaid_Form_Item($item_id);
52
+                    $item->set_quantity($qty);
53 53
 
54
-                    if ( 0 == $qty ) {
55
-                        $item->set_allow_quantities( true );
56
-                        $item->set_is_required( false );
54
+                    if (0 == $qty) {
55
+                        $item->set_allow_quantities(true);
56
+                        $item->set_is_required(false);
57 57
                     }
58 58
 
59 59
                     $item_ids[] = $item->get_id();
@@ -61,23 +61,23 @@  discard block
 block discarded – undo
61 61
                 }
62 62
             }
63 63
 
64
-            if ( ! $payment_form->is_default() ) {
64
+            if (!$payment_form->is_default()) {
65 65
 
66
-                foreach ( $payment_form->get_items() as $item ) {
67
-                    if ( ! in_array( $item->get_id(), $item_ids ) ) {
66
+                foreach ($payment_form->get_items() as $item) {
67
+                    if (!in_array($item->get_id(), $item_ids)) {
68 68
                         $item_ids[] = $item->get_id();
69 69
                         $items[]    = $item;
70 70
                     }
71 71
                 }
72 72
 			}
73 73
 
74
-            $payment_form->set_items( $items );
74
+            $payment_form->set_items($items);
75 75
 
76 76
 		}
77 77
 
78 78
 		// Process each individual item.
79
-		foreach ( $payment_form->get_items() as $item ) {
80
-			$this->process_item( $item, $selected_items, $submission );
79
+		foreach ($payment_form->get_items() as $item) {
80
+			$this->process_item($item, $selected_items, $submission);
81 81
 		}
82 82
 
83 83
 	}
@@ -89,40 +89,40 @@  discard block
 block discarded – undo
89 89
 	 * @param array $selected_items
90 90
 	 * @param GetPaid_Payment_Form_Submission $submission
91 91
 	 */
92
-	public function process_item( $item, $selected_items, $submission ) {
92
+	public function process_item($item, $selected_items, $submission) {
93 93
 
94 94
 		// Abort if this is an optional item and it has not been selected.
95
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
95
+		if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
96 96
 			return;
97 97
 		}
98 98
 
99 99
 		// (maybe) let customers change the quantities and prices.
100
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
100
+		if (isset($selected_items[$item->get_id()])) {
101 101
 
102 102
 			// Maybe change the quantities.
103
-			if ( $item->allows_quantities() ) {
104
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
103
+			if ($item->allows_quantities()) {
104
+				$item->set_quantity((float) $selected_items[$item->get_id()]['quantity']);
105 105
 			}
106 106
 
107 107
 			// Maybe change the price.
108
-			if ( $item->user_can_set_their_price() ) {
109
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
108
+			if ($item->user_can_set_their_price()) {
109
+				$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
110 110
 
111
-				if ( $item->get_minimum_price() > $price ) {
112
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
111
+				if ($item->get_minimum_price() > $price) {
112
+					throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price())));
113 113
 				}
114 114
 
115
-				$item->set_price( $price );
115
+				$item->set_price($price);
116 116
 
117 117
 			}
118 118
 		}
119 119
 
120
-		if ( 0 == $item->get_quantity() ) {
120
+		if (0 == $item->get_quantity()) {
121 121
 			return;
122 122
 		}
123 123
 
124 124
 		// Save the item.
125
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
125
+		$this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission);
126 126
 
127 127
 	}
128 128
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 2 patches
Indentation   +571 added lines, -571 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'        => 'draft',
34
-		'version'       => '',
35
-		'date_created'  => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'        => 'draft',
34
+        'version'       => '',
35
+        'date_created'  => null,
36 36
         'date_modified' => null,
37 37
         'name'          => '',
38 38
         'author'        => 1,
39 39
         'elements'      => null,
40
-		'items'         => null,
41
-		'earned'        => 0,
42
-		'refunded'      => 0,
43
-		'cancelled'     => 0,
44
-		'failed'        => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'         => null,
41
+        'earned'        => 0,
42
+        'refunded'      => 0,
43
+        'cancelled'     => 0,
44
+        'failed'        => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,356 +114,356 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'      => 'gtscicd',
237
-					'name'    => 'gtscicd',
238
-					'type'    => 'gateway_select',
239
-					'premade' => true,
234
+                $_elements[] = array(
235
+                    'text'    => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'      => 'gtscicd',
237
+                    'name'    => 'gtscicd',
238
+                    'type'    => 'gateway_select',
239
+                    'premade' => true,
240 240
 
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266 266
 
267
-		// Convert the items.
268
-		$prepared = array();
267
+        // Convert the items.
268
+        $prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+        foreach ( $items as $key => $value ) {
271 271
 
272
-			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
272
+            // Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
274 274
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
278 278
 
279
-				continue;
279
+                continue;
280 280
 
281
-			}
281
+            }
282 282
 
283
-			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
283
+            // $item_id => $quantity (buy buttons)
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
286 286
 
287
-				if ( $item->can_purchase() ) {
287
+                if ( $item->can_purchase() ) {
288 288
 
289
-					$value = (float) $value;
290
-					$item->set_quantity( $value );
291
-					if ( 0 == $value ) {
292
-						$item->set_quantity( 1 );
293
-						$item->set_allow_quantities( true );
294
-					}
289
+                    $value = (float) $value;
290
+                    $item->set_quantity( $value );
291
+                    if ( 0 == $value ) {
292
+                        $item->set_quantity( 1 );
293
+                        $item->set_allow_quantities( true );
294
+                    }
295 295
 
296
-					$prepared[] = $item;
297
-				}
296
+                    $prepared[] = $item;
297
+                }
298 298
 
299
-				continue;
300
-			}
299
+                continue;
300
+            }
301 301
 
302
-			// Items saved via payment forms editor.
303
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
302
+            // Items saved via payment forms editor.
303
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
304 304
 
305
-				$item = new GetPaid_Form_Item( $value['id'] );
305
+                $item = new GetPaid_Form_Item( $value['id'] );
306 306
 
307
-				if ( ! $item->can_purchase() ) {
308
-					continue;
309
-				}
307
+                if ( ! $item->can_purchase() ) {
308
+                    continue;
309
+                }
310 310
 
311
-				// Sub-total (Cart items).
312
-				if ( isset( $value['subtotal'] ) ) {
313
-					$item->set_price( $value['subtotal'] );
314
-				}
311
+                // Sub-total (Cart items).
312
+                if ( isset( $value['subtotal'] ) ) {
313
+                    $item->set_price( $value['subtotal'] );
314
+                }
315 315
 
316
-				if ( isset( $value['quantity'] ) ) {
317
-					$item->set_quantity( $value['quantity'] );
318
-				}
316
+                if ( isset( $value['quantity'] ) ) {
317
+                    $item->set_quantity( $value['quantity'] );
318
+                }
319 319
 
320
-				if ( isset( $value['allow_quantities'] ) ) {
321
-					$item->set_allow_quantities( $value['allow_quantities'] );
322
-				}
320
+                if ( isset( $value['allow_quantities'] ) ) {
321
+                    $item->set_allow_quantities( $value['allow_quantities'] );
322
+                }
323 323
 
324
-				if ( isset( $value['required'] ) ) {
325
-					$item->set_is_required( $value['required'] );
326
-				}
324
+                if ( isset( $value['required'] ) ) {
325
+                    $item->set_is_required( $value['required'] );
326
+                }
327 327
 
328
-				if ( isset( $value['description'] ) ) {
329
-					$item->set_custom_description( $value['description'] );
330
-				}
328
+                if ( isset( $value['description'] ) ) {
329
+                    $item->set_custom_description( $value['description'] );
330
+                }
331 331
 
332
-				$prepared[] = $item;
333
-				continue;
332
+                $prepared[] = $item;
333
+                continue;
334 334
 
335
-			}
335
+            }
336 336
 
337
-			// $item_id => array( 'price' => 10 ) (item variations)
338
-			if ( is_numeric( $key ) && is_array( $value ) ) {
339
-				$item = new GetPaid_Form_Item( $key );
337
+            // $item_id => array( 'price' => 10 ) (item variations)
338
+            if ( is_numeric( $key ) && is_array( $value ) ) {
339
+                $item = new GetPaid_Form_Item( $key );
340 340
 
341
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
-					$item->set_price( $value['price'] );
343
-				}
341
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
+                    $item->set_price( $value['price'] );
343
+                }
344 344
 
345
-				if ( $item->can_purchase() ) {
346
-					$prepared[] = $item;
347
-				}
345
+                if ( $item->can_purchase() ) {
346
+                    $prepared[] = $item;
347
+                }
348 348
 
349
-				continue;
350
-			}
349
+                continue;
350
+            }
351 351
 }
352 352
 
353
-		if ( 'objects' == $return && 'view' == $context ) {
354
-			return $prepared;
355
-		}
356
-
357
-		$items = array();
358
-		foreach ( $prepared as $item ) {
359
-			$items[] = $item->prepare_data_for_use();
360
-		}
361
-
362
-		return $items;
363
-	}
364
-
365
-	/**
366
-	 * Get a single item belonging to the form.
367
-	 *
368
-	 * @since 1.0.19
369
-	 * @param  int $item_id The item id to return.
370
-	 * @return GetPaid_Form_Item|bool
371
-	 */
372
-	public function get_item( $item_id ) {
373
-
374
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
375
-			return false;
376
-		}
377
-
378
-		foreach ( $this->get_items() as $item ) {
379
-			if ( $item->get_id() == (int) $item_id ) {
380
-				return $item;
381
-			}
382
-		}
383
-
384
-		return false;
385
-
386
-	}
387
-
388
-	/**
389
-	 * Gets a single element.
390
-	 *
391
-	 * @since 1.0.19
392
-	 * @param  string $element_type The element type to return.
393
-	 * @return array|bool
394
-	 */
395
-	public function get_element_type( $element_type ) {
396
-
397
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
398
-			return false;
399
-		}
400
-
401
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
402
-
403
-			if ( $element['type'] == $element_type ) {
404
-				return $element;
405
-			}
353
+        if ( 'objects' == $return && 'view' == $context ) {
354
+            return $prepared;
355
+        }
356
+
357
+        $items = array();
358
+        foreach ( $prepared as $item ) {
359
+            $items[] = $item->prepare_data_for_use();
360
+        }
361
+
362
+        return $items;
363
+    }
364
+
365
+    /**
366
+     * Get a single item belonging to the form.
367
+     *
368
+     * @since 1.0.19
369
+     * @param  int $item_id The item id to return.
370
+     * @return GetPaid_Form_Item|bool
371
+     */
372
+    public function get_item( $item_id ) {
373
+
374
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
375
+            return false;
376
+        }
377
+
378
+        foreach ( $this->get_items() as $item ) {
379
+            if ( $item->get_id() == (int) $item_id ) {
380
+                return $item;
381
+            }
382
+        }
383
+
384
+        return false;
385
+
386
+    }
387
+
388
+    /**
389
+     * Gets a single element.
390
+     *
391
+     * @since 1.0.19
392
+     * @param  string $element_type The element type to return.
393
+     * @return array|bool
394
+     */
395
+    public function get_element_type( $element_type ) {
396
+
397
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
398
+            return false;
399
+        }
400
+
401
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
402
+
403
+            if ( $element['type'] == $element_type ) {
404
+                return $element;
405
+            }
406 406
 }
407 407
 
408
-		return false;
409
-
410
-	}
411
-
412
-	/**
413
-	 * Get the total amount earned via this form.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return float
418
-	 */
419
-	public function get_earned( $context = 'view' ) {
420
-		return $this->get_prop( 'earned', $context );
421
-	}
422
-
423
-	/**
424
-	 * Get the total amount refunded via this form.
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return float
429
-	 */
430
-	public function get_refunded( $context = 'view' ) {
431
-		return $this->get_prop( 'refunded', $context );
432
-	}
433
-
434
-	/**
435
-	 * Get the total amount cancelled via this form.
436
-	 *
437
-	 * @since 1.0.19
438
-	 * @param  string $context View or edit context.
439
-	 * @return float
440
-	 */
441
-	public function get_cancelled( $context = 'view' ) {
442
-		return $this->get_prop( 'cancelled', $context );
443
-	}
444
-
445
-	/**
446
-	 * Get the total amount failed via this form.
447
-	 *
448
-	 * @since 1.0.19
449
-	 * @param  string $context View or edit context.
450
-	 * @return float
451
-	 */
452
-	public function get_failed( $context = 'view' ) {
453
-		return $this->get_prop( 'failed', $context );
454
-	}
455
-
456
-	/**
457
-	 * Get the currency.
458
-	 *
459
-	 * @since 1.0.19
460
-	 * @param  string $context View or edit context.
461
-	 * @return string
462
-	 */
463
-	public function get_currency() {
464
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
465
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
466
-	}
408
+        return false;
409
+
410
+    }
411
+
412
+    /**
413
+     * Get the total amount earned via this form.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return float
418
+     */
419
+    public function get_earned( $context = 'view' ) {
420
+        return $this->get_prop( 'earned', $context );
421
+    }
422
+
423
+    /**
424
+     * Get the total amount refunded via this form.
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return float
429
+     */
430
+    public function get_refunded( $context = 'view' ) {
431
+        return $this->get_prop( 'refunded', $context );
432
+    }
433
+
434
+    /**
435
+     * Get the total amount cancelled via this form.
436
+     *
437
+     * @since 1.0.19
438
+     * @param  string $context View or edit context.
439
+     * @return float
440
+     */
441
+    public function get_cancelled( $context = 'view' ) {
442
+        return $this->get_prop( 'cancelled', $context );
443
+    }
444
+
445
+    /**
446
+     * Get the total amount failed via this form.
447
+     *
448
+     * @since 1.0.19
449
+     * @param  string $context View or edit context.
450
+     * @return float
451
+     */
452
+    public function get_failed( $context = 'view' ) {
453
+        return $this->get_prop( 'failed', $context );
454
+    }
455
+
456
+    /**
457
+     * Get the currency.
458
+     *
459
+     * @since 1.0.19
460
+     * @param  string $context View or edit context.
461
+     * @return string
462
+     */
463
+    public function get_currency() {
464
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
465
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
466
+    }
467 467
 
468 468
     /*
469 469
 	|--------------------------------------------------------------------------
@@ -476,22 +476,22 @@  discard block
 block discarded – undo
476 476
     */
477 477
 
478 478
     /**
479
-	 * Set plugin version when the item was created.
480
-	 *
481
-	 * @since 1.0.19
482
-	 */
483
-	public function set_version( $value ) {
484
-		$this->set_prop( 'version', $value );
479
+     * Set plugin version when the item was created.
480
+     *
481
+     * @since 1.0.19
482
+     */
483
+    public function set_version( $value ) {
484
+        $this->set_prop( 'version', $value );
485 485
     }
486 486
 
487 487
     /**
488
-	 * Set date when the item was created.
489
-	 *
490
-	 * @since 1.0.19
491
-	 * @param string $value Value to set.
488
+     * Set date when the item was created.
489
+     *
490
+     * @since 1.0.19
491
+     * @param string $value Value to set.
492 492
      * @return bool Whether or not the date was set.
493
-	 */
494
-	public function set_date_created( $value ) {
493
+     */
494
+    public function set_date_created( $value ) {
495 495
         $date = strtotime( $value );
496 496
 
497 497
         if ( $date ) {
@@ -504,13 +504,13 @@  discard block
 block discarded – undo
504 504
     }
505 505
 
506 506
     /**
507
-	 * Set date when the item was last modified.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param string $value Value to set.
507
+     * Set date when the item was last modified.
508
+     *
509
+     * @since 1.0.19
510
+     * @param string $value Value to set.
511 511
      * @return bool Whether or not the date was set.
512
-	 */
513
-	public function set_date_modified( $value ) {
512
+     */
513
+    public function set_date_modified( $value ) {
514 514
         $date = strtotime( $value );
515 515
 
516 516
         if ( $date ) {
@@ -523,164 +523,164 @@  discard block
 block discarded – undo
523 523
     }
524 524
 
525 525
     /**
526
-	 * Set the item name.
527
-	 *
528
-	 * @since 1.0.19
529
-	 * @param  string $value New name.
530
-	 */
531
-	public function set_name( $value ) {
532
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
533
-    }
534
-
535
-    /**
536
-	 * Alias of self::set_name().
537
-	 *
538
-	 * @since 1.0.19
539
-	 * @param  string $value New name.
540
-	 */
541
-	public function set_title( $value ) {
542
-		$this->set_name( $value );
543
-    }
544
-
545
-    /**
546
-	 * Set the owner of the item.
547
-	 *
548
-	 * @since 1.0.19
549
-	 * @param  int $value New author.
550
-	 */
551
-	public function set_author( $value ) {
552
-		$this->set_prop( 'author', (int) $value );
553
-	}
554
-
555
-	/**
556
-	 * Set the form elements.
557
-	 *
558
-	 * @since 1.0.19
559
-	 * @sinve 2.3.4 Array values sanitized.
560
-	 * @param  array $value Form elements.
561
-	 */
562
-	public function set_elements( $value ) {
563
-		if ( is_array( $value ) ) {
564
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
565
-		}
566
-	}
567
-
568
-	/**
569
-	 * Sanitize array values.
570
-	 *
571
-	 * @param $value
572
-	 *
573
-	 * @return mixed
574
-	 */
575
-	public function sanitize_array_values( $value ) {
576
-
577
-		// sanitize
578
-		if ( ! empty( $value ) ) {
579
-
580
-			foreach ( $value as $key => $val_arr ) {
581
-
582
-				if ( is_array( $val_arr ) ) {
583
-					// check if we have sub array items.
584
-					$sub_arr = array();
585
-					foreach ( $val_arr as $key2 => $val2 ) {
586
-						if ( is_array( $val2 ) ) {
587
-							$sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
588
-							unset( $val_arr[ $key ][ $key2 ] );
589
-						}
590
-					}
591
-
592
-					// we allow some html in description so we sanitize it separately.
593
-					$help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
594
-
595
-					// sanitize array elements
596
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
597
-
598
-					// add back the description if set
599
-					if ( isset( $val_arr['description'] ) ) {
526
+     * Set the item name.
527
+     *
528
+     * @since 1.0.19
529
+     * @param  string $value New name.
530
+     */
531
+    public function set_name( $value ) {
532
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
533
+    }
534
+
535
+    /**
536
+     * Alias of self::set_name().
537
+     *
538
+     * @since 1.0.19
539
+     * @param  string $value New name.
540
+     */
541
+    public function set_title( $value ) {
542
+        $this->set_name( $value );
543
+    }
544
+
545
+    /**
546
+     * Set the owner of the item.
547
+     *
548
+     * @since 1.0.19
549
+     * @param  int $value New author.
550
+     */
551
+    public function set_author( $value ) {
552
+        $this->set_prop( 'author', (int) $value );
553
+    }
554
+
555
+    /**
556
+     * Set the form elements.
557
+     *
558
+     * @since 1.0.19
559
+     * @sinve 2.3.4 Array values sanitized.
560
+     * @param  array $value Form elements.
561
+     */
562
+    public function set_elements( $value ) {
563
+        if ( is_array( $value ) ) {
564
+            $this->set_prop( 'elements', wp_kses_post_deep( $value ) );
565
+        }
566
+    }
567
+
568
+    /**
569
+     * Sanitize array values.
570
+     *
571
+     * @param $value
572
+     *
573
+     * @return mixed
574
+     */
575
+    public function sanitize_array_values( $value ) {
576
+
577
+        // sanitize
578
+        if ( ! empty( $value ) ) {
579
+
580
+            foreach ( $value as $key => $val_arr ) {
581
+
582
+                if ( is_array( $val_arr ) ) {
583
+                    // check if we have sub array items.
584
+                    $sub_arr = array();
585
+                    foreach ( $val_arr as $key2 => $val2 ) {
586
+                        if ( is_array( $val2 ) ) {
587
+                            $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
588
+                            unset( $val_arr[ $key ][ $key2 ] );
589
+                        }
590
+                    }
591
+
592
+                    // we allow some html in description so we sanitize it separately.
593
+                    $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
594
+
595
+                    // sanitize array elements
596
+                    $value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
597
+
598
+                    // add back the description if set
599
+                    if ( isset( $val_arr['description'] ) ) {
600 600
 $value[ $key ]['description'] = $help_text;}
601 601
 
602
-					// add back sub array items after its been sanitized.
603
-					if ( ! empty( $sub_arr ) ) {
604
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
605
-					}
606
-				}
602
+                    // add back sub array items after its been sanitized.
603
+                    if ( ! empty( $sub_arr ) ) {
604
+                        $value[ $key ] = array_merge( $value[ $key ], $sub_arr );
605
+                    }
606
+                }
607 607
 }
608 608
 }
609 609
 
610
-		return $value;
611
-	}
612
-
613
-	/**
614
-	 * Set the form items.
615
-	 *
616
-	 * @since 1.0.19
617
-	 * @param  array $value Form elements.
618
-	 */
619
-	public function set_items( $value ) {
620
-		if ( is_array( $value ) ) {
621
-			$this->set_prop( 'items', $value );
622
-		}
623
-	}
624
-
625
-	/**
626
-	 * Set the total amount earned via this form.
627
-	 *
628
-	 * @since 1.0.19
629
-	 * @param  float $value Amount earned.
630
-	 */
631
-	public function set_earned( $value ) {
632
-		$value = max( (float) $value, 0 );
633
-		$this->set_prop( 'earned', $value );
634
-	}
635
-
636
-	/**
637
-	 * Set the total amount refunded via this form.
638
-	 *
639
-	 * @since 1.0.19
640
-	 * @param  float $value Amount refunded.
641
-	 */
642
-	public function set_refunded( $value ) {
643
-		$value = max( (float) $value, 0 );
644
-		$this->set_prop( 'refunded', $value );
645
-	}
646
-
647
-	/**
648
-	 * Set the total amount cancelled via this form.
649
-	 *
650
-	 * @since 1.0.19
651
-	 * @param  float $value Amount cancelled.
652
-	 */
653
-	public function set_cancelled( $value ) {
654
-		$value = max( (float) $value, 0 );
655
-		$this->set_prop( 'cancelled', $value );
656
-	}
657
-
658
-	/**
659
-	 * Set the total amount failed via this form.
660
-	 *
661
-	 * @since 1.0.19
662
-	 * @param  float $value Amount cancelled.
663
-	 */
664
-	public function set_failed( $value ) {
665
-		$value = max( (float) $value, 0 );
666
-		$this->set_prop( 'failed', $value );
667
-	}
610
+        return $value;
611
+    }
612
+
613
+    /**
614
+     * Set the form items.
615
+     *
616
+     * @since 1.0.19
617
+     * @param  array $value Form elements.
618
+     */
619
+    public function set_items( $value ) {
620
+        if ( is_array( $value ) ) {
621
+            $this->set_prop( 'items', $value );
622
+        }
623
+    }
624
+
625
+    /**
626
+     * Set the total amount earned via this form.
627
+     *
628
+     * @since 1.0.19
629
+     * @param  float $value Amount earned.
630
+     */
631
+    public function set_earned( $value ) {
632
+        $value = max( (float) $value, 0 );
633
+        $this->set_prop( 'earned', $value );
634
+    }
635
+
636
+    /**
637
+     * Set the total amount refunded via this form.
638
+     *
639
+     * @since 1.0.19
640
+     * @param  float $value Amount refunded.
641
+     */
642
+    public function set_refunded( $value ) {
643
+        $value = max( (float) $value, 0 );
644
+        $this->set_prop( 'refunded', $value );
645
+    }
646
+
647
+    /**
648
+     * Set the total amount cancelled via this form.
649
+     *
650
+     * @since 1.0.19
651
+     * @param  float $value Amount cancelled.
652
+     */
653
+    public function set_cancelled( $value ) {
654
+        $value = max( (float) $value, 0 );
655
+        $this->set_prop( 'cancelled', $value );
656
+    }
657
+
658
+    /**
659
+     * Set the total amount failed via this form.
660
+     *
661
+     * @since 1.0.19
662
+     * @param  float $value Amount cancelled.
663
+     */
664
+    public function set_failed( $value ) {
665
+        $value = max( (float) $value, 0 );
666
+        $this->set_prop( 'failed', $value );
667
+    }
668 668
 
669 669
     /**
670 670
      * Create an item. For backwards compatibilty.
671 671
      *
672 672
      * @deprecated
673
-	 * @return int item id
673
+     * @return int item id
674 674
      */
675 675
     public function create( $data = array() ) {
676 676
 
677
-		// Set the properties.
678
-		if ( is_array( $data ) ) {
679
-			$this->set_props( $data );
680
-		}
677
+        // Set the properties.
678
+        if ( is_array( $data ) ) {
679
+            $this->set_props( $data );
680
+        }
681 681
 
682
-		// Save the item.
683
-		return $this->save();
682
+        // Save the item.
683
+        return $this->save();
684 684
 
685 685
     }
686 686
 
@@ -688,7 +688,7 @@  discard block
 block discarded – undo
688 688
      * Updates an item. For backwards compatibilty.
689 689
      *
690 690
      * @deprecated
691
-	 * @return int item id
691
+     * @return int item id
692 692
      */
693 693
     public function update( $data = array() ) {
694 694
         return $this->create( $data );
@@ -704,22 +704,22 @@  discard block
 block discarded – undo
704 704
 	*/
705 705
 
706 706
     /**
707
-	 * Checks whether this is the default payment form.
708
-	 *
709
-	 * @since 1.0.19
710
-	 * @return bool
711
-	 */
707
+     * Checks whether this is the default payment form.
708
+     *
709
+     * @since 1.0.19
710
+     * @return bool
711
+     */
712 712
     public function is_default() {
713 713
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
714 714
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
715
-	}
715
+    }
716 716
 
717 717
     /**
718
-	 * Checks whether the form is active.
719
-	 *
720
-	 * @since 1.0.19
721
-	 * @return bool
722
-	 */
718
+     * Checks whether the form is active.
719
+     *
720
+     * @since 1.0.19
721
+     * @return bool
722
+     */
723 723
     public function is_active() {
724 724
         $is_active = 0 !== (int) $this->get_id();
725 725
 
@@ -728,81 +728,81 @@  discard block
 block discarded – undo
728 728
         }
729 729
 
730 730
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
731
-	}
732
-
733
-	/**
734
-	 * Checks whether the form has a given item.
735
-	 *
736
-	 * @since 1.0.19
737
-	 * @return bool
738
-	 */
731
+    }
732
+
733
+    /**
734
+     * Checks whether the form has a given item.
735
+     *
736
+     * @since 1.0.19
737
+     * @return bool
738
+     */
739 739
     public function has_item( $item_id ) {
740 740
         return false !== $this->get_item( $item_id );
741
-	}
742
-
743
-	/**
744
-	 * Checks whether the form has a given element.
745
-	 *
746
-	 * @since 1.0.19
747
-	 * @return bool
748
-	 */
741
+    }
742
+
743
+    /**
744
+     * Checks whether the form has a given element.
745
+     *
746
+     * @since 1.0.19
747
+     * @return bool
748
+     */
749 749
     public function has_element_type( $element_type ) {
750 750
         return false !== $this->get_element_type( $element_type );
751
-	}
752
-
753
-	/**
754
-	 * Checks whether this form is recurring or not.
755
-	 *
756
-	 * @since 1.0.19
757
-	 * @return bool
758
-	 */
751
+    }
752
+
753
+    /**
754
+     * Checks whether this form is recurring or not.
755
+     *
756
+     * @since 1.0.19
757
+     * @return bool
758
+     */
759 759
     public function is_recurring() {
760 760
 
761
-		if ( ! empty( $this->invoice ) ) {
762
-			return $this->invoice->is_recurring();
763
-		}
761
+        if ( ! empty( $this->invoice ) ) {
762
+            return $this->invoice->is_recurring();
763
+        }
764 764
 
765
-		foreach ( $this->get_items() as $item ) {
765
+        foreach ( $this->get_items() as $item ) {
766 766
 
767
-			if ( $item->is_recurring() ) {
768
-				return true;
769
-			}
767
+            if ( $item->is_recurring() ) {
768
+                return true;
769
+            }
770 770
 }
771 771
 
772 772
         return false;
773
-	}
773
+    }
774 774
 
775
-	/**
776
-	 * Retrieves the form's html.
777
-	 *
778
-	 * @since 1.0.19
779
-	 */
775
+    /**
776
+     * Retrieves the form's html.
777
+     *
778
+     * @since 1.0.19
779
+     */
780 780
     public function get_html( $extra_markup = '' ) {
781 781
 
782
-		// Return the HTML.
783
-		return wpinv_get_template_html(
784
-			'payment-forms/form.php',
785
-			array(
786
-				'form'         => $this,
787
-				'extra_markup' => $extra_markup,
788
-			)
789
-		);
790
-
791
-	}
792
-
793
-	/**
794
-	 * Displays the payment form.
795
-	 *
796
-	 * @since 1.0.19
797
-	 */
782
+        // Return the HTML.
783
+        return wpinv_get_template_html(
784
+            'payment-forms/form.php',
785
+            array(
786
+                'form'         => $this,
787
+                'extra_markup' => $extra_markup,
788
+            )
789
+        );
790
+
791
+    }
792
+
793
+    /**
794
+     * Displays the payment form.
795
+     *
796
+     * @since 1.0.19
797
+     */
798 798
     public function display( $extra_markup = '' ) {
799
-		wpinv_get_template(
800
-			'payment-forms/form.php',
801
-			array(
802
-				'form'         => $this,
803
-				'extra_markup' => $extra_markup,
804
-			)
805
-		);
799
+        wpinv_get_template(
800
+            'payment-forms/form.php',
801
+            array(
802
+                'form'         => $this,
803
+                'extra_markup' => $extra_markup,
804
+            )
805
+        );
806 806
     }
807 807
 
808 808
 }
Please login to merge, or discard this patch.
Spacing   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
75
+	public function __construct($form = 0) {
76
+		parent::__construct($form);
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+		if (is_numeric($form) && $form > 0) {
79
+			$this->set_id($form);
80
+		} elseif ($form instanceof self) {
81 81
 
82
-			$this->set_id( $form->get_id() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 89
 		}
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
93 93
 
94
-		if ( $this->get_id() > 0 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 
99 99
 	}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param  string $context View or edit context.
121 121
 	 * @return string
122 122
 	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
123
+	public function get_version($context = 'view') {
124
+		return $this->get_prop('version', $context);
125 125
     }
126 126
 
127 127
     /**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
134
+	public function get_date_created($context = 'view') {
135
+		return $this->get_prop('date_created', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
146
-        $date = $this->get_date_created( $context );
145
+	public function get_date_created_gmt($context = 'view') {
146
+        $date = $this->get_date_created($context);
147 147
 
148
-        if ( $date ) {
149
-            $date = get_gmt_from_date( $date );
148
+        if ($date) {
149
+            $date = get_gmt_from_date($date);
150 150
         }
151 151
 		return $date;
152 152
     }
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param  string $context View or edit context.
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
161
+	public function get_date_modified($context = 'view') {
162
+		return $this->get_prop('date_modified', $context);
163 163
     }
164 164
 
165 165
     /**
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param  string $context View or edit context.
170 170
 	 * @return string
171 171
 	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
173
-        $date = $this->get_date_modified( $context );
172
+	public function get_date_modified_gmt($context = 'view') {
173
+        $date = $this->get_date_modified($context);
174 174
 
175
-        if ( $date ) {
176
-            $date = get_gmt_from_date( $date );
175
+        if ($date) {
176
+            $date = get_gmt_from_date($date);
177 177
         }
178 178
 		return $date;
179 179
     }
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  string $context View or edit context.
186 186
 	 * @return string
187 187
 	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
188
+	public function get_name($context = 'view') {
189
+		return $this->get_prop('name', $context);
190 190
     }
191 191
 
192 192
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param  string $context View or edit context.
197 197
 	 * @return string
198 198
 	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
199
+	public function get_title($context = 'view') {
200
+		return $this->get_name($context);
201 201
 	}
202 202
 
203 203
     /**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 * @param  string $context View or edit context.
208 208
 	 * @return int
209 209
 	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
210
+	public function get_author($context = 'view') {
211
+		return (int) $this->get_prop('author', $context);
212 212
     }
213 213
 
214 214
     /**
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return array
220 220
 	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
221
+	public function get_elements($context = 'view') {
222
+		$elements = $this->get_prop('elements', $context);
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
225
-            return wpinv_get_data( 'sample-payment-form' );
224
+		if (empty($elements) || !is_array($elements)) {
225
+            return wpinv_get_data('sample-payment-form');
226 226
 		}
227 227
 
228 228
 		// Ensure that all required elements exist.
229 229
 		$_elements = array();
230
-		foreach ( $elements as $element ) {
230
+		foreach ($elements as $element) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
233 233
 
234 234
 				$_elements[] = array(
235
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
235
+					'text'    => __('Select Payment Method', 'invoicing'),
236 236
 					'id'      => 'gtscicd',
237 237
 					'name'    => 'gtscicd',
238 238
 					'type'    => 'gateway_select',
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 	 * @param  string $return objects or arrays.
258 258
 	 * @return GetPaid_Form_Item[]
259 259
 	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
260
+	public function get_items($context = 'view', $return = 'objects') {
261
+		$items = $this->get_prop('items', $context);
262 262
 
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
264
-            $items = wpinv_get_data( 'sample-payment-form-items' );
263
+		if (empty($items) || !is_array($items)) {
264
+            $items = wpinv_get_data('sample-payment-form-items');
265 265
 		}
266 266
 
267 267
 		// Convert the items.
268 268
 		$prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+		foreach ($items as $key => $value) {
271 271
 
272 272
 			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
273
+			if ($value instanceof GetPaid_Form_Item) {
274 274
 
275
-				if ( $value->can_purchase() ) {
275
+				if ($value->can_purchase()) {
276 276
 					$prepared[] = $value;
277 277
 				}
278 278
 
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 			}
282 282
 
283 283
 			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
284
+			if (is_numeric($key) && is_numeric($value)) {
285
+				$item = new GetPaid_Form_Item($key);
286 286
 
287
-				if ( $item->can_purchase() ) {
287
+				if ($item->can_purchase()) {
288 288
 
289 289
 					$value = (float) $value;
290
-					$item->set_quantity( $value );
291
-					if ( 0 == $value ) {
292
-						$item->set_quantity( 1 );
293
-						$item->set_allow_quantities( true );
290
+					$item->set_quantity($value);
291
+					if (0 == $value) {
292
+						$item->set_quantity(1);
293
+						$item->set_allow_quantities(true);
294 294
 					}
295 295
 
296 296
 					$prepared[] = $item;
@@ -300,33 +300,33 @@  discard block
 block discarded – undo
300 300
 			}
301 301
 
302 302
 			// Items saved via payment forms editor.
303
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
303
+			if (is_array($value) && isset($value['id'])) {
304 304
 
305
-				$item = new GetPaid_Form_Item( $value['id'] );
305
+				$item = new GetPaid_Form_Item($value['id']);
306 306
 
307
-				if ( ! $item->can_purchase() ) {
307
+				if (!$item->can_purchase()) {
308 308
 					continue;
309 309
 				}
310 310
 
311 311
 				// Sub-total (Cart items).
312
-				if ( isset( $value['subtotal'] ) ) {
313
-					$item->set_price( $value['subtotal'] );
312
+				if (isset($value['subtotal'])) {
313
+					$item->set_price($value['subtotal']);
314 314
 				}
315 315
 
316
-				if ( isset( $value['quantity'] ) ) {
317
-					$item->set_quantity( $value['quantity'] );
316
+				if (isset($value['quantity'])) {
317
+					$item->set_quantity($value['quantity']);
318 318
 				}
319 319
 
320
-				if ( isset( $value['allow_quantities'] ) ) {
321
-					$item->set_allow_quantities( $value['allow_quantities'] );
320
+				if (isset($value['allow_quantities'])) {
321
+					$item->set_allow_quantities($value['allow_quantities']);
322 322
 				}
323 323
 
324
-				if ( isset( $value['required'] ) ) {
325
-					$item->set_is_required( $value['required'] );
324
+				if (isset($value['required'])) {
325
+					$item->set_is_required($value['required']);
326 326
 				}
327 327
 
328
-				if ( isset( $value['description'] ) ) {
329
-					$item->set_custom_description( $value['description'] );
328
+				if (isset($value['description'])) {
329
+					$item->set_custom_description($value['description']);
330 330
 				}
331 331
 
332 332
 				$prepared[] = $item;
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
 			}
336 336
 
337 337
 			// $item_id => array( 'price' => 10 ) (item variations)
338
-			if ( is_numeric( $key ) && is_array( $value ) ) {
339
-				$item = new GetPaid_Form_Item( $key );
338
+			if (is_numeric($key) && is_array($value)) {
339
+				$item = new GetPaid_Form_Item($key);
340 340
 
341
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
-					$item->set_price( $value['price'] );
341
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
342
+					$item->set_price($value['price']);
343 343
 				}
344 344
 
345
-				if ( $item->can_purchase() ) {
345
+				if ($item->can_purchase()) {
346 346
 					$prepared[] = $item;
347 347
 				}
348 348
 
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 			}
351 351
 }
352 352
 
353
-		if ( 'objects' == $return && 'view' == $context ) {
353
+		if ('objects' == $return && 'view' == $context) {
354 354
 			return $prepared;
355 355
 		}
356 356
 
357 357
 		$items = array();
358
-		foreach ( $prepared as $item ) {
358
+		foreach ($prepared as $item) {
359 359
 			$items[] = $item->prepare_data_for_use();
360 360
 		}
361 361
 
@@ -369,14 +369,14 @@  discard block
 block discarded – undo
369 369
 	 * @param  int $item_id The item id to return.
370 370
 	 * @return GetPaid_Form_Item|bool
371 371
 	 */
372
-	public function get_item( $item_id ) {
372
+	public function get_item($item_id) {
373 373
 
374
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
374
+		if (empty($item_id) || !is_numeric($item_id)) {
375 375
 			return false;
376 376
 		}
377 377
 
378
-		foreach ( $this->get_items() as $item ) {
379
-			if ( $item->get_id() == (int) $item_id ) {
378
+		foreach ($this->get_items() as $item) {
379
+			if ($item->get_id() == (int) $item_id) {
380 380
 				return $item;
381 381
 			}
382 382
 		}
@@ -392,15 +392,15 @@  discard block
 block discarded – undo
392 392
 	 * @param  string $element_type The element type to return.
393 393
 	 * @return array|bool
394 394
 	 */
395
-	public function get_element_type( $element_type ) {
395
+	public function get_element_type($element_type) {
396 396
 
397
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
397
+		if (empty($element_type) || !is_scalar($element_type)) {
398 398
 			return false;
399 399
 		}
400 400
 
401
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
401
+		foreach ($this->get_prop('elements') as $element) {
402 402
 
403
-			if ( $element['type'] == $element_type ) {
403
+			if ($element['type'] == $element_type) {
404 404
 				return $element;
405 405
 			}
406 406
 }
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 	 * @param  string $context View or edit context.
417 417
 	 * @return float
418 418
 	 */
419
-	public function get_earned( $context = 'view' ) {
420
-		return $this->get_prop( 'earned', $context );
419
+	public function get_earned($context = 'view') {
420
+		return $this->get_prop('earned', $context);
421 421
 	}
422 422
 
423 423
 	/**
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	 * @param  string $context View or edit context.
428 428
 	 * @return float
429 429
 	 */
430
-	public function get_refunded( $context = 'view' ) {
431
-		return $this->get_prop( 'refunded', $context );
430
+	public function get_refunded($context = 'view') {
431
+		return $this->get_prop('refunded', $context);
432 432
 	}
433 433
 
434 434
 	/**
@@ -438,8 +438,8 @@  discard block
 block discarded – undo
438 438
 	 * @param  string $context View or edit context.
439 439
 	 * @return float
440 440
 	 */
441
-	public function get_cancelled( $context = 'view' ) {
442
-		return $this->get_prop( 'cancelled', $context );
441
+	public function get_cancelled($context = 'view') {
442
+		return $this->get_prop('cancelled', $context);
443 443
 	}
444 444
 
445 445
 	/**
@@ -449,8 +449,8 @@  discard block
 block discarded – undo
449 449
 	 * @param  string $context View or edit context.
450 450
 	 * @return float
451 451
 	 */
452
-	public function get_failed( $context = 'view' ) {
453
-		return $this->get_prop( 'failed', $context );
452
+	public function get_failed($context = 'view') {
453
+		return $this->get_prop('failed', $context);
454 454
 	}
455 455
 
456 456
 	/**
@@ -461,8 +461,8 @@  discard block
 block discarded – undo
461 461
 	 * @return string
462 462
 	 */
463 463
 	public function get_currency() {
464
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
465
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
464
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
465
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
466 466
 	}
467 467
 
468 468
     /*
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
 	 *
481 481
 	 * @since 1.0.19
482 482
 	 */
483
-	public function set_version( $value ) {
484
-		$this->set_prop( 'version', $value );
483
+	public function set_version($value) {
484
+		$this->set_prop('version', $value);
485 485
     }
486 486
 
487 487
     /**
@@ -491,11 +491,11 @@  discard block
 block discarded – undo
491 491
 	 * @param string $value Value to set.
492 492
      * @return bool Whether or not the date was set.
493 493
 	 */
494
-	public function set_date_created( $value ) {
495
-        $date = strtotime( $value );
494
+	public function set_date_created($value) {
495
+        $date = strtotime($value);
496 496
 
497
-        if ( $date ) {
498
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
497
+        if ($date) {
498
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
499 499
             return true;
500 500
         }
501 501
 
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
 	 * @param string $value Value to set.
511 511
      * @return bool Whether or not the date was set.
512 512
 	 */
513
-	public function set_date_modified( $value ) {
514
-        $date = strtotime( $value );
513
+	public function set_date_modified($value) {
514
+        $date = strtotime($value);
515 515
 
516
-        if ( $date ) {
517
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
516
+        if ($date) {
517
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
518 518
             return true;
519 519
         }
520 520
 
@@ -528,8 +528,8 @@  discard block
 block discarded – undo
528 528
 	 * @since 1.0.19
529 529
 	 * @param  string $value New name.
530 530
 	 */
531
-	public function set_name( $value ) {
532
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
531
+	public function set_name($value) {
532
+		$this->set_prop('name', sanitize_text_field($value));
533 533
     }
534 534
 
535 535
     /**
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
 	 * @since 1.0.19
539 539
 	 * @param  string $value New name.
540 540
 	 */
541
-	public function set_title( $value ) {
542
-		$this->set_name( $value );
541
+	public function set_title($value) {
542
+		$this->set_name($value);
543 543
     }
544 544
 
545 545
     /**
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @since 1.0.19
549 549
 	 * @param  int $value New author.
550 550
 	 */
551
-	public function set_author( $value ) {
552
-		$this->set_prop( 'author', (int) $value );
551
+	public function set_author($value) {
552
+		$this->set_prop('author', (int) $value);
553 553
 	}
554 554
 
555 555
 	/**
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
 	 * @sinve 2.3.4 Array values sanitized.
560 560
 	 * @param  array $value Form elements.
561 561
 	 */
562
-	public function set_elements( $value ) {
563
-		if ( is_array( $value ) ) {
564
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
562
+	public function set_elements($value) {
563
+		if (is_array($value)) {
564
+			$this->set_prop('elements', wp_kses_post_deep($value));
565 565
 		}
566 566
 	}
567 567
 
@@ -572,36 +572,36 @@  discard block
 block discarded – undo
572 572
 	 *
573 573
 	 * @return mixed
574 574
 	 */
575
-	public function sanitize_array_values( $value ) {
575
+	public function sanitize_array_values($value) {
576 576
 
577 577
 		// sanitize
578
-		if ( ! empty( $value ) ) {
578
+		if (!empty($value)) {
579 579
 
580
-			foreach ( $value as $key => $val_arr ) {
580
+			foreach ($value as $key => $val_arr) {
581 581
 
582
-				if ( is_array( $val_arr ) ) {
582
+				if (is_array($val_arr)) {
583 583
 					// check if we have sub array items.
584 584
 					$sub_arr = array();
585
-					foreach ( $val_arr as $key2 => $val2 ) {
586
-						if ( is_array( $val2 ) ) {
587
-							$sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
588
-							unset( $val_arr[ $key ][ $key2 ] );
585
+					foreach ($val_arr as $key2 => $val2) {
586
+						if (is_array($val2)) {
587
+							$sub_arr[$key2] = $this->sanitize_array_values($val2);
588
+							unset($val_arr[$key][$key2]);
589 589
 						}
590 590
 					}
591 591
 
592 592
 					// we allow some html in description so we sanitize it separately.
593
-					$help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
593
+					$help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : '';
594 594
 
595 595
 					// sanitize array elements
596
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
596
+					$value[$key] = array_map('sanitize_text_field', $val_arr);
597 597
 
598 598
 					// add back the description if set
599
-					if ( isset( $val_arr['description'] ) ) {
600
-$value[ $key ]['description'] = $help_text;}
599
+					if (isset($val_arr['description'])) {
600
+$value[$key]['description'] = $help_text; }
601 601
 
602 602
 					// add back sub array items after its been sanitized.
603
-					if ( ! empty( $sub_arr ) ) {
604
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
603
+					if (!empty($sub_arr)) {
604
+						$value[$key] = array_merge($value[$key], $sub_arr);
605 605
 					}
606 606
 				}
607 607
 }
@@ -616,9 +616,9 @@  discard block
 block discarded – undo
616 616
 	 * @since 1.0.19
617 617
 	 * @param  array $value Form elements.
618 618
 	 */
619
-	public function set_items( $value ) {
620
-		if ( is_array( $value ) ) {
621
-			$this->set_prop( 'items', $value );
619
+	public function set_items($value) {
620
+		if (is_array($value)) {
621
+			$this->set_prop('items', $value);
622 622
 		}
623 623
 	}
624 624
 
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 	 * @since 1.0.19
629 629
 	 * @param  float $value Amount earned.
630 630
 	 */
631
-	public function set_earned( $value ) {
632
-		$value = max( (float) $value, 0 );
633
-		$this->set_prop( 'earned', $value );
631
+	public function set_earned($value) {
632
+		$value = max((float) $value, 0);
633
+		$this->set_prop('earned', $value);
634 634
 	}
635 635
 
636 636
 	/**
@@ -639,9 +639,9 @@  discard block
 block discarded – undo
639 639
 	 * @since 1.0.19
640 640
 	 * @param  float $value Amount refunded.
641 641
 	 */
642
-	public function set_refunded( $value ) {
643
-		$value = max( (float) $value, 0 );
644
-		$this->set_prop( 'refunded', $value );
642
+	public function set_refunded($value) {
643
+		$value = max((float) $value, 0);
644
+		$this->set_prop('refunded', $value);
645 645
 	}
646 646
 
647 647
 	/**
@@ -650,9 +650,9 @@  discard block
 block discarded – undo
650 650
 	 * @since 1.0.19
651 651
 	 * @param  float $value Amount cancelled.
652 652
 	 */
653
-	public function set_cancelled( $value ) {
654
-		$value = max( (float) $value, 0 );
655
-		$this->set_prop( 'cancelled', $value );
653
+	public function set_cancelled($value) {
654
+		$value = max((float) $value, 0);
655
+		$this->set_prop('cancelled', $value);
656 656
 	}
657 657
 
658 658
 	/**
@@ -661,9 +661,9 @@  discard block
 block discarded – undo
661 661
 	 * @since 1.0.19
662 662
 	 * @param  float $value Amount cancelled.
663 663
 	 */
664
-	public function set_failed( $value ) {
665
-		$value = max( (float) $value, 0 );
666
-		$this->set_prop( 'failed', $value );
664
+	public function set_failed($value) {
665
+		$value = max((float) $value, 0);
666
+		$this->set_prop('failed', $value);
667 667
 	}
668 668
 
669 669
     /**
@@ -672,11 +672,11 @@  discard block
 block discarded – undo
672 672
      * @deprecated
673 673
 	 * @return int item id
674 674
      */
675
-    public function create( $data = array() ) {
675
+    public function create($data = array()) {
676 676
 
677 677
 		// Set the properties.
678
-		if ( is_array( $data ) ) {
679
-			$this->set_props( $data );
678
+		if (is_array($data)) {
679
+			$this->set_props($data);
680 680
 		}
681 681
 
682 682
 		// Save the item.
@@ -690,8 +690,8 @@  discard block
 block discarded – undo
690 690
      * @deprecated
691 691
 	 * @return int item id
692 692
      */
693
-    public function update( $data = array() ) {
694
-        return $this->create( $data );
693
+    public function update($data = array()) {
694
+        return $this->create($data);
695 695
     }
696 696
 
697 697
     /*
@@ -711,7 +711,7 @@  discard block
 block discarded – undo
711 711
 	 */
712 712
     public function is_default() {
713 713
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
714
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
714
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
715 715
 	}
716 716
 
717 717
     /**
@@ -723,11 +723,11 @@  discard block
 block discarded – undo
723 723
     public function is_active() {
724 724
         $is_active = 0 !== (int) $this->get_id();
725 725
 
726
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
726
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
727 727
             $is_active = false;
728 728
         }
729 729
 
730
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
730
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
731 731
 	}
732 732
 
733 733
 	/**
@@ -736,8 +736,8 @@  discard block
 block discarded – undo
736 736
 	 * @since 1.0.19
737 737
 	 * @return bool
738 738
 	 */
739
-    public function has_item( $item_id ) {
740
-        return false !== $this->get_item( $item_id );
739
+    public function has_item($item_id) {
740
+        return false !== $this->get_item($item_id);
741 741
 	}
742 742
 
743 743
 	/**
@@ -746,8 +746,8 @@  discard block
 block discarded – undo
746 746
 	 * @since 1.0.19
747 747
 	 * @return bool
748 748
 	 */
749
-    public function has_element_type( $element_type ) {
750
-        return false !== $this->get_element_type( $element_type );
749
+    public function has_element_type($element_type) {
750
+        return false !== $this->get_element_type($element_type);
751 751
 	}
752 752
 
753 753
 	/**
@@ -758,13 +758,13 @@  discard block
 block discarded – undo
758 758
 	 */
759 759
     public function is_recurring() {
760 760
 
761
-		if ( ! empty( $this->invoice ) ) {
761
+		if (!empty($this->invoice)) {
762 762
 			return $this->invoice->is_recurring();
763 763
 		}
764 764
 
765
-		foreach ( $this->get_items() as $item ) {
765
+		foreach ($this->get_items() as $item) {
766 766
 
767
-			if ( $item->is_recurring() ) {
767
+			if ($item->is_recurring()) {
768 768
 				return true;
769 769
 			}
770 770
 }
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 	 *
778 778
 	 * @since 1.0.19
779 779
 	 */
780
-    public function get_html( $extra_markup = '' ) {
780
+    public function get_html($extra_markup = '') {
781 781
 
782 782
 		// Return the HTML.
783 783
 		return wpinv_get_template_html(
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 *
796 796
 	 * @since 1.0.19
797 797
 	 */
798
-    public function display( $extra_markup = '' ) {
798
+    public function display($extra_markup = '') {
799 799
 		wpinv_get_template(
800 800
 			'payment-forms/form.php',
801 801
 			array(
Please login to merge, or discard this patch.
templates/payment-forms/form.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Make sure that the form is active.
13
-if ( ! $form->is_active() ) {
13
+if (!$form->is_active()) {
14 14
     aui()->alert(
15 15
         array(
16 16
             'type'    => 'warning',
17
-            'content' => __( 'This payment form is no longer active', 'invoicing' ),
17
+            'content' => __('This payment form is no longer active', 'invoicing'),
18 18
         ),
19 19
         true
20 20
     );
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
 }
23 23
 
24 24
 // Require login to checkout.
25
-if ( wpinv_require_login_to_checkout() && ! get_current_user_id() ) {
25
+if (wpinv_require_login_to_checkout() && !get_current_user_id()) {
26 26
 
27 27
     aui()->alert(
28 28
         array(
29 29
             'type'    => 'danger',
30
-            'content' => __( 'You must be logged in to checkout.', 'invoicing' ),
30
+            'content' => __('You must be logged in to checkout.', 'invoicing'),
31 31
         ),
32 32
         true
33 33
     );
@@ -36,29 +36,29 @@  discard block
 block discarded – undo
36 36
 }
37 37
 
38 38
 // Fires before displaying a payment form.
39
-do_action( 'getpaid_before_payment_form', $form );
39
+do_action('getpaid_before_payment_form', $form);
40 40
 ?>
41 41
 
42
-<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint( $form->get_id() ); ?> bsui position-relative' method='POST' data-key='<?php echo esc_attr( uniqid( 'gpf' ) ); ?>' data-currency='<?php echo esc_attr( empty( $form->invoice ) ? wpinv_get_currency() : $form->invoice->get_currency() ); ?>' novalidate>
42
+<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint($form->get_id()); ?> bsui position-relative' method='POST' data-key='<?php echo esc_attr(uniqid('gpf')); ?>' data-currency='<?php echo esc_attr(empty($form->invoice) ? wpinv_get_currency() : $form->invoice->get_currency()); ?>' novalidate>
43 43
 
44 44
     <?php
45 45
 
46 46
         // Fires when printing the top of a payment form.
47
-        do_action( 'getpaid_payment_form_top', $form );
47
+        do_action('getpaid_payment_form_top', $form);
48 48
 
49 49
         // And the optional invoice id.
50
-        if ( ! empty( $form->invoice ) ) {
51
-		    getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() );
50
+        if (!empty($form->invoice)) {
51
+		    getpaid_hidden_field('invoice_id', $form->invoice->get_id());
52 52
         }
53 53
 
54 54
         // We also want to include the form id.
55
-        getpaid_hidden_field( 'form_id', $form->get_id() );
55
+        getpaid_hidden_field('form_id', $form->get_id());
56 56
 
57 57
         // And an indication that this is a payment form submission.
58
-        getpaid_hidden_field( 'getpaid_payment_form_submission', '1' );
58
+        getpaid_hidden_field('getpaid_payment_form_submission', '1');
59 59
 
60 60
         // Fires before displaying payment form elements.
61
-        do_action( 'getpaid_payment_form_before_elements', $form );
61
+        do_action('getpaid_payment_form_before_elements', $form);
62 62
 
63 63
         // Display the elements.
64 64
         ?>
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
             <div class="row">
67 67
                 <?php
68 68
 
69
-                    foreach ( $form->get_elements() as $element ) {
69
+                    foreach ($form->get_elements() as $element) {
70 70
 
71
-					if ( isset( $element['type'] ) ) {
72
-						$grid_class = getpaid_get_form_element_grid_class( $element );
73
-						echo "<div class='" . esc_attr( $grid_class ) . "'>";
74
-						do_action( 'getpaid_payment_form_element', $element, $form );
75
-						do_action( "getpaid_payment_form_element_{$element['type']}_template", $element, $form );
71
+					if (isset($element['type'])) {
72
+						$grid_class = getpaid_get_form_element_grid_class($element);
73
+						echo "<div class='" . esc_attr($grid_class) . "'>";
74
+						do_action('getpaid_payment_form_element', $element, $form);
75
+						do_action("getpaid_payment_form_element_{$element['type']}_template", $element, $form);
76 76
 						echo '</div>';
77 77
                         }
78 78
 }
@@ -83,28 +83,28 @@  discard block
 block discarded – undo
83 83
 
84 84
         <?php
85 85
         // Fires after displaying payment form elements.
86
-        do_action( 'getpaid_payment_form_after_elements', $form );
86
+        do_action('getpaid_payment_form_after_elements', $form);
87 87
 
88 88
         echo "<div class='getpaid-payment-form-errors alert alert-danger d-none'></div>";
89 89
 
90
-        if ( wpinv_current_user_can_manage_invoicing() ) {
90
+        if (wpinv_current_user_can_manage_invoicing()) {
91 91
 
92 92
             edit_post_link(
93
-                __( 'Edit this form.', 'invoicing' ),
93
+                __('Edit this form.', 'invoicing'),
94 94
                 '<small class="form-text text-muted">',
95
-                '&nbsp;' . __( 'This is only visible to website administators.', 'invoicing' ) . '</small>',
95
+                '&nbsp;' . __('This is only visible to website administators.', 'invoicing') . '</small>',
96 96
                 $form->get_id(),
97 97
                 'text-danger'
98 98
             );
99 99
 
100 100
         }
101 101
 
102
-        echo wp_kses( $extra_markup, getpaid_allowed_html() );
102
+        echo wp_kses($extra_markup, getpaid_allowed_html());
103 103
     ?>
104 104
 
105 105
     <div class="loading_div overlay overlay-black position-absolute row m-0 rounded overflow-hidden" style="height: 100%;width: 100%;top: 0px;z-index: 2;display:none;">
106 106
         <div class="spinner-border mx-auto align-self-center text-white" role="status">
107
-            <span class="sr-only"><?php esc_html_e( 'Loading...', 'invoicing' ); ?></span>
107
+            <span class="sr-only"><?php esc_html_e('Loading...', 'invoicing'); ?></span>
108 108
         </div>
109 109
     </div>
110 110
 
@@ -113,4 +113,4 @@  discard block
 block discarded – undo
113 113
 <?php
114 114
 
115 115
 // Fires after displaying a payment form.
116
-do_action( 'getpaid_after_payment_form', $form );
116
+do_action('getpaid_after_payment_form', $form);
Please login to merge, or discard this patch.