Passed
Push — master ( 23c074...2114e2 )
by Brian
05:15
created
includes/class-wpinv-ajax.php 1 patch
Spacing   +213 added lines, -213 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
 
@@ -102,36 +102,36 @@  discard block
 block discarded – undo
102 102
             'ip_geolocation'              => true,
103 103
         );
104 104
 
105
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
106
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
107
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
105
+        foreach ($ajax_events as $ajax_event => $nopriv) {
106
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
107
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
108 108
 
109
-            if ( $nopriv ) {
110
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+            if ($nopriv) {
110
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
113 113
             }
114 114
         }
115 115
     }
116 116
     
117 117
     public static function add_note() {
118
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
118
+        check_ajax_referer('add-invoice-note', '_nonce');
119 119
 
120
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
120
+        if (!wpinv_current_user_can_manage_invoicing()) {
121 121
             die(-1);
122 122
         }
123 123
 
124
-        $post_id   = absint( $_POST['post_id'] );
125
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
126
-        $note_type = sanitize_text_field( $_POST['note_type'] );
124
+        $post_id   = absint($_POST['post_id']);
125
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
126
+        $note_type = sanitize_text_field($_POST['note_type']);
127 127
 
128 128
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
129 129
 
130
-        if ( $post_id > 0 ) {
131
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
130
+        if ($post_id > 0) {
131
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
132 132
 
133
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
134
-                wpinv_get_invoice_note_line_item( $note_id );
133
+            if ($note_id > 0 && !is_wp_error($note_id)) {
134
+                wpinv_get_invoice_note_line_item($note_id);
135 135
             }
136 136
         }
137 137
 
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
     }
140 140
 
141 141
     public static function delete_note() {
142
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
142
+        check_ajax_referer('delete-invoice-note', '_nonce');
143 143
 
144
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
144
+        if (!wpinv_current_user_can_manage_invoicing()) {
145 145
             die(-1);
146 146
         }
147 147
 
148
-        $note_id = (int)$_POST['note_id'];
148
+        $note_id = (int) $_POST['note_id'];
149 149
 
150
-        if ( $note_id > 0 ) {
151
-            wp_delete_comment( $note_id, true );
150
+        if ($note_id > 0) {
151
+            wp_delete_comment($note_id, true);
152 152
         }
153 153
 
154 154
         die();
@@ -166,34 +166,34 @@  discard block
 block discarded – undo
166 166
     public static function get_billing_details() {
167 167
 
168 168
         // Verify nonce.
169
-        check_ajax_referer( 'wpinv-nonce' );
169
+        check_ajax_referer('wpinv-nonce');
170 170
 
171 171
         // Can the user manage the plugin?
172
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
172
+        if (!wpinv_current_user_can_manage_invoicing()) {
173 173
             die(-1);
174 174
         }
175 175
 
176 176
         // Do we have a user id?
177 177
         $user_id = $_GET['user_id'];
178 178
 
179
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
179
+        if (empty($user_id) || !is_numeric($user_id)) {
180 180
             die(-1);
181 181
         }
182 182
 
183 183
         // Fetch the billing details.
184
-        $billing_details    = wpinv_get_user_address( $user_id );
185
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
184
+        $billing_details    = wpinv_get_user_address($user_id);
185
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
186 186
 
187 187
         // unset the user id and email.
188
-        $to_ignore = array( 'user_id', 'email' );
188
+        $to_ignore = array('user_id', 'email');
189 189
 
190
-        foreach ( $to_ignore as $key ) {
191
-            if ( isset( $billing_details[ $key ] ) ) {
192
-                unset( $billing_details[ $key ] );
190
+        foreach ($to_ignore as $key) {
191
+            if (isset($billing_details[$key])) {
192
+                unset($billing_details[$key]);
193 193
             }
194 194
         }
195 195
 
196
-        wp_send_json_success( $billing_details );
196
+        wp_send_json_success($billing_details);
197 197
 
198 198
     }
199 199
 
@@ -203,47 +203,47 @@  discard block
 block discarded – undo
203 203
     public static function check_new_user_email() {
204 204
 
205 205
         // Verify nonce.
206
-        check_ajax_referer( 'wpinv-nonce' );
206
+        check_ajax_referer('wpinv-nonce');
207 207
 
208 208
         // Can the user manage the plugin?
209
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
209
+        if (!wpinv_current_user_can_manage_invoicing()) {
210 210
             die(-1);
211 211
         }
212 212
 
213 213
         // We need an email address.
214
-        if ( empty( $_GET['email'] ) ) {
215
-            _e( "Provide the new user's email address", 'invoicing' );
214
+        if (empty($_GET['email'])) {
215
+            _e("Provide the new user's email address", 'invoicing');
216 216
             exit;
217 217
         }
218 218
 
219 219
         // Ensure the email is valid.
220
-        $email = sanitize_text_field( $_GET['email'] );
221
-        if ( ! is_email( $email ) ) {
222
-            _e( 'Invalid email address', 'invoicing' );
220
+        $email = sanitize_text_field($_GET['email']);
221
+        if (!is_email($email)) {
222
+            _e('Invalid email address', 'invoicing');
223 223
             exit;
224 224
         }
225 225
 
226 226
         // And it does not exist.
227
-        if ( email_exists( $email ) ) {
228
-            _e( 'A user with this email address already exists', 'invoicing' );
227
+        if (email_exists($email)) {
228
+            _e('A user with this email address already exists', 'invoicing');
229 229
             exit;
230 230
         }
231 231
 
232
-        wp_send_json_success( true );
232
+        wp_send_json_success(true);
233 233
     }
234 234
     
235 235
     public static function run_tool() {
236
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
237
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
236
+        check_ajax_referer('wpinv-nonce', '_nonce');
237
+        if (!wpinv_current_user_can_manage_invoicing()) {
238 238
             die(-1);
239 239
         }
240 240
         
241
-        $tool = sanitize_text_field( $_POST['tool'] );
241
+        $tool = sanitize_text_field($_POST['tool']);
242 242
         
243
-        do_action( 'wpinv_run_tool' );
243
+        do_action('wpinv_run_tool');
244 244
         
245
-        if ( !empty( $tool ) ) {
246
-            do_action( 'wpinv_tool_' . $tool );
245
+        if (!empty($tool)) {
246
+            do_action('wpinv_tool_' . $tool);
247 247
         }
248 248
     }
249 249
 
@@ -253,30 +253,30 @@  discard block
 block discarded – undo
253 253
     public static function get_payment_form() {
254 254
 
255 255
         // Check nonce.
256
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
257
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
256
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
257
+            _e('Error: Reload the page and try again.', 'invoicing');
258 258
             exit;
259 259
         }
260 260
 
261 261
         // Is the request set up correctly?
262
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
262
+		if (empty($_GET['form']) && empty($_GET['item'])) {
263 263
 			echo aui()->alert(
264 264
 				array(
265 265
 					'type'    => 'warning',
266
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
266
+					'content' => __('No payment form or item provided', 'invoicing'),
267 267
 				)
268 268
             );
269 269
             exit;
270 270
         }
271 271
 
272 272
         // Payment form or button?
273
-		if ( ! empty( $_GET['form'] ) ) {
274
-            getpaid_display_payment_form( $_GET['form'] );
275
-		} else if( ! empty( $_GET['invoice'] ) ) {
276
-		    getpaid_display_invoice_payment_form( $_GET['invoice'] );
273
+		if (!empty($_GET['form'])) {
274
+            getpaid_display_payment_form($_GET['form']);
275
+		} else if (!empty($_GET['invoice'])) {
276
+		    getpaid_display_invoice_payment_form($_GET['invoice']);
277 277
         } else {
278
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
279
-		    getpaid_display_item_payment_form( $items );
278
+			$items = getpaid_convert_items_to_array($_GET['item']);
279
+		    getpaid_display_item_payment_form($items);
280 280
         }
281 281
 
282 282
         exit;
@@ -291,17 +291,17 @@  discard block
 block discarded – undo
291 291
     public static function payment_form() {
292 292
 
293 293
         // Check nonce.
294
-        check_ajax_referer( 'getpaid_form_nonce' );
294
+        check_ajax_referer('getpaid_form_nonce');
295 295
 
296 296
         // ... form fields...
297
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
298
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
297
+        if (empty($_POST['getpaid_payment_form_submission'])) {
298
+            _e('Error: Reload the page and try again.', 'invoicing');
299 299
             exit;
300 300
         }
301 301
 
302 302
         // Process the payment form.
303
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
304
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
303
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
304
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
305 305
         $checkout->process_checkout();
306 306
 
307 307
         exit;
@@ -314,51 +314,51 @@  discard block
 block discarded – undo
314 314
      */
315 315
     public static function get_payment_form_states_field() {
316 316
 
317
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
317
+        if (empty($_GET['country']) || empty($_GET['form'])) {
318 318
             exit;
319 319
         }
320 320
 
321
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
321
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
322 322
 
323
-        if ( empty( $elements ) ) {
323
+        if (empty($elements)) {
324 324
             exit;
325 325
         }
326 326
 
327 327
         $address_fields = array();
328
-        foreach ( $elements as $element ) {
329
-            if ( 'address' === $element['type'] ) {
328
+        foreach ($elements as $element) {
329
+            if ('address' === $element['type']) {
330 330
                 $address_fields = $element;
331 331
                 break;
332 332
             }
333 333
         }
334 334
 
335
-        if ( empty( $address_fields ) ) {
335
+        if (empty($address_fields)) {
336 336
             exit;
337 337
         }
338 338
 
339
-        foreach( $address_fields['fields'] as $address_field ) {
339
+        foreach ($address_fields['fields'] as $address_field) {
340 340
 
341
-            if ( 'wpinv_state' == $address_field['name'] ) {
341
+            if ('wpinv_state' == $address_field['name']) {
342 342
 
343 343
                 $label = $address_field['label'];
344 344
 
345
-                if ( ! empty( $address_field['required'] ) ) {
345
+                if (!empty($address_field['required'])) {
346 346
                     $label .= "<span class='text-danger'> *</span>";
347 347
                 }
348 348
 
349
-                $states = wpinv_get_country_states( $_GET['country'] );
349
+                $states = wpinv_get_country_states($_GET['country']);
350 350
 
351
-                if ( ! empty( $states ) ) {
351
+                if (!empty($states)) {
352 352
 
353 353
                     $html = aui()->select(
354 354
                             array(
355 355
                                 'options'          => $states,
356
-                                'name'             => esc_attr( $address_field['name'] ),
357
-                                'id'               => esc_attr( $address_field['name'] ),
358
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
356
+                                'name'             => esc_attr($address_field['name']),
357
+                                'id'               => esc_attr($address_field['name']),
358
+                                'placeholder'      => esc_attr($address_field['placeholder']),
359 359
                                 'required'         => (bool) $address_field['required'],
360 360
                                 'no_wrap'          => true,
361
-                                'label'            => wp_kses_post( $label ),
361
+                                'label'            => wp_kses_post($label),
362 362
                                 'select2'          => false,
363 363
                             )
364 364
                         );
@@ -367,10 +367,10 @@  discard block
 block discarded – undo
367 367
 
368 368
                     $html = aui()->input(
369 369
                             array(
370
-                                'name'       => esc_attr( $address_field['name'] ),
371
-                                'id'         => esc_attr( $address_field['name'] ),
370
+                                'name'       => esc_attr($address_field['name']),
371
+                                'id'         => esc_attr($address_field['name']),
372 372
                                 'required'   => (bool) $address_field['required'],
373
-                                'label'      => wp_kses_post( $label ),
373
+                                'label'      => wp_kses_post($label),
374 374
                                 'no_wrap'    => true,
375 375
                                 'type'       => 'text',
376 376
                             )
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 
379 379
                 }
380 380
 
381
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
381
+                wp_send_json_success(str_replace('sr-only', '', $html));
382 382
                 exit;
383 383
 
384 384
             }
@@ -394,56 +394,56 @@  discard block
 block discarded – undo
394 394
     public static function recalculate_invoice_totals() {
395 395
 
396 396
         // Verify nonce.
397
-        check_ajax_referer( 'wpinv-nonce' );
397
+        check_ajax_referer('wpinv-nonce');
398 398
 
399
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
399
+        if (!wpinv_current_user_can_manage_invoicing()) {
400 400
             exit;
401 401
         }
402 402
 
403 403
         // We need an invoice.
404
-        if ( empty( $_POST['post_id'] ) ) {
404
+        if (empty($_POST['post_id'])) {
405 405
             exit;
406 406
         }
407 407
 
408 408
         // Fetch the invoice.
409
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
409
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
410 410
 
411 411
         // Ensure it exists.
412
-        if ( ! $invoice->get_id() ) {
412
+        if (!$invoice->get_id()) {
413 413
             exit;
414 414
         }
415 415
 
416 416
         // Maybe set the country, state, currency.
417
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
418
-            if ( isset( $_POST[ $key ] ) ) {
417
+        foreach (array('country', 'state', 'currency') as $key) {
418
+            if (isset($_POST[$key])) {
419 419
                 $method = "set_$key";
420
-                $invoice->$method( $_POST[ $key ] );
420
+                $invoice->$method($_POST[$key]);
421 421
             }
422 422
         }
423 423
 
424 424
         // Maybe disable taxes.
425
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
425
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
426 426
 
427 427
         // Recalculate totals.
428 428
         $invoice->recalculate_total();
429 429
 
430
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
430
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
431 431
 
432
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
433
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
434
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
432
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
433
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
434
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
435 435
         }
436 436
 
437 437
         $totals = array(
438
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
439
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
440
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
438
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
439
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
440
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
441 441
             'total'    => $total,
442 442
         );
443 443
 
444
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
444
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
445 445
 
446
-        wp_send_json_success( compact( 'totals' ) );
446
+        wp_send_json_success(compact('totals'));
447 447
     }
448 448
 
449 449
     /**
@@ -452,33 +452,33 @@  discard block
 block discarded – undo
452 452
     public static function get_invoice_items() {
453 453
 
454 454
         // Verify nonce.
455
-        check_ajax_referer( 'wpinv-nonce' );
455
+        check_ajax_referer('wpinv-nonce');
456 456
 
457
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
457
+        if (!wpinv_current_user_can_manage_invoicing()) {
458 458
             exit;
459 459
         }
460 460
 
461 461
         // We need an invoice and items.
462
-        if ( empty( $_POST['post_id'] ) ) {
462
+        if (empty($_POST['post_id'])) {
463 463
             exit;
464 464
         }
465 465
 
466 466
         // Fetch the invoice.
467
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
467
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
468 468
 
469 469
         // Ensure it exists.
470
-        if ( ! $invoice->get_id() ) {
470
+        if (!$invoice->get_id()) {
471 471
             exit;
472 472
         }
473 473
 
474 474
         // Return an array of invoice items.
475 475
         $items = array();
476 476
 
477
-        foreach ( $invoice->get_items() as $item_id => $item ) {
478
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
477
+        foreach ($invoice->get_items() as $item_id => $item) {
478
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
479 479
         }
480 480
 
481
-        wp_send_json_success( compact( 'items' ) );
481
+        wp_send_json_success(compact('items'));
482 482
     }
483 483
 
484 484
     /**
@@ -487,50 +487,50 @@  discard block
 block discarded – undo
487 487
     public static function edit_invoice_item() {
488 488
 
489 489
         // Verify nonce.
490
-        check_ajax_referer( 'wpinv-nonce' );
490
+        check_ajax_referer('wpinv-nonce');
491 491
 
492
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
492
+        if (!wpinv_current_user_can_manage_invoicing()) {
493 493
             exit;
494 494
         }
495 495
 
496 496
         // We need an invoice and item details.
497
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
497
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
498 498
             exit;
499 499
         }
500 500
 
501 501
         // Fetch the invoice.
502
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
502
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
503 503
 
504 504
         // Ensure it exists and its not been paid for.
505
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
505
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
506 506
             exit;
507 507
         }
508 508
 
509 509
         // Format the data.
510
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
510
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
511 511
 
512 512
         // Ensure that we have an item id.
513
-        if ( empty( $data['id'] ) ) {
513
+        if (empty($data['id'])) {
514 514
             exit;
515 515
         }
516 516
 
517 517
         // Abort if the invoice does not have the specified item.
518
-        $item = $invoice->get_item( (int) $data['id'] );
518
+        $item = $invoice->get_item((int) $data['id']);
519 519
 
520
-        if ( empty( $item ) ) {
520
+        if (empty($item)) {
521 521
             exit;
522 522
         }
523 523
 
524 524
         // Update the item.
525
-        $item->set_price( $data['price'] );
526
-        $item->set_name( $data['name'] );
527
-        $item->set_description( $data['description'] );
528
-        $item->set_quantity( $data['quantity'] );
525
+        $item->set_price($data['price']);
526
+        $item->set_name($data['name']);
527
+        $item->set_description($data['description']);
528
+        $item->set_quantity($data['quantity']);
529 529
 
530 530
         // Add it to the invoice.
531
-        $error = $invoice->add_item( $item );
531
+        $error = $invoice->add_item($item);
532 532
         $alert = false;
533
-        if ( is_wp_error( $error ) ) {
533
+        if (is_wp_error($error)) {
534 534
             $alert = $error->get_error_message();
535 535
         }
536 536
 
@@ -543,11 +543,11 @@  discard block
 block discarded – undo
543 543
         // Return an array of invoice items.
544 544
         $items = array();
545 545
 
546
-        foreach ( $invoice->get_items() as $item_id => $item ) {
547
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
546
+        foreach ($invoice->get_items() as $item_id => $item) {
547
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
548 548
         }
549 549
 
550
-        wp_send_json_success( compact( 'items', 'alert' ) );
550
+        wp_send_json_success(compact('items', 'alert'));
551 551
     }
552 552
 
553 553
     /**
@@ -556,33 +556,33 @@  discard block
 block discarded – undo
556 556
     public static function remove_invoice_item() {
557 557
 
558 558
         // Verify nonce.
559
-        check_ajax_referer( 'wpinv-nonce' );
559
+        check_ajax_referer('wpinv-nonce');
560 560
 
561
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
561
+        if (!wpinv_current_user_can_manage_invoicing()) {
562 562
             exit;
563 563
         }
564 564
 
565 565
         // We need an invoice and an item.
566
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
566
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
567 567
             exit;
568 568
         }
569 569
 
570 570
         // Fetch the invoice.
571
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
571
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
572 572
 
573 573
         // Ensure it exists and its not been paid for.
574
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
574
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
575 575
             exit;
576 576
         }
577 577
 
578 578
         // Abort if the invoice does not have the specified item.
579
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
579
+        $item = $invoice->get_item((int) $_POST['item_id']);
580 580
 
581
-        if ( empty( $item ) ) {
581
+        if (empty($item)) {
582 582
             exit;
583 583
         }
584 584
 
585
-        $invoice->remove_item( (int) $_POST['item_id'] );
585
+        $invoice->remove_item((int) $_POST['item_id']);
586 586
 
587 587
         // Update totals.
588 588
         $invoice->recalculate_total();
@@ -593,11 +593,11 @@  discard block
 block discarded – undo
593 593
         // Return an array of invoice items.
594 594
         $items = array();
595 595
 
596
-        foreach ( $invoice->get_items() as $item_id => $item ) {
597
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
596
+        foreach ($invoice->get_items() as $item_id => $item) {
597
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
598 598
         }
599 599
 
600
-        wp_send_json_success( compact( 'items' ) );
600
+        wp_send_json_success(compact('items'));
601 601
     }
602 602
 
603 603
     /**
@@ -606,39 +606,39 @@  discard block
 block discarded – undo
606 606
     public static function add_invoice_items() {
607 607
 
608 608
         // Verify nonce.
609
-        check_ajax_referer( 'wpinv-nonce' );
609
+        check_ajax_referer('wpinv-nonce');
610 610
 
611
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
611
+        if (!wpinv_current_user_can_manage_invoicing()) {
612 612
             exit;
613 613
         }
614 614
 
615 615
         // We need an invoice and items.
616
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
616
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
617 617
             exit;
618 618
         }
619 619
 
620 620
         // Fetch the invoice.
621
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
621
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
622 622
         $alert   = false;
623 623
 
624 624
         // Ensure it exists and its not been paid for.
625
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
625
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
626 626
             exit;
627 627
         }
628 628
 
629 629
         // Add the items.
630
-        foreach ( $_POST['items'] as $data ) {
630
+        foreach ($_POST['items'] as $data) {
631 631
 
632
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
632
+            $item = new GetPaid_Form_Item($data['id']);
633 633
 
634
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
635
-                $item->set_quantity( $data[ 'qty' ] );
634
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
635
+                $item->set_quantity($data['qty']);
636 636
             }
637 637
 
638
-            if ( $item->get_id() > 0 ) {
639
-                $error = $invoice->add_item( $item );
638
+            if ($item->get_id() > 0) {
639
+                $error = $invoice->add_item($item);
640 640
 
641
-                if ( is_wp_error( $error ) ) {
641
+                if (is_wp_error($error)) {
642 642
                     $alert = $error->get_error_message();
643 643
                 }
644 644
 
@@ -653,11 +653,11 @@  discard block
 block discarded – undo
653 653
         // Return an array of invoice items.
654 654
         $items = array();
655 655
 
656
-        foreach ( $invoice->get_items() as $item_id => $item ) {
657
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
656
+        foreach ($invoice->get_items() as $item_id => $item) {
657
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
658 658
         }
659 659
 
660
-        wp_send_json_success( compact( 'items', 'alert' ) );
660
+        wp_send_json_success(compact('items', 'alert'));
661 661
     }
662 662
 
663 663
     /**
@@ -666,15 +666,15 @@  discard block
 block discarded – undo
666 666
     public static function get_invoicing_items() {
667 667
 
668 668
         // Verify nonce.
669
-        check_ajax_referer( 'wpinv-nonce' );
669
+        check_ajax_referer('wpinv-nonce');
670 670
 
671
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
671
+        if (!wpinv_current_user_can_manage_invoicing()) {
672 672
             exit;
673 673
         }
674 674
 
675 675
         // We need a search term.
676
-        if ( empty( $_GET['search'] ) ) {
677
-            wp_send_json_success( array() );
676
+        if (empty($_GET['search'])) {
677
+            wp_send_json_success(array());
678 678
         }
679 679
 
680 680
         // Retrieve items.
@@ -683,8 +683,8 @@  discard block
 block discarded – undo
683 683
             'orderby'        => 'title',
684 684
             'order'          => 'ASC',
685 685
             'posts_per_page' => -1,
686
-            'post_status'    => array( 'publish' ),
687
-            's'              => trim( $_GET['search'] ),
686
+            'post_status'    => array('publish'),
687
+            's'              => trim($_GET['search']),
688 688
             'meta_query'     => array(
689 689
                 array(
690 690
                     'key'       => '_wpinv_type',
@@ -694,22 +694,22 @@  discard block
 block discarded – undo
694 694
             )
695 695
         );
696 696
 
697
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
697
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
698 698
         $data  = array();
699 699
 
700 700
 
701
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
701
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
702 702
 
703
-        foreach ( $items as $item ) {
704
-            $item      = new GetPaid_Form_Item( $item );
703
+        foreach ($items as $item) {
704
+            $item = new GetPaid_Form_Item($item);
705 705
             $data[] = array(
706 706
                 'id'        => (int) $item->get_id(),
707
-                'text'      => strip_tags( $item->get_name() ),
708
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
707
+                'text'      => strip_tags($item->get_name()),
708
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
709 709
             );
710 710
         }
711 711
 
712
-        wp_send_json_success( $data );
712
+        wp_send_json_success($data);
713 713
 
714 714
     }
715 715
 
@@ -719,24 +719,24 @@  discard block
 block discarded – undo
719 719
     public static function get_aui_states_field() {
720 720
 
721 721
         // Verify nonce.
722
-        check_ajax_referer( 'wpinv-nonce' );
722
+        check_ajax_referer('wpinv-nonce');
723 723
 
724 724
         // We need a country.
725
-        if ( empty( $_GET['country'] ) ) {
725
+        if (empty($_GET['country'])) {
726 726
             exit;
727 727
         }
728 728
 
729
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
730
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
729
+        $states = wpinv_get_country_states(trim($_GET['country']));
730
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
731 731
 
732
-        if ( empty( $states ) ) {
732
+        if (empty($states)) {
733 733
 
734 734
             $html = aui()->input(
735 735
                 array(
736 736
                     'type'        => 'text',
737 737
                     'id'          => 'wpinv_state',
738 738
                     'name'        => 'wpinv_state',
739
-                    'label'       => __( 'State', 'invoicing' ),
739
+                    'label'       => __('State', 'invoicing'),
740 740
                     'label_type'  => 'vertical',
741 741
                     'placeholder' => 'Liège',
742 742
                     'class'       => 'form-control-sm',
@@ -750,9 +750,9 @@  discard block
 block discarded – undo
750 750
                 array(
751 751
                     'id'          => 'wpinv_state',
752 752
                     'name'        => 'wpinv_state',
753
-                    'label'       => __( 'State', 'invoicing' ),
753
+                    'label'       => __('State', 'invoicing'),
754 754
                     'label_type'  => 'vertical',
755
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
755
+                    'placeholder' => __('Select a state', 'invoicing'),
756 756
                     'class'       => 'form-control-sm',
757 757
                     'value'       => $state,
758 758
                     'options'     => $states,
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
         wp_send_json_success(
767 767
             array(
768 768
                 'html'   => $html,
769
-                'select' => ! empty ( $states )
769
+                'select' => !empty ($states)
770 770
             )
771 771
         );
772 772
 
@@ -780,46 +780,46 @@  discard block
 block discarded – undo
780 780
     public static function ip_geolocation() {
781 781
 
782 782
         // Check nonce.
783
-        check_ajax_referer( 'getpaid-ip-location' );
783
+        check_ajax_referer('getpaid-ip-location');
784 784
 
785 785
         // IP address.
786
-        if ( empty( $_GET['ip'] ) || ! rest_is_ip_address( $_GET['ip'] ) ) {
787
-            _e( 'Invalid IP Address.', 'invoicing' );
786
+        if (empty($_GET['ip']) || !rest_is_ip_address($_GET['ip'])) {
787
+            _e('Invalid IP Address.', 'invoicing');
788 788
             exit;
789 789
         }
790 790
 
791 791
         // Retrieve location info.
792
-        $location = getpaid_geolocate_ip_address( $_GET['ip'] );
792
+        $location = getpaid_geolocate_ip_address($_GET['ip']);
793 793
 
794
-        if ( empty( $location ) ) {
795
-            _e( 'Unable to find geolocation for the IP Address.', 'invoicing' );
794
+        if (empty($location)) {
795
+            _e('Unable to find geolocation for the IP Address.', 'invoicing');
796 796
             exit;
797 797
         }
798 798
 
799 799
         // Sorry.
800
-        extract( $location );
800
+        extract($location);
801 801
 
802 802
         // Prepare the address.
803 803
         $content = '';
804 804
 
805
-        if ( ! empty( $location['city'] ) ) {
806
-            $content .=  $location['city']  . ', ';
805
+        if (!empty($location['city'])) {
806
+            $content .= $location['city'] . ', ';
807 807
         }
808 808
         
809
-        if ( ! empty( $location['region'] ) ) {
810
-            $content .=  $location['region']  . ', ';
809
+        if (!empty($location['region'])) {
810
+            $content .= $location['region'] . ', ';
811 811
         }
812 812
         
813
-        $content .=  $location['country'] . ' (' . $location['iso'] . ')';
813
+        $content .= $location['country'] . ' (' . $location['iso'] . ')';
814 814
 
815 815
         $location['address'] = $content;
816 816
 
817
-        $content  = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $content ) . '</p>';
818
-        $content .= '<p>'. $location['credit'] . '</p>';
817
+        $content  = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $content) . '</p>';
818
+        $content .= '<p>' . $location['credit'] . '</p>';
819 819
 
820 820
         $location['content'] = $content;
821 821
 
822
-        wpinv_get_template( 'geolocation.php', $location );
822
+        wpinv_get_template('geolocation.php', $location);
823 823
 
824 824
         exit;
825 825
     }
@@ -832,11 +832,11 @@  discard block
 block discarded – undo
832 832
     public static function payment_form_refresh_prices() {
833 833
 
834 834
         // Check nonce.
835
-        check_ajax_referer( 'getpaid_form_nonce' );
835
+        check_ajax_referer('getpaid_form_nonce');
836 836
 
837 837
         // ... form fields...
838
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
839
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
838
+        if (empty($_POST['getpaid_payment_form_submission'])) {
839
+            _e('Error: Reload the page and try again.', 'invoicing');
840 840
             exit;
841 841
         }
842 842
 
@@ -844,18 +844,18 @@  discard block
 block discarded – undo
844 844
         $submission = new GetPaid_Payment_Form_Submission();
845 845
 
846 846
         // Do we have an error?
847
-        if ( ! empty( $submission->last_error ) ) {
847
+        if (!empty($submission->last_error)) {
848 848
             echo $submission->last_error;
849 849
             exit;
850 850
         }
851 851
 
852 852
         // Prepare the response.
853
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
853
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
854 854
         
855 855
         // Filter the response.
856
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
856
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
857 857
 
858
-        wp_send_json_success( $response );
858
+        wp_send_json_success($response);
859 859
     }
860 860
 
861 861
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-payment-form.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit; // Exit if accessed directly
11 11
 }
12 12
 
@@ -20,14 +20,14 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param WP_Post $post
22 22
 	 */
23
-    public static function output( $post ) {
23
+    public static function output($post) {
24 24
         ?>
25 25
         <div id="wpinv-form-builder" class="bsui">
26 26
             <div class="row">
27 27
                 <div class="col-sm-4">
28 28
 
29 29
                     <!-- Builder tabs -->
30
-                    <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e( 'Go Back', 'invoicing' ); ?></button>
30
+                    <button class="button button-primary" v-if="active_tab!='new_item'" @click.prevent="active_tab='new_item'"><?php _e('Go Back', 'invoicing'); ?></button>
31 31
 
32 32
                     <!-- Builder tab content -->
33 33
                     <div class="mt-4">
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
                         <!-- Available builder elements -->
36 36
                         <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'">
37 37
                             <div class="wpinv-form-builder-add-field-types">
38
-                                <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small>
38
+                                <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small>
39 39
                                 <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable">
40 40
                                     <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }">
41 41
                                         <button class="button btn">
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
                         <!-- Edit an element -->
51 51
                         <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='edit_item'" style="font-size: 14px;">
52 52
                             <div class="wpinv-form-builder-edit-field-wrapper">
53
-                                <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?>
54
-                                <?php do_action( 'getpaid_payment_form_edit_element_template', $post ); ?>
53
+                                <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?>
54
+                                <?php do_action('getpaid_payment_form_edit_element_template', $post); ?>
55 55
                                 <div>
56
-                                    <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Element', 'invoicing' ); ?></button>
56
+                                    <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Element', 'invoicing'); ?></button>
57 57
                                 </div>
58 58
                             </div>
59 59
                         </div>
@@ -62,14 +62,14 @@  discard block
 block discarded – undo
62 62
 
63 63
                 </div>
64 64
                 <div class="col-sm-8 border-left">
65
-                    <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small>
66
-                    <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p>
65
+                    <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small>
66
+                    <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p>
67 67
 
68 68
                     <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 14px;">
69 69
                         <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="[{ active: active_form_element==form_element &&  active_tab=='edit_item' }, form_element.type]" @click="active_tab = 'edit_item'; active_form_element = form_element">
70 70
                             <div class="wpinv-form-builder-element-preview-inner">
71 71
                                 <div class="wpinv-payment-form-field-preview-overlay"></div>
72
-                                <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?>
72
+                                <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?>
73 73
                             </div>
74 74
                         </div>
75 75
                     </draggable>
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
         </div>
83 83
         <?php
84 84
 
85
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
85
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
86 86
     }
87 87
 
88 88
     /**
@@ -90,33 +90,33 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @param int $post_id
92 92
 	 */
93
-	public static function save( $post_id ) {
93
+	public static function save($post_id) {
94 94
 
95 95
         // Prepare the form.
96
-        $form = new GetPaid_Payment_Form( $post_id );
96
+        $form = new GetPaid_Payment_Form($post_id);
97 97
 
98 98
         // Fetch form items.
99
-        $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true );
99
+        $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true);
100 100
 
101 101
         // Ensure that we have an array...
102
-        if ( empty( $form_items ) ) {
102
+        if (empty($form_items)) {
103 103
             $form_items = array();
104 104
         }
105 105
 
106 106
         // Add it to the form.
107
-        $form->set_items( self::item_to_objects( $form_items ) );
107
+        $form->set_items(self::item_to_objects($form_items));
108 108
 
109 109
         // Save form elements.
110
-        $form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true );
111
-        if ( empty( $form_elements ) ) {
110
+        $form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true);
111
+        if (empty($form_elements)) {
112 112
             $form_elements = array();
113 113
         }
114 114
 
115
-        $form->set_elements( $form_elements );
115
+        $form->set_elements($form_elements);
116 116
 
117 117
         // Persist data to the datastore.
118 118
         $form->save();
119
-        do_action( 'getpaid_payment_form_metabox_save', $post_id, $form );
119
+        do_action('getpaid_payment_form_metabox_save', $post_id, $form);
120 120
 
121 121
     }
122 122
 
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
 	 *
126 126
 	 * @param array $items
127 127
 	 */
128
-	public static function item_to_objects( $items ) {
128
+	public static function item_to_objects($items) {
129 129
 
130 130
         $objects = array();
131 131
 
132
-        foreach ( $items as $item ) {
133
-            $_item = new GetPaid_Form_Item( $item['id'] );
134
-            $_item->set_allow_quantities( (bool) $item['allow_quantities'] );
135
-            $_item->set_is_required( (bool) $item['required'] );
132
+        foreach ($items as $item) {
133
+            $_item = new GetPaid_Form_Item($item['id']);
134
+            $_item->set_allow_quantities((bool) $item['allow_quantities']);
135
+            $_item->set_is_required((bool) $item['required']);
136 136
             $objects[] = $_item;
137 137
         }
138 138
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-form-item.php 2 patches
Indentation   +349 added lines, -349 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,60 +10,60 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Form_Item  extends WPInv_Item {
11 11
 
12 12
     /**
13
-	 * Stores a custom description for the item.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $custom_description = null;
18
-
19
-	/**
20
-	 * Stores the item quantity.
21
-	 *
22
-	 * @var int
23
-	 */
24
-	protected $quantity = 1;
25
-
26
-	/**
27
-	 * Stores the item meta.
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $meta = array();
32
-
33
-	/**
34
-	 * Is this item required?
35
-	 *
36
-	 * @var int
37
-	 */
38
-	protected $is_required = true;
39
-
40
-	/**
41
-	 * Are quantities allowed?
42
-	 *
43
-	 * @var int
44
-	 */
45
-	protected $allow_quantities = false;
46
-
47
-	/**
48
-	 * Associated invoice.
49
-	 *
50
-	 * @var int
51
-	 */
52
-	public $invoice_id = 0;
53
-
54
-	/**
55
-	 * Item discount.
56
-	 *
57
-	 * @var float
58
-	 */
59
-	public $item_discount = 0;
60
-
61
-	/**
62
-	 * Item tax.
63
-	 *
64
-	 * @var float
65
-	 */
66
-	public $item_tax = 0;
13
+     * Stores a custom description for the item.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $custom_description = null;
18
+
19
+    /**
20
+     * Stores the item quantity.
21
+     *
22
+     * @var int
23
+     */
24
+    protected $quantity = 1;
25
+
26
+    /**
27
+     * Stores the item meta.
28
+     *
29
+     * @var array
30
+     */
31
+    protected $meta = array();
32
+
33
+    /**
34
+     * Is this item required?
35
+     *
36
+     * @var int
37
+     */
38
+    protected $is_required = true;
39
+
40
+    /**
41
+     * Are quantities allowed?
42
+     *
43
+     * @var int
44
+     */
45
+    protected $allow_quantities = false;
46
+
47
+    /**
48
+     * Associated invoice.
49
+     *
50
+     * @var int
51
+     */
52
+    public $invoice_id = 0;
53
+
54
+    /**
55
+     * Item discount.
56
+     *
57
+     * @var float
58
+     */
59
+    public $item_discount = 0;
60
+
61
+    /**
62
+     * Item tax.
63
+     *
64
+     * @var float
65
+     */
66
+    public $item_tax = 0;
67 67
 
68 68
     /*
69 69
 	|--------------------------------------------------------------------------
@@ -81,227 +81,227 @@  discard block
 block discarded – undo
81 81
     */
82 82
 
83 83
     /**
84
-	 * Get the item name.
85
-	 *
86
-	 * @since 1.0.19
87
-	 * @param  string $context View or edit context.
88
-	 * @return string
89
-	 */
90
-	public function get_name( $context = 'view' ) {
91
-		$name = parent::get_name( $context );
92
-		return $name . wpinv_get_item_suffix( $this );
93
-	}
94
-
95
-	/**
96
-	 * Get the item name without a suffix.
97
-	 *
98
-	 * @since 1.0.19
99
-	 * @param  string $context View or edit context.
100
-	 * @return string
101
-	 */
102
-	public function get_raw_name( $context = 'view' ) {
103
-		return parent::get_name( $context );
104
-	}
105
-
106
-	/**
107
-	 * Get the item description.
108
-	 *
109
-	 * @since 1.0.19
110
-	 * @param  string $context View or edit context.
111
-	 * @return string
112
-	 */
113
-	public function get_description( $context = 'view' ) {
114
-
115
-		if ( isset( $this->custom_description ) ) {
116
-			return $this->custom_description;
117
-		}
118
-
119
-		return parent::get_description( $context );
120
-	}
121
-
122
-	/**
123
-	 * Returns the sub total.
124
-	 *
125
-	 * @since 1.0.19
126
-	 * @param  string $context View or edit context.
127
-	 * @return int
128
-	 */
129
-	public function get_sub_total( $context = 'view' ) {
130
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
131
-	}
132
-
133
-	/**
134
-	 * Returns the recurring sub total.
135
-	 *
136
-	 * @since 1.0.19
137
-	 * @param  string $context View or edit context.
138
-	 * @return int
139
-	 */
140
-	public function get_recurring_sub_total( $context = 'view' ) {
141
-		return $this->get_quantity( $context ) * $this->get_price( $context );
142
-	}
143
-
144
-	/**
145
-	 * @deprecated
146
-	 */
147
-	public function get_qantity( $context = 'view' ) {
148
-		return $this->get_quantity( $context );
149
-	}
150
-
151
-	/**
152
-	 * Get the item quantity.
153
-	 *
154
-	 * @since 1.0.19
155
-	 * @param  string $context View or edit context.
156
-	 * @return int
157
-	 */
158
-	public function get_quantity( $context = 'view' ) {
159
-		$quantity = (int) $this->quantity;
160
-
161
-		if ( empty( $quantity ) || 1 > $quantity ) {
162
-			$quantity = 1;
163
-		}
164
-
165
-		if ( 'view' == $context ) {
166
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
167
-		}
168
-
169
-		return $quantity;
170
-
171
-	}
172
-
173
-	/**
174
-	 * Get the item meta data.
175
-	 *
176
-	 * @since 1.0.19
177
-	 * @param  string $context View or edit context.
178
-	 * @return meta
179
-	 */
180
-	public function get_item_meta( $context = 'view' ) {
181
-		$meta = $this->meta;
182
-
183
-		if ( 'view' == $context ) {
184
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
185
-		}
186
-
187
-		return $meta;
188
-
189
-	}
190
-
191
-	/**
192
-	 * Returns whether or not customers can update the item quantity.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @param  string $context View or edit context.
196
-	 * @return bool
197
-	 */
198
-	public function get_allow_quantities( $context = 'view' ) {
199
-		$allow_quantities = (bool) $this->allow_quantities;
200
-
201
-		if ( 'view' == $context ) {
202
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
203
-		}
204
-
205
-		return $allow_quantities;
206
-
207
-	}
208
-
209
-	/**
210
-	 * Returns whether or not the item is required.
211
-	 *
212
-	 * @since 1.0.19
213
-	 * @param  string $context View or edit context.
214
-	 * @return bool
215
-	 */
216
-	public function get_is_required( $context = 'view' ) {
217
-		$is_required = (bool) $this->is_required;
218
-
219
-		if ( 'view' == $context ) {
220
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
221
-		}
222
-
223
-		return $is_required;
224
-
225
-	}
226
-
227
-	/**
228
-	 * Prepares form data for use.
229
-	 *
230
-	 * @since 1.0.19
231
-	 * @return array
232
-	 */
233
-	public function prepare_data_for_use( $required = null ) {
234
-
235
-		$required = is_null( $required ) ? $this->is_required() : $required;
236
-		return array(
237
-			'title'            => strip_tags( $this->get_name() ),
238
-			'id'               => $this->get_id(),
239
-			'price'            => $this->get_price(),
240
-			'recurring'        => $this->is_recurring(),
241
-			'description'      => $this->get_description(),
242
-			'allow_quantities' => $this->allows_quantities(),
243
-			'required'         => $required,
244
-		);
245
-
246
-	}
247
-
248
-	/**
249
-	 * Prepares form data for ajax use.
250
-	 *
251
-	 * @since 1.0.19
252
-	 * @return array
253
-	 */
254
-	public function prepare_data_for_invoice_edit_ajax( $currency = '' ) {
255
-
256
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
257
-
258
-		if ( $description ) {
259
-			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
260
-		}
261
-
262
-		return array(
263
-			'id'     => $this->get_id(),
264
-			'texts'  => array(
265
-				'item-name'        => sanitize_text_field( $this->get_name() ),
266
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
267
-				'item-quantity'    => absint( $this->get_quantity() ),
268
-				'item-price'       => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ),
269
-				'item-total'       => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ),
270
-			),
271
-			'inputs' => array(
272
-				'item-id'          => $this->get_id(),
273
-				'item-name'        => sanitize_text_field( $this->get_name() ),
274
-				'item-description' => wp_kses_post( $this->get_description() ),
275
-				'item-quantity'    => absint( $this->get_quantity() ),
276
-				'item-price'       => $this->get_price(),
277
-			)
278
-		);
279
-
280
-	}
281
-
282
-	/**
283
-	 * Prepares form data for saving (cart_details).
284
-	 *
285
-	 * @since 1.0.19
286
-	 * @return array
287
-	 */
288
-	public function prepare_data_for_saving() {
289
-
290
-		return array(
291
-			'post_id'           => $this->invoice_id,
292
-			'item_id'           => $this->get_id(),
293
-			'item_name'         => sanitize_text_field( $this->get_raw_name() ),
294
-			'item_description'  => $this->get_description(),
295
-			'tax'               => $this->item_tax,
296
-			'item_price'        => $this->get_price(),
297
-			'quantity'          => (int) $this->get_quantity(),
298
-			'discount'          => $this->item_discount,
299
-			'subtotal'          => $this->get_sub_total(),
300
-			'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount,
301
-			'meta'              => $this->get_item_meta(),
302
-		);
303
-
304
-	}
84
+     * Get the item name.
85
+     *
86
+     * @since 1.0.19
87
+     * @param  string $context View or edit context.
88
+     * @return string
89
+     */
90
+    public function get_name( $context = 'view' ) {
91
+        $name = parent::get_name( $context );
92
+        return $name . wpinv_get_item_suffix( $this );
93
+    }
94
+
95
+    /**
96
+     * Get the item name without a suffix.
97
+     *
98
+     * @since 1.0.19
99
+     * @param  string $context View or edit context.
100
+     * @return string
101
+     */
102
+    public function get_raw_name( $context = 'view' ) {
103
+        return parent::get_name( $context );
104
+    }
105
+
106
+    /**
107
+     * Get the item description.
108
+     *
109
+     * @since 1.0.19
110
+     * @param  string $context View or edit context.
111
+     * @return string
112
+     */
113
+    public function get_description( $context = 'view' ) {
114
+
115
+        if ( isset( $this->custom_description ) ) {
116
+            return $this->custom_description;
117
+        }
118
+
119
+        return parent::get_description( $context );
120
+    }
121
+
122
+    /**
123
+     * Returns the sub total.
124
+     *
125
+     * @since 1.0.19
126
+     * @param  string $context View or edit context.
127
+     * @return int
128
+     */
129
+    public function get_sub_total( $context = 'view' ) {
130
+        return $this->get_quantity( $context ) * $this->get_initial_price( $context );
131
+    }
132
+
133
+    /**
134
+     * Returns the recurring sub total.
135
+     *
136
+     * @since 1.0.19
137
+     * @param  string $context View or edit context.
138
+     * @return int
139
+     */
140
+    public function get_recurring_sub_total( $context = 'view' ) {
141
+        return $this->get_quantity( $context ) * $this->get_price( $context );
142
+    }
143
+
144
+    /**
145
+     * @deprecated
146
+     */
147
+    public function get_qantity( $context = 'view' ) {
148
+        return $this->get_quantity( $context );
149
+    }
150
+
151
+    /**
152
+     * Get the item quantity.
153
+     *
154
+     * @since 1.0.19
155
+     * @param  string $context View or edit context.
156
+     * @return int
157
+     */
158
+    public function get_quantity( $context = 'view' ) {
159
+        $quantity = (int) $this->quantity;
160
+
161
+        if ( empty( $quantity ) || 1 > $quantity ) {
162
+            $quantity = 1;
163
+        }
164
+
165
+        if ( 'view' == $context ) {
166
+            return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
167
+        }
168
+
169
+        return $quantity;
170
+
171
+    }
172
+
173
+    /**
174
+     * Get the item meta data.
175
+     *
176
+     * @since 1.0.19
177
+     * @param  string $context View or edit context.
178
+     * @return meta
179
+     */
180
+    public function get_item_meta( $context = 'view' ) {
181
+        $meta = $this->meta;
182
+
183
+        if ( 'view' == $context ) {
184
+            return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
185
+        }
186
+
187
+        return $meta;
188
+
189
+    }
190
+
191
+    /**
192
+     * Returns whether or not customers can update the item quantity.
193
+     *
194
+     * @since 1.0.19
195
+     * @param  string $context View or edit context.
196
+     * @return bool
197
+     */
198
+    public function get_allow_quantities( $context = 'view' ) {
199
+        $allow_quantities = (bool) $this->allow_quantities;
200
+
201
+        if ( 'view' == $context ) {
202
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
203
+        }
204
+
205
+        return $allow_quantities;
206
+
207
+    }
208
+
209
+    /**
210
+     * Returns whether or not the item is required.
211
+     *
212
+     * @since 1.0.19
213
+     * @param  string $context View or edit context.
214
+     * @return bool
215
+     */
216
+    public function get_is_required( $context = 'view' ) {
217
+        $is_required = (bool) $this->is_required;
218
+
219
+        if ( 'view' == $context ) {
220
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
221
+        }
222
+
223
+        return $is_required;
224
+
225
+    }
226
+
227
+    /**
228
+     * Prepares form data for use.
229
+     *
230
+     * @since 1.0.19
231
+     * @return array
232
+     */
233
+    public function prepare_data_for_use( $required = null ) {
234
+
235
+        $required = is_null( $required ) ? $this->is_required() : $required;
236
+        return array(
237
+            'title'            => strip_tags( $this->get_name() ),
238
+            'id'               => $this->get_id(),
239
+            'price'            => $this->get_price(),
240
+            'recurring'        => $this->is_recurring(),
241
+            'description'      => $this->get_description(),
242
+            'allow_quantities' => $this->allows_quantities(),
243
+            'required'         => $required,
244
+        );
245
+
246
+    }
247
+
248
+    /**
249
+     * Prepares form data for ajax use.
250
+     *
251
+     * @since 1.0.19
252
+     * @return array
253
+     */
254
+    public function prepare_data_for_invoice_edit_ajax( $currency = '' ) {
255
+
256
+        $description = getpaid_item_recurring_price_help_text( $this, $currency );
257
+
258
+        if ( $description ) {
259
+            $description = "<div class='getpaid-subscription-help-text'>$description</div>";
260
+        }
261
+
262
+        return array(
263
+            'id'     => $this->get_id(),
264
+            'texts'  => array(
265
+                'item-name'        => sanitize_text_field( $this->get_name() ),
266
+                'item-description' => wp_kses_post( $this->get_description() ) . $description,
267
+                'item-quantity'    => absint( $this->get_quantity() ),
268
+                'item-price'       => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ),
269
+                'item-total'       => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ),
270
+            ),
271
+            'inputs' => array(
272
+                'item-id'          => $this->get_id(),
273
+                'item-name'        => sanitize_text_field( $this->get_name() ),
274
+                'item-description' => wp_kses_post( $this->get_description() ),
275
+                'item-quantity'    => absint( $this->get_quantity() ),
276
+                'item-price'       => $this->get_price(),
277
+            )
278
+        );
279
+
280
+    }
281
+
282
+    /**
283
+     * Prepares form data for saving (cart_details).
284
+     *
285
+     * @since 1.0.19
286
+     * @return array
287
+     */
288
+    public function prepare_data_for_saving() {
289
+
290
+        return array(
291
+            'post_id'           => $this->invoice_id,
292
+            'item_id'           => $this->get_id(),
293
+            'item_name'         => sanitize_text_field( $this->get_raw_name() ),
294
+            'item_description'  => $this->get_description(),
295
+            'tax'               => $this->item_tax,
296
+            'item_price'        => $this->get_price(),
297
+            'quantity'          => (int) $this->get_quantity(),
298
+            'discount'          => $this->item_discount,
299
+            'subtotal'          => $this->get_sub_total(),
300
+            'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount,
301
+            'meta'              => $this->get_item_meta(),
302
+        );
303
+
304
+    }
305 305
 
306 306
     /*
307 307
 	|--------------------------------------------------------------------------
@@ -313,70 +313,70 @@  discard block
 block discarded – undo
313 313
 	| object.
314 314
     */
315 315
 
316
-	/**
317
-	 * Set the item qantity.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @param  int $quantity The item quantity.
321
-	 */
322
-	public function set_quantity( $quantity ) {
323
-
324
-		if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
325
-			$quantity = 1;
326
-		}
327
-
328
-		$this->quantity = (int) $quantity;
329
-
330
-	}
331
-
332
-	/**
333
-	 * Set the item meta data.
334
-	 *
335
-	 * @since 1.0.19
336
-	 * @param  array $meta The item meta data.
337
-	 */
338
-	public function set_item_meta( $meta ) {
339
-		$this->meta = maybe_unserialize( $meta );
340
-	}
341
-
342
-	/**
343
-	 * Set whether or not the quantities are allowed.
344
-	 *
345
-	 * @since 1.0.19
346
-	 * @param  bool $allow_quantities
347
-	 */
348
-	public function set_allow_quantities( $allow_quantities ) {
349
-		$this->allow_quantities = (bool) $allow_quantities;
350
-	}
351
-
352
-	/**
353
-	 * Set whether or not the item is required.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  bool $is_required
357
-	 */
358
-	public function set_is_required( $is_required ) {
359
-		$this->is_required = (bool) $is_required;
360
-	}
361
-
362
-	/**
363
-	 * Sets the custom item description.
364
-	 *
365
-	 * @since 1.0.19
366
-	 * @param  string $description
367
-	 */
368
-	public function set_custom_description( $description ) {
369
-		$this->custom_description = $description;
370
-	}
316
+    /**
317
+     * Set the item qantity.
318
+     *
319
+     * @since 1.0.19
320
+     * @param  int $quantity The item quantity.
321
+     */
322
+    public function set_quantity( $quantity ) {
323
+
324
+        if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
325
+            $quantity = 1;
326
+        }
327
+
328
+        $this->quantity = (int) $quantity;
329
+
330
+    }
331
+
332
+    /**
333
+     * Set the item meta data.
334
+     *
335
+     * @since 1.0.19
336
+     * @param  array $meta The item meta data.
337
+     */
338
+    public function set_item_meta( $meta ) {
339
+        $this->meta = maybe_unserialize( $meta );
340
+    }
341
+
342
+    /**
343
+     * Set whether or not the quantities are allowed.
344
+     *
345
+     * @since 1.0.19
346
+     * @param  bool $allow_quantities
347
+     */
348
+    public function set_allow_quantities( $allow_quantities ) {
349
+        $this->allow_quantities = (bool) $allow_quantities;
350
+    }
351
+
352
+    /**
353
+     * Set whether or not the item is required.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  bool $is_required
357
+     */
358
+    public function set_is_required( $is_required ) {
359
+        $this->is_required = (bool) $is_required;
360
+    }
361
+
362
+    /**
363
+     * Sets the custom item description.
364
+     *
365
+     * @since 1.0.19
366
+     * @param  string $description
367
+     */
368
+    public function set_custom_description( $description ) {
369
+        $this->custom_description = $description;
370
+    }
371 371
 
372 372
     /**
373 373
      * We do not want to save items to the database.
374 374
      * 
375
-	 * @return int item id
375
+     * @return int item id
376 376
      */
377 377
     public function save( $data = array() ) {
378 378
         return $this->get_id();
379
-	}
379
+    }
380 380
 
381 381
     /*
382 382
 	|--------------------------------------------------------------------------
@@ -388,23 +388,23 @@  discard block
 block discarded – undo
388 388
 	*/
389 389
 
390 390
     /**
391
-	 * Checks whether the item has enabled dynamic pricing.
392
-	 *
393
-	 * @since 1.0.19
394
-	 * @return bool
395
-	 */
396
-	public function is_required() {
391
+     * Checks whether the item has enabled dynamic pricing.
392
+     *
393
+     * @since 1.0.19
394
+     * @return bool
395
+     */
396
+    public function is_required() {
397 397
         return (bool) $this->get_is_required();
398
-	}
399
-
400
-	/**
401
-	 * Checks whether users can edit the quantities.
402
-	 *
403
-	 * @since 1.0.19
404
-	 * @return bool
405
-	 */
406
-	public function allows_quantities() {
398
+    }
399
+
400
+    /**
401
+     * Checks whether users can edit the quantities.
402
+     *
403
+     * @since 1.0.19
404
+     * @return bool
405
+     */
406
+    public function allows_quantities() {
407 407
         return (bool) $this->get_allow_quantities();
408
-	}
408
+    }
409 409
 
410 410
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 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
 
@@ -87,9 +87,9 @@  discard block
 block discarded – undo
87 87
 	 * @param  string $context View or edit context.
88 88
 	 * @return string
89 89
 	 */
90
-	public function get_name( $context = 'view' ) {
91
-		$name = parent::get_name( $context );
92
-		return $name . wpinv_get_item_suffix( $this );
90
+	public function get_name($context = 'view') {
91
+		$name = parent::get_name($context);
92
+		return $name . wpinv_get_item_suffix($this);
93 93
 	}
94 94
 
95 95
 	/**
@@ -99,8 +99,8 @@  discard block
 block discarded – undo
99 99
 	 * @param  string $context View or edit context.
100 100
 	 * @return string
101 101
 	 */
102
-	public function get_raw_name( $context = 'view' ) {
103
-		return parent::get_name( $context );
102
+	public function get_raw_name($context = 'view') {
103
+		return parent::get_name($context);
104 104
 	}
105 105
 
106 106
 	/**
@@ -110,13 +110,13 @@  discard block
 block discarded – undo
110 110
 	 * @param  string $context View or edit context.
111 111
 	 * @return string
112 112
 	 */
113
-	public function get_description( $context = 'view' ) {
113
+	public function get_description($context = 'view') {
114 114
 
115
-		if ( isset( $this->custom_description ) ) {
115
+		if (isset($this->custom_description)) {
116 116
 			return $this->custom_description;
117 117
 		}
118 118
 
119
-		return parent::get_description( $context );
119
+		return parent::get_description($context);
120 120
 	}
121 121
 
122 122
 	/**
@@ -126,8 +126,8 @@  discard block
 block discarded – undo
126 126
 	 * @param  string $context View or edit context.
127 127
 	 * @return int
128 128
 	 */
129
-	public function get_sub_total( $context = 'view' ) {
130
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
129
+	public function get_sub_total($context = 'view') {
130
+		return $this->get_quantity($context) * $this->get_initial_price($context);
131 131
 	}
132 132
 
133 133
 	/**
@@ -137,15 +137,15 @@  discard block
 block discarded – undo
137 137
 	 * @param  string $context View or edit context.
138 138
 	 * @return int
139 139
 	 */
140
-	public function get_recurring_sub_total( $context = 'view' ) {
141
-		return $this->get_quantity( $context ) * $this->get_price( $context );
140
+	public function get_recurring_sub_total($context = 'view') {
141
+		return $this->get_quantity($context) * $this->get_price($context);
142 142
 	}
143 143
 
144 144
 	/**
145 145
 	 * @deprecated
146 146
 	 */
147
-	public function get_qantity( $context = 'view' ) {
148
-		return $this->get_quantity( $context );
147
+	public function get_qantity($context = 'view') {
148
+		return $this->get_quantity($context);
149 149
 	}
150 150
 
151 151
 	/**
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
 	 * @param  string $context View or edit context.
156 156
 	 * @return int
157 157
 	 */
158
-	public function get_quantity( $context = 'view' ) {
158
+	public function get_quantity($context = 'view') {
159 159
 		$quantity = (int) $this->quantity;
160 160
 
161
-		if ( empty( $quantity ) || 1 > $quantity ) {
161
+		if (empty($quantity) || 1 > $quantity) {
162 162
 			$quantity = 1;
163 163
 		}
164 164
 
165
-		if ( 'view' == $context ) {
166
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
165
+		if ('view' == $context) {
166
+			return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this);
167 167
 		}
168 168
 
169 169
 		return $quantity;
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 	 * @param  string $context View or edit context.
178 178
 	 * @return meta
179 179
 	 */
180
-	public function get_item_meta( $context = 'view' ) {
180
+	public function get_item_meta($context = 'view') {
181 181
 		$meta = $this->meta;
182 182
 
183
-		if ( 'view' == $context ) {
184
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
183
+		if ('view' == $context) {
184
+			return apply_filters('getpaid_payment_form_item_meta', $meta, $this);
185 185
 		}
186 186
 
187 187
 		return $meta;
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
 	 * @param  string $context View or edit context.
196 196
 	 * @return bool
197 197
 	 */
198
-	public function get_allow_quantities( $context = 'view' ) {
198
+	public function get_allow_quantities($context = 'view') {
199 199
 		$allow_quantities = (bool) $this->allow_quantities;
200 200
 
201
-		if ( 'view' == $context ) {
202
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
201
+		if ('view' == $context) {
202
+			return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this);
203 203
 		}
204 204
 
205 205
 		return $allow_quantities;
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
 	 * @param  string $context View or edit context.
214 214
 	 * @return bool
215 215
 	 */
216
-	public function get_is_required( $context = 'view' ) {
216
+	public function get_is_required($context = 'view') {
217 217
 		$is_required = (bool) $this->is_required;
218 218
 
219
-		if ( 'view' == $context ) {
220
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
219
+		if ('view' == $context) {
220
+			return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this);
221 221
 		}
222 222
 
223 223
 		return $is_required;
@@ -230,11 +230,11 @@  discard block
 block discarded – undo
230 230
 	 * @since 1.0.19
231 231
 	 * @return array
232 232
 	 */
233
-	public function prepare_data_for_use( $required = null ) {
233
+	public function prepare_data_for_use($required = null) {
234 234
 
235
-		$required = is_null( $required ) ? $this->is_required() : $required;
235
+		$required = is_null($required) ? $this->is_required() : $required;
236 236
 		return array(
237
-			'title'            => strip_tags( $this->get_name() ),
237
+			'title'            => strip_tags($this->get_name()),
238 238
 			'id'               => $this->get_id(),
239 239
 			'price'            => $this->get_price(),
240 240
 			'recurring'        => $this->is_recurring(),
@@ -251,28 +251,28 @@  discard block
 block discarded – undo
251 251
 	 * @since 1.0.19
252 252
 	 * @return array
253 253
 	 */
254
-	public function prepare_data_for_invoice_edit_ajax( $currency = '' ) {
254
+	public function prepare_data_for_invoice_edit_ajax($currency = '') {
255 255
 
256
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
256
+		$description = getpaid_item_recurring_price_help_text($this, $currency);
257 257
 
258
-		if ( $description ) {
258
+		if ($description) {
259 259
 			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
260 260
 		}
261 261
 
262 262
 		return array(
263 263
 			'id'     => $this->get_id(),
264 264
 			'texts'  => array(
265
-				'item-name'        => sanitize_text_field( $this->get_name() ),
266
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
267
-				'item-quantity'    => absint( $this->get_quantity() ),
268
-				'item-price'       => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ),
269
-				'item-total'       => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ),
265
+				'item-name'        => sanitize_text_field($this->get_name()),
266
+				'item-description' => wp_kses_post($this->get_description()) . $description,
267
+				'item-quantity'    => absint($this->get_quantity()),
268
+				'item-price'       => wpinv_price(wpinv_format_amount($this->get_price()), $currency),
269
+				'item-total'       => wpinv_price(wpinv_format_amount($this->get_sub_total()), $currency),
270 270
 			),
271 271
 			'inputs' => array(
272 272
 				'item-id'          => $this->get_id(),
273
-				'item-name'        => sanitize_text_field( $this->get_name() ),
274
-				'item-description' => wp_kses_post( $this->get_description() ),
275
-				'item-quantity'    => absint( $this->get_quantity() ),
273
+				'item-name'        => sanitize_text_field($this->get_name()),
274
+				'item-description' => wp_kses_post($this->get_description()),
275
+				'item-quantity'    => absint($this->get_quantity()),
276 276
 				'item-price'       => $this->get_price(),
277 277
 			)
278 278
 		);
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 		return array(
291 291
 			'post_id'           => $this->invoice_id,
292 292
 			'item_id'           => $this->get_id(),
293
-			'item_name'         => sanitize_text_field( $this->get_raw_name() ),
293
+			'item_name'         => sanitize_text_field($this->get_raw_name()),
294 294
 			'item_description'  => $this->get_description(),
295 295
 			'tax'               => $this->item_tax,
296 296
 			'item_price'        => $this->get_price(),
@@ -319,9 +319,9 @@  discard block
 block discarded – undo
319 319
 	 * @since 1.0.19
320 320
 	 * @param  int $quantity The item quantity.
321 321
 	 */
322
-	public function set_quantity( $quantity ) {
322
+	public function set_quantity($quantity) {
323 323
 
324
-		if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
324
+		if (empty($quantity) || !is_numeric($quantity)) {
325 325
 			$quantity = 1;
326 326
 		}
327 327
 
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
 	 * @since 1.0.19
336 336
 	 * @param  array $meta The item meta data.
337 337
 	 */
338
-	public function set_item_meta( $meta ) {
339
-		$this->meta = maybe_unserialize( $meta );
338
+	public function set_item_meta($meta) {
339
+		$this->meta = maybe_unserialize($meta);
340 340
 	}
341 341
 
342 342
 	/**
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 * @since 1.0.19
346 346
 	 * @param  bool $allow_quantities
347 347
 	 */
348
-	public function set_allow_quantities( $allow_quantities ) {
348
+	public function set_allow_quantities($allow_quantities) {
349 349
 		$this->allow_quantities = (bool) $allow_quantities;
350 350
 	}
351 351
 
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 * @since 1.0.19
356 356
 	 * @param  bool $is_required
357 357
 	 */
358
-	public function set_is_required( $is_required ) {
358
+	public function set_is_required($is_required) {
359 359
 		$this->is_required = (bool) $is_required;
360 360
 	}
361 361
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @since 1.0.19
366 366
 	 * @param  string $description
367 367
 	 */
368
-	public function set_custom_description( $description ) {
368
+	public function set_custom_description($description) {
369 369
 		$this->custom_description = $description;
370 370
 	}
371 371
 
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
      * 
375 375
 	 * @return int item id
376 376
      */
377
-    public function save( $data = array() ) {
377
+    public function save($data = array()) {
378 378
         return $this->get_id();
379 379
 	}
380 380
 
Please login to merge, or discard this patch.