Passed
Push — master ( 35bd8d...8ba8d0 )
by Brian
10:42 queued 04:43
created
includes/class-wpinv-payment-form-elements.php 1 patch
Spacing   +658 added lines, -658 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
     exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -13,19 +13,19 @@  discard block
 block discarded – undo
13 13
 
14 14
     public function __construct() {
15 15
 
16
-        foreach( $this->get_elements() as $element ) {
16
+        foreach ($this->get_elements() as $element) {
17 17
             $element = $element['type'];
18 18
 
19
-            if ( method_exists( $this, "render_{$element}_template" ) ) {
20
-                add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 );
19
+            if (method_exists($this, "render_{$element}_template")) {
20
+                add_action('wpinv_payment_form_render_element_template', array($this, "render_{$element}_template"), 10, 2);
21 21
             }
22 22
 
23
-            if ( method_exists( $this, "edit_{$element}_template" ) ) {
24
-                add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 );
23
+            if (method_exists($this, "edit_{$element}_template")) {
24
+                add_action('wpinv_payment_form_edit_element_template', array($this, "edit_{$element}_template"), 10, 2);
25 25
             }
26 26
 
27
-            if ( method_exists( $this, "frontend_render_{$element}_template" ) ) {
28
-                add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 );
27
+            if (method_exists($this, "frontend_render_{$element}_template")) {
28
+                add_action("wpinv_frontend_render_payment_form_$element", array($this, "frontend_render_{$element}_template"), 10, 3);
29 29
             }
30 30
 
31 31
         }
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function get_elements() {
39 39
 
40
-        if ( ! empty( $this->elements ) ) {
40
+        if (!empty($this->elements)) {
41 41
             return $this->elements;
42 42
         }
43 43
 
@@ -45,28 +45,28 @@  discard block
 block discarded – undo
45 45
 
46 46
             array(
47 47
                 'type'     => 'heading',
48
-                'name'     => __( 'Heading', 'invoicing' ),
48
+                'name'     => __('Heading', 'invoicing'),
49 49
                 'defaults' => array(
50 50
                     'level' => 'h2',
51
-                    'text'  => __( 'Heading', 'invoicing' ),
51
+                    'text'  => __('Heading', 'invoicing'),
52 52
                 )
53 53
             ),
54 54
 
55 55
             array(
56 56
                 'type' => 'paragraph',
57
-                'name' => __( 'Paragraph', 'invoicing' ),
57
+                'name' => __('Paragraph', 'invoicing'),
58 58
                 'defaults'  => array(
59
-                    'text'  => __( 'Paragraph text', 'invoicing' ),
59
+                    'text'  => __('Paragraph text', 'invoicing'),
60 60
                 )
61 61
             ),
62 62
 
63 63
             array( 
64 64
                 'type' => 'alert',
65
-                'name' => __( 'Alert', 'invoicing' ),
65
+                'name' => __('Alert', 'invoicing'),
66 66
                 'defaults'  => array(
67 67
                     'value'        => '',
68 68
                     'class'        => 'alert-warning',
69
-                    'text'         => __( 'Alert', 'invoicing' ),
69
+                    'text'         => __('Alert', 'invoicing'),
70 70
                     'dismissible'  => false,
71 71
                 )
72 72
             ),
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 
83 83
             array(
84 84
                 'type' => 'text',
85
-                'name' => __( 'Text Input', 'invoicing' ),
85
+                'name' => __('Text Input', 'invoicing'),
86 86
                 'defaults'  => array(
87
-                    'placeholder'  => __( 'Enter some text', 'invoicing' ),
87
+                    'placeholder'  => __('Enter some text', 'invoicing'),
88 88
                     'value'        => '',
89
-                    'label'        => __( 'Field Label', 'invoicing' ),
89
+                    'label'        => __('Field Label', 'invoicing'),
90 90
                     'description'  => '',
91 91
                     'required'     => false,
92 92
                 )
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 
95 95
             array(
96 96
                 'type' => 'textarea',
97
-                'name' => __( 'Textarea', 'invoicing' ),
97
+                'name' => __('Textarea', 'invoicing'),
98 98
                 'defaults'         => array(
99
-                    'placeholder'  => __( 'Enter your text hear', 'invoicing' ),
99
+                    'placeholder'  => __('Enter your text hear', 'invoicing'),
100 100
                     'value'        => '',
101
-                    'label'        => __( 'Textarea Label', 'invoicing' ),
101
+                    'label'        => __('Textarea Label', 'invoicing'),
102 102
                     'description'  => '',
103 103
                     'required'     => false,
104 104
                 )
@@ -106,27 +106,27 @@  discard block
 block discarded – undo
106 106
 
107 107
             array(
108 108
                 'type' => 'select',
109
-                'name' => __( 'Dropdown', 'invoicing' ),
109
+                'name' => __('Dropdown', 'invoicing'),
110 110
                 'defaults'         => array(
111
-                    'placeholder'  => __( 'Select a value', 'invoicing' ),
111
+                    'placeholder'  => __('Select a value', 'invoicing'),
112 112
                     'value'        => '',
113
-                    'label'        => __( 'Dropdown Label', 'invoicing' ),
113
+                    'label'        => __('Dropdown Label', 'invoicing'),
114 114
                     'description'  => '',
115 115
                     'required'     => false,
116 116
                     'options'      => array(
117
-                        esc_attr__( 'Option One', 'invoicing' ),
118
-                        esc_attr__( 'Option Two', 'invoicing' ),
119
-                        esc_attr__( 'Option Three', 'invoicing' )
117
+                        esc_attr__('Option One', 'invoicing'),
118
+                        esc_attr__('Option Two', 'invoicing'),
119
+                        esc_attr__('Option Three', 'invoicing')
120 120
                     ),
121 121
                 )
122 122
             ),
123 123
 
124 124
             array(
125 125
                 'type' => 'checkbox',
126
-                'name' => __( 'Checkbox', 'invoicing' ),
126
+                'name' => __('Checkbox', 'invoicing'),
127 127
                 'defaults'         => array(
128 128
                     'value'        => '',
129
-                    'label'        => __( 'Checkbox Label', 'invoicing' ),
129
+                    'label'        => __('Checkbox Label', 'invoicing'),
130 130
                     'description'  => '',
131 131
                     'required'     => false,
132 132
                 )
@@ -134,23 +134,23 @@  discard block
 block discarded – undo
134 134
 
135 135
             array( 
136 136
                 'type' => 'radio',
137
-                'name' => __( 'Multiple Choice', 'invoicing' ),
137
+                'name' => __('Multiple Choice', 'invoicing'),
138 138
                 'defaults'     => array(
139
-                    'label'    => __( 'Select one choice', 'invoicing' ),
139
+                    'label'    => __('Select one choice', 'invoicing'),
140 140
                     'options'  => array(
141
-                        esc_attr__( 'Choice One', 'invoicing' ),
142
-                        esc_attr__( 'Choice Two', 'invoicing' ),
143
-                        esc_attr__( 'Choice Three', 'invoicing' )
141
+                        esc_attr__('Choice One', 'invoicing'),
142
+                        esc_attr__('Choice Two', 'invoicing'),
143
+                        esc_attr__('Choice Three', 'invoicing')
144 144
                     ),
145 145
                 )
146 146
             ),
147 147
 
148 148
             array( 
149 149
                 'type' => 'date',
150
-                'name' => __( 'Date', 'invoicing' ),
150
+                'name' => __('Date', 'invoicing'),
151 151
                 'defaults' => array(
152 152
                     'value'        => '',
153
-                    'label'        => __( 'Date', 'invoicing' ),
153
+                    'label'        => __('Date', 'invoicing'),
154 154
                     'description'  => '',
155 155
                     'required'     => false,
156 156
                 )
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
 
159 159
             array( 
160 160
                 'type' => 'time',
161
-                'name' => __( 'Time', 'invoicing' ),
161
+                'name' => __('Time', 'invoicing'),
162 162
                 'defaults' => array(
163 163
                     'value'        => '',
164
-                    'label'        => __( 'Time', 'invoicing' ),
164
+                    'label'        => __('Time', 'invoicing'),
165 165
                     'description'  => '',
166 166
                     'required'     => false,
167 167
                 )
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 
170 170
             array( 
171 171
                 'type' => 'number',
172
-                'name' => __( 'Number', 'invoicing' ),
172
+                'name' => __('Number', 'invoicing'),
173 173
                 'defaults' => array(
174 174
                     'placeholder'  => '',
175 175
                     'value'        => '',
176
-                    'label'        => __( 'Number', 'invoicing' ),
176
+                    'label'        => __('Number', 'invoicing'),
177 177
                     'description'  => '',
178 178
                     'required'     => false,
179 179
                 )
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
 
182 182
             array( 
183 183
                 'type' => 'website',
184
-                'name' => __( 'Website', 'invoicing' ),
184
+                'name' => __('Website', 'invoicing'),
185 185
                 'defaults' => array(
186 186
                     'placeholder'  => 'http://example.com',
187 187
                     'value'        => '',
188
-                    'label'        => __( 'Website', 'invoicing' ),
188
+                    'label'        => __('Website', 'invoicing'),
189 189
                     'description'  => '',
190 190
                     'required'     => false,
191 191
                 )
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 
194 194
             array( 
195 195
                 'type' => 'email',
196
-                'name' => __( 'Email', 'invoicing' ),
196
+                'name' => __('Email', 'invoicing'),
197 197
                 'defaults'  => array(
198 198
                     'placeholder'  => '[email protected]',
199 199
                     'value'        => '',
200
-                    'label'        => __( 'Email Address', 'invoicing' ),
200
+                    'label'        => __('Email Address', 'invoicing'),
201 201
                     'description'  => '',
202 202
                     'required'     => false,
203 203
                 )
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 
206 206
             array( 
207 207
                 'type' => 'address',
208
-                'name' => __( 'Address', 'invoicing' ),
208
+                'name' => __('Address', 'invoicing'),
209 209
                 'defaults'  => array(
210 210
 
211 211
                     'fields' => array(
212 212
                         array(
213 213
                             'placeholder'  => 'Jon',
214 214
                             'value'        => '',
215
-                            'label'        => __( 'First Name', 'invoicing' ),
215
+                            'label'        => __('First Name', 'invoicing'),
216 216
                             'description'  => '',
217 217
                             'required'     => false,
218 218
                             'visible'      => true,
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                         array(
223 223
                             'placeholder'  => 'Snow',
224 224
                             'value'        => '',
225
-                            'label'        => __( 'Last Name', 'invoicing' ),
225
+                            'label'        => __('Last Name', 'invoicing'),
226 226
                             'description'  => '',
227 227
                             'required'     => false,
228 228
                             'visible'      => true,
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
                         array(
233 233
                             'placeholder'  => '',
234 234
                             'value'        => '',
235
-                            'label'        => __( 'Address', 'invoicing' ),
235
+                            'label'        => __('Address', 'invoicing'),
236 236
                             'description'  => '',
237 237
                             'required'     => false,
238 238
                             'visible'      => true,
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
                         array(
243 243
                             'placeholder'  => '',
244 244
                             'value'        => '',
245
-                            'label'        => __( 'City', 'invoicing' ),
245
+                            'label'        => __('City', 'invoicing'),
246 246
                             'description'  => '',
247 247
                             'required'     => false,
248 248
                             'visible'      => true,
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
                         ),
251 251
 
252 252
                         array(
253
-                            'placeholder'  => __( 'Select your country' ),
253
+                            'placeholder'  => __('Select your country'),
254 254
                             'value'        => '',
255
-                            'label'        => __( 'Country', 'invoicing' ),
255
+                            'label'        => __('Country', 'invoicing'),
256 256
                             'description'  => '',
257 257
                             'required'     => false,
258 258
                             'visible'      => true,
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
                         ),
261 261
 
262 262
                         array(
263
-                            'placeholder'  => __( 'Choose a state', 'invoicing' ),
263
+                            'placeholder'  => __('Choose a state', 'invoicing'),
264 264
                             'value'        => '',
265
-                            'label'        => __( 'State / Province', 'invoicing' ),
265
+                            'label'        => __('State / Province', 'invoicing'),
266 266
                             'description'  => '',
267 267
                             'required'     => false,
268 268
                             'visible'      => true,
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                         array(
273 273
                             'placeholder'  => '',
274 274
                             'value'        => '',
275
-                            'label'        => __( 'ZIP / Postcode', 'invoicing' ),
275
+                            'label'        => __('ZIP / Postcode', 'invoicing'),
276 276
                             'description'  => '',
277 277
                             'required'     => false,
278 278
                             'visible'      => true,
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                         array(
283 283
                             'placeholder'  => '',
284 284
                             'value'        => '',
285
-                            'label'        => __( 'Phone', 'invoicing' ),
285
+                            'label'        => __('Phone', 'invoicing'),
286 286
                             'description'  => '',
287 287
                             'required'     => false,
288 288
                             'visible'      => true,
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
                         array(
293 293
                             'placeholder'  => '',
294 294
                             'value'        => '',
295
-                            'label'        => __( 'Company', 'invoicing' ),
295
+                            'label'        => __('Company', 'invoicing'),
296 296
                             'description'  => '',
297 297
                             'required'     => false,
298 298
                             'visible'      => false,
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                         array(
303 303
                             'placeholder'  => '',
304 304
                             'value'        => '',
305
-                            'label'        => __( 'VAT Number', 'invoicing' ),
305
+                            'label'        => __('VAT Number', 'invoicing'),
306 306
                             'description'  => '',
307 307
                             'required'     => false,
308 308
                             'visible'      => false,
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
 
315 315
             array( 
316 316
                 'type' => 'billing_email',
317
-                'name' => __( 'Billing Email', 'invoicing' ),
317
+                'name' => __('Billing Email', 'invoicing'),
318 318
                 'defaults'  => array(
319 319
                     'placeholder'  => '[email protected]',
320 320
                     'value'        => '',
321
-                    'label'        => __( 'Billing Email', 'invoicing' ),
321
+                    'label'        => __('Billing Email', 'invoicing'),
322 322
                     'description'  => '',
323 323
                     'premade'      => true,
324 324
                 )
@@ -326,18 +326,18 @@  discard block
 block discarded – undo
326 326
 
327 327
             array( 
328 328
                 'type' => 'discount',
329
-                'name' => __( 'Discount Input', 'invoicing' ),
329
+                'name' => __('Discount Input', 'invoicing'),
330 330
                 'defaults'  => array(
331 331
                     'value'        => '',
332
-                    'input_label'  => __( 'Coupon Code', 'invoicing' ),
333
-                    'button_label' => __( 'Apply Coupon', 'invoicing' ),
334
-                    'description'  => __( 'Have a discount code? Enter it above.', 'invoicing' ),
332
+                    'input_label'  => __('Coupon Code', 'invoicing'),
333
+                    'button_label' => __('Apply Coupon', 'invoicing'),
334
+                    'description'  => __('Have a discount code? Enter it above.', 'invoicing'),
335 335
                 )
336 336
             ),
337 337
 
338 338
             array( 
339 339
                 'type' => 'items',
340
-                'name' => __( 'Items', 'invoicing' ),
340
+                'name' => __('Items', 'invoicing'),
341 341
                 'defaults'  => array(
342 342
                     'value'        => '',
343 343
                     'items_type'   => 'total',
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
 
349 349
             array(
350 350
                 'type' => 'terms',
351
-                'name' => __( 'Terms', 'invoicing' ),
351
+                'name' => __('Terms', 'invoicing'),
352 352
                 'defaults'         => array(
353 353
                     'value'        => '',
354
-                    'text'         => __( 'I\'ve read and accept the <a href="" target="_blank">terms &amp; conditions</a>', 'invoicing' ),
354
+                    'text'         => __('I\'ve read and accept the <a href="" target="_blank">terms &amp; conditions</a>', 'invoicing'),
355 355
                     'description'  => '',
356 356
                     'required'     => true,
357 357
                 )
@@ -359,34 +359,34 @@  discard block
 block discarded – undo
359 359
 
360 360
             array(
361 361
                 'type' => 'privacy',
362
-                'name' => __( 'Privacy', 'invoicing' ),
362
+                'name' => __('Privacy', 'invoicing'),
363 363
                 'defaults'         => array(
364 364
                     'value'        => '',
365
-                    'text'         => __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our privacy policy.', 'invoicing' ),
365
+                    'text'         => __('Your personal data will be used to process your invoice, payment and for other purposes described in our privacy policy.', 'invoicing'),
366 366
                 )
367 367
             ),
368 368
 
369 369
             array( 
370 370
                 'type'       => 'pay_button',
371
-                'name'       => __( 'Payment Button', 'invoicing' ),
371
+                'name'       => __('Payment Button', 'invoicing'),
372 372
                 'defaults'   => array(
373 373
                     'value'        => '',
374 374
                     'class'        => 'btn-primary',
375
-                    'label'        => __( 'Pay Now »', 'invoicing' ),
376
-                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
375
+                    'label'        => __('Pay Now »', 'invoicing'),
376
+                    'description'  => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'),
377 377
                     'premade'      => true,
378 378
                 )
379 379
             )
380 380
         );
381 381
 
382
-        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
382
+        $this->elements = apply_filters('wpinv_filter_core_payment_form_elements', $this->elements);
383 383
         return $this->elements;
384 384
     }
385 385
 
386 386
     /**
387 387
      * Returns the restrict markup.
388 388
      */
389
-    public function get_restrict_markup( $field, $field_type ) {
389
+    public function get_restrict_markup($field, $field_type) {
390 390
         $restrict = "$field.type=='$field_type'";
391 391
         return "v-if=\"$restrict\"";
392 392
     }
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
     /**
395 395
      * Renders the title element template.
396 396
      */
397
-    public function render_heading_template( $field ) {
398
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
397
+    public function render_heading_template($field) {
398
+        $restrict = $this->get_restrict_markup($field, 'heading');
399 399
         echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
400 400
     }
401 401
 
402 402
     /**
403 403
      * Renders the title element on the frontend.
404 404
      */
405
-    public function frontend_render_heading_template( $field ) {
405
+    public function frontend_render_heading_template($field) {
406 406
         $tag = $field['level'];
407 407
         echo "<$tag>{$field['text']}</$tag>";
408 408
     }
@@ -410,10 +410,10 @@  discard block
 block discarded – undo
410 410
     /**
411 411
      * Renders the edit title element template.
412 412
      */
413
-    public function edit_heading_template( $field ) {
414
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
415
-        $label    = __( 'Heading', 'invoicing' );
416
-        $label2   = __( 'Select Heading Level', 'invoicing' );
413
+    public function edit_heading_template($field) {
414
+        $restrict = $this->get_restrict_markup($field, 'heading');
415
+        $label    = __('Heading', 'invoicing');
416
+        $label2   = __('Select Heading Level', 'invoicing');
417 417
         $id       = $field . '.id + "_edit"';
418 418
         $id2      = $field . '.id + "_edit2"';
419 419
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
     /**
446 446
      * Renders a paragraph element template.
447 447
      */
448
-    public function render_paragraph_template( $field ) {
449
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
448
+    public function render_paragraph_template($field) {
449
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
450 450
         $label    = "$field.text";
451 451
         echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
452 452
     }
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
     /**
455 455
      * Renders a privacy element template.
456 456
      */
457
-    public function render_privacy_template( $field ) {
458
-        $restrict = $this->get_restrict_markup( $field, 'privacy' );
457
+    public function render_privacy_template($field) {
458
+        $restrict = $this->get_restrict_markup($field, 'privacy');
459 459
         $label    = "$field.text";
460 460
         echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
461 461
     }
@@ -463,23 +463,23 @@  discard block
 block discarded – undo
463 463
     /**
464 464
      * Renders the paragraph element on the frontend.
465 465
      */
466
-    public function frontend_render_paragraph_template( $field ) {
466
+    public function frontend_render_paragraph_template($field) {
467 467
         echo "<p>{$field['text']}</p>";
468 468
     }
469 469
 
470 470
     /**
471 471
      * Renders the privacy element on the frontend.
472 472
      */
473
-    public function frontend_render_privacy_template( $field ) {
473
+    public function frontend_render_privacy_template($field) {
474 474
         echo "<p>{$field['text']}</p>";
475 475
     }
476 476
 
477 477
     /**
478 478
      * Renders the edit paragraph element template.
479 479
      */
480
-    public function edit_paragraph_template( $field ) {
481
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
482
-        $label    = __( 'Enter your text', 'invoicing' );
480
+    public function edit_paragraph_template($field) {
481
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
482
+        $label    = __('Enter your text', 'invoicing');
483 483
         $id       = $field . '.id + "_edit"';
484 484
         echo "
485 485
             <div $restrict>
@@ -495,9 +495,9 @@  discard block
 block discarded – undo
495 495
     /**
496 496
      * Renders the edit privacy element template.
497 497
      */
498
-    public function edit_privacy_template( $field ) {
499
-        $restrict = $this->get_restrict_markup( $field, 'privacy' );
500
-        $label    = __( 'Privacy Text', 'invoicing' );
498
+    public function edit_privacy_template($field) {
499
+        $restrict = $this->get_restrict_markup($field, 'privacy');
500
+        $label    = __('Privacy Text', 'invoicing');
501 501
         $id       = $field . '.id + "_edit"';
502 502
         echo "
503 503
             <div $restrict>
@@ -513,8 +513,8 @@  discard block
 block discarded – undo
513 513
     /**
514 514
      * Renders the text element template.
515 515
      */
516
-    public function render_text_template( $field ) {
517
-        $restrict = $this->get_restrict_markup( $field, 'text' );
516
+    public function render_text_template($field) {
517
+        $restrict = $this->get_restrict_markup($field, 'text');
518 518
         $label    = "$field.label";
519 519
         echo "
520 520
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -529,23 +529,23 @@  discard block
 block discarded – undo
529 529
     /**
530 530
      * Renders the text element on the frontend.
531 531
      */
532
-    public function frontend_render_text_template( $field ) {
532
+    public function frontend_render_text_template($field) {
533 533
         
534 534
         echo "<div class='form-group'>";
535 535
 
536 536
         echo aui()->input(
537 537
             array(
538
-                'name'       => esc_attr( $field['id'] ),
539
-                'id'         => esc_attr( $field['id'] ),
540
-                'placeholder'=> esc_attr( $field['placeholder'] ),
538
+                'name'       => esc_attr($field['id']),
539
+                'id'         => esc_attr($field['id']),
540
+                'placeholder'=> esc_attr($field['placeholder']),
541 541
                 'required'   => (bool) $field['required'],
542
-                'label'      => wp_kses_post( $field['label'] ),
542
+                'label'      => wp_kses_post($field['label']),
543 543
                 'no_wrap'    => true,
544 544
             )
545 545
         );
546 546
 
547
-        if ( ! empty( $field['description'] ) ) {
548
-            $description = wp_kses_post( $field['description'] );
547
+        if (!empty($field['description'])) {
548
+            $description = wp_kses_post($field['description']);
549 549
             echo "<small class='form-text text-muted'>$description</small>";
550 550
         }
551 551
 
@@ -556,16 +556,16 @@  discard block
 block discarded – undo
556 556
     /**
557 557
      * Renders the edit text element template.
558 558
      */
559
-    public function edit_text_template( $field ) {
560
-        $restrict = $this->get_restrict_markup( $field, 'text' );
561
-        $label    = __( 'Field Label', 'invoicing' );
559
+    public function edit_text_template($field) {
560
+        $restrict = $this->get_restrict_markup($field, 'text');
561
+        $label    = __('Field Label', 'invoicing');
562 562
         $id       = $field . '.id + "_edit"';
563
-        $label2   = __( 'Placeholder text', 'invoicing' );
563
+        $label2   = __('Placeholder text', 'invoicing');
564 564
         $id2      = $field . '.id + "_edit2"';
565
-        $label3   = __( 'Help text', 'invoicing' );
566
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
565
+        $label3   = __('Help text', 'invoicing');
566
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
567 567
         $id3      = $field . '.id + "_edit3"';
568
-        $label5   = __( 'Is this field required?', 'invoicing' );
568
+        $label5   = __('Is this field required?', 'invoicing');
569 569
         $id4      = $field . '.id + "_edit4"';
570 570
         echo "
571 571
             <div $restrict>
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
     /**
594 594
      * Renders the textarea element template.
595 595
      */
596
-    public function render_textarea_template( $field ) {
597
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
596
+    public function render_textarea_template($field) {
597
+        $restrict = $this->get_restrict_markup($field, 'textarea');
598 598
         $label    = "$field.label";
599 599
         echo "
600 600
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -609,24 +609,24 @@  discard block
 block discarded – undo
609 609
     /**
610 610
      * Renders the textarea element on the frontend.
611 611
      */
612
-    public function frontend_render_textarea_template( $field ) {
612
+    public function frontend_render_textarea_template($field) {
613 613
         
614 614
         echo "<div class='form-group'>";
615 615
 
616 616
         echo aui()->textarea(
617 617
             array(
618
-                'name'       => esc_attr( $field['id'] ),
619
-                'id'         => esc_attr( $field['id'] ),
620
-                'placeholder'=> esc_attr( $field['placeholder'] ),
618
+                'name'       => esc_attr($field['id']),
619
+                'id'         => esc_attr($field['id']),
620
+                'placeholder'=> esc_attr($field['placeholder']),
621 621
                 'required'   => (bool) $field['required'],
622
-                'label'      => wp_kses_post( $field['label'] ),
622
+                'label'      => wp_kses_post($field['label']),
623 623
                 'no_wrap'    => true,
624 624
                 'rows'       => 3,
625 625
             )
626 626
         );
627 627
 
628
-        if ( ! empty( $field['description'] ) ) {
629
-            $description = wp_kses_post( $field['description'] );
628
+        if (!empty($field['description'])) {
629
+            $description = wp_kses_post($field['description']);
630 630
             echo "<small class='form-text text-muted'>$description</small>";
631 631
         }
632 632
 
@@ -637,16 +637,16 @@  discard block
 block discarded – undo
637 637
     /**
638 638
      * Renders the edit textarea element template.
639 639
      */
640
-    public function edit_textarea_template( $field ) {
641
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
642
-        $label    = __( 'Field Label', 'invoicing' );
640
+    public function edit_textarea_template($field) {
641
+        $restrict = $this->get_restrict_markup($field, 'textarea');
642
+        $label    = __('Field Label', 'invoicing');
643 643
         $id       = $field . '.id + "_edit"';
644
-        $label2   = __( 'Placeholder text', 'invoicing' );
644
+        $label2   = __('Placeholder text', 'invoicing');
645 645
         $id2      = $field . '.id + "_edit2"';
646
-        $label3   = __( 'Help text', 'invoicing' );
647
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
646
+        $label3   = __('Help text', 'invoicing');
647
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
648 648
         $id3      = $field . '.id + "_edit3"';
649
-        $label5   = __( 'Is this field required?', 'invoicing' );
649
+        $label5   = __('Is this field required?', 'invoicing');
650 650
         $id4      = $field . '.id + "_edit4"';
651 651
         echo "
652 652
             <div $restrict>
@@ -674,8 +674,8 @@  discard block
 block discarded – undo
674 674
     /**
675 675
      * Renders the select element template.
676 676
      */
677
-    public function render_select_template( $field ) {
678
-        $restrict    = $this->get_restrict_markup( $field, 'select' );
677
+    public function render_select_template($field) {
678
+        $restrict    = $this->get_restrict_markup($field, 'select');
679 679
         $label       = "$field.label";
680 680
         $placeholder = "$field.placeholder";
681 681
         $id          = $field . '.id';
@@ -695,24 +695,24 @@  discard block
 block discarded – undo
695 695
     /**
696 696
      * Renders the select element on the frontend.
697 697
      */
698
-    public function frontend_render_select_template( $field ) {
698
+    public function frontend_render_select_template($field) {
699 699
         
700 700
         echo "<div class='form-group'>";
701 701
 
702 702
         echo aui()->select(
703 703
             array(
704
-                'name'       => esc_attr( $field['id'] ),
705
-                'id'         => esc_attr( $field['id'] ),
706
-                'placeholder'=> esc_attr( $field['placeholder'] ),
704
+                'name'       => esc_attr($field['id']),
705
+                'id'         => esc_attr($field['id']),
706
+                'placeholder'=> esc_attr($field['placeholder']),
707 707
                 'required'   => (bool) $field['required'],
708
-                'label'      => wp_kses_post( $field['label'] ),
708
+                'label'      => wp_kses_post($field['label']),
709 709
                 'no_wrap'    => true,
710
-                'options'    => array_combine( $field['options'], $field['options'] ),
710
+                'options'    => array_combine($field['options'], $field['options']),
711 711
             )
712 712
         );
713 713
 
714
-        if ( ! empty( $field['description'] ) ) {
715
-            $description = wp_kses_post( $field['description'] );
714
+        if (!empty($field['description'])) {
715
+            $description = wp_kses_post($field['description']);
716 716
             echo "<small class='form-text text-muted'>$description</small>";
717 717
         }
718 718
 
@@ -723,18 +723,18 @@  discard block
 block discarded – undo
723 723
     /**
724 724
      * Renders the edit select element template.
725 725
      */
726
-    public function edit_select_template( $field ) {
727
-        $restrict = $this->get_restrict_markup( $field, 'select' );
728
-        $label    = __( 'Field Label', 'invoicing' );
726
+    public function edit_select_template($field) {
727
+        $restrict = $this->get_restrict_markup($field, 'select');
728
+        $label    = __('Field Label', 'invoicing');
729 729
         $id       = $field . '.id + "_edit"';
730
-        $label2   = __( 'Placeholder text', 'invoicing' );
730
+        $label2   = __('Placeholder text', 'invoicing');
731 731
         $id2      = $field . '.id + "_edit2"';
732
-        $label3   = __( 'Help text', 'invoicing' );
733
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
732
+        $label3   = __('Help text', 'invoicing');
733
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
734 734
         $id3      = $field . '.id + "_edit3"';
735
-        $label5   = __( 'Is this field required?', 'invoicing' );
735
+        $label5   = __('Is this field required?', 'invoicing');
736 736
         $id4      = $field . '.id + "_edit4"';
737
-        $label6   = __( 'Available Options', 'invoicing' );
737
+        $label6   = __('Available Options', 'invoicing');
738 738
         echo "
739 739
             <div $restrict>
740 740
                 <div class='form-group'>
@@ -772,8 +772,8 @@  discard block
 block discarded – undo
772 772
     /**
773 773
      * Renders the checkbox element template.
774 774
      */
775
-    public function render_checkbox_template( $field ) {
776
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
775
+    public function render_checkbox_template($field) {
776
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
777 777
         echo "
778 778
             <div class='form-check' $restrict>
779 779
                 <div class='wpinv-payment-form-field-preview-overlay'></div>
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
     /**
788 788
      * Renders the terms element template.
789 789
      */
790
-    public function render_terms_template( $field ) {
791
-        $restrict = $this->get_restrict_markup( $field, 'terms' );
790
+    public function render_terms_template($field) {
791
+        $restrict = $this->get_restrict_markup($field, 'terms');
792 792
         echo "
793 793
             <div class='form-check' $restrict>
794 794
                 <div class='wpinv-payment-form-field-preview-overlay'></div>
@@ -802,24 +802,24 @@  discard block
 block discarded – undo
802 802
     /**
803 803
      * Renders the checkbox element on the frontend.
804 804
      */
805
-    public function frontend_render_checkbox_template( $field ) {
805
+    public function frontend_render_checkbox_template($field) {
806 806
         
807 807
         echo "<div class='form-group'>";
808 808
 
809 809
         echo aui()->input(
810 810
             array(
811
-                'name'       => esc_attr( $field['id'] ),
812
-                'id'         => esc_attr( $field['id'] ),
811
+                'name'       => esc_attr($field['id']),
812
+                'id'         => esc_attr($field['id']),
813 813
                 'required'   => (bool) $field['required'],
814
-                'label'      => wp_kses_post( $field['label'] ),
814
+                'label'      => wp_kses_post($field['label']),
815 815
                 'no_wrap'    => true,
816
-                'value'      => esc_attr__( 'Yes', 'invoicing' ),
816
+                'value'      => esc_attr__('Yes', 'invoicing'),
817 817
                 'type'       => 'checkbox',
818 818
             )
819 819
         );
820 820
 
821
-        if ( ! empty( $field['description'] ) ) {
822
-            $description = wp_kses_post( $field['description'] );
821
+        if (!empty($field['description'])) {
822
+            $description = wp_kses_post($field['description']);
823 823
             echo "<small class='form-text text-muted'>$description</small>";
824 824
         }
825 825
 
@@ -830,24 +830,24 @@  discard block
 block discarded – undo
830 830
         /**
831 831
      * Renders the terms element on the frontend.
832 832
      */
833
-    public function frontend_render_terms_template( $field ) {
833
+    public function frontend_render_terms_template($field) {
834 834
         
835 835
         echo "<div class='form-group'>";
836 836
 
837 837
         echo aui()->input(
838 838
             array(
839
-                'name'       => esc_attr( $field['id'] ),
840
-                'id'         => esc_attr( $field['id'] ),
839
+                'name'       => esc_attr($field['id']),
840
+                'id'         => esc_attr($field['id']),
841 841
                 'required'   => (bool) $field['required'],
842
-                'label'      => wp_kses_post( $field['text'] ),
842
+                'label'      => wp_kses_post($field['text']),
843 843
                 'no_wrap'    => true,
844
-                'value'      => esc_attr__( 'Yes', 'invoicing' ),
844
+                'value'      => esc_attr__('Yes', 'invoicing'),
845 845
                 'type'       => 'checkbox',
846 846
             )
847 847
         );
848 848
 
849
-        if ( ! empty( $field['description'] ) ) {
850
-            $description = wp_kses_post( $field['description'] );
849
+        if (!empty($field['description'])) {
850
+            $description = wp_kses_post($field['description']);
851 851
             echo "<small class='form-text text-muted'>$description</small>";
852 852
         }
853 853
 
@@ -858,14 +858,14 @@  discard block
 block discarded – undo
858 858
     /**
859 859
      * Renders the edit checkbox element template.
860 860
      */
861
-    public function edit_checkbox_template( $field ) {
862
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
863
-        $label    = __( 'Field Label', 'invoicing' );
861
+    public function edit_checkbox_template($field) {
862
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
863
+        $label    = __('Field Label', 'invoicing');
864 864
         $id       = $field . '.id + "_edit"';
865
-        $label2   = __( 'Help text', 'invoicing' );
866
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
865
+        $label2   = __('Help text', 'invoicing');
866
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
867 867
         $id2      = $field . '.id + "_edit2"';
868
-        $label4   = __( 'Is this field required?', 'invoicing' );
868
+        $label4   = __('Is this field required?', 'invoicing');
869 869
         $id3      = $field . '.id + "_edit3"';
870 870
         echo "
871 871
             <div $restrict>
@@ -889,14 +889,14 @@  discard block
 block discarded – undo
889 889
     /**
890 890
      * Renders the edit terms element template.
891 891
      */
892
-    public function edit_terms_template( $field ) {
893
-        $restrict = $this->get_restrict_markup( $field, 'terms' );
894
-        $label    = __( 'Field Label', 'invoicing' );
892
+    public function edit_terms_template($field) {
893
+        $restrict = $this->get_restrict_markup($field, 'terms');
894
+        $label    = __('Field Label', 'invoicing');
895 895
         $id       = $field . '.id + "_edit"';
896
-        $label2   = __( 'Help text', 'invoicing' );
897
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
896
+        $label2   = __('Help text', 'invoicing');
897
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
898 898
         $id2      = $field . '.id + "_edit2"';
899
-        $label4   = __( 'Is this field required?', 'invoicing' );
899
+        $label4   = __('Is this field required?', 'invoicing');
900 900
         $id3      = $field . '.id + "_edit3"';
901 901
         echo "
902 902
             <div $restrict>
@@ -920,8 +920,8 @@  discard block
 block discarded – undo
920 920
     /**
921 921
      * Renders the radio element template.
922 922
      */
923
-    public function render_radio_template( $field ) {
924
-        $restrict    = $this->get_restrict_markup( $field, 'radio' );
923
+    public function render_radio_template($field) {
924
+        $restrict    = $this->get_restrict_markup($field, 'radio');
925 925
         $label       = "$field.label";
926 926
         $id          = $field . '.id';
927 927
         echo "
@@ -940,20 +940,20 @@  discard block
 block discarded – undo
940 940
     /**
941 941
      * Renders the radio element on the frontend.
942 942
      */
943
-    public function frontend_render_radio_template( $field ) {
943
+    public function frontend_render_radio_template($field) {
944 944
         
945 945
         echo "<div class='form-group'>";
946 946
 
947
-        if ( ! empty( $field['label'] ) ) {
948
-            $label = wp_kses_post( $field['label'] );
947
+        if (!empty($field['label'])) {
948
+            $label = wp_kses_post($field['label']);
949 949
             echo "<legend class='col-form-label'>$label</legend>";
950 950
         }
951 951
 
952
-        foreach( $field['options'] as $index => $option ) {
952
+        foreach ($field['options'] as $index => $option) {
953 953
             $id    = $field['id'] . $index;
954 954
             $name  = $field['id'];
955
-            $value = esc_attr( $option );
956
-            $label = wp_kses_post( $option );
955
+            $value = esc_attr($option);
956
+            $label = wp_kses_post($option);
957 957
 
958 958
             echo "
959 959
                 <div class='form-check'>
@@ -963,8 +963,8 @@  discard block
 block discarded – undo
963 963
             ";
964 964
         }
965 965
 
966
-        if ( ! empty( $field['description'] ) ) {
967
-            $description = wp_kses_post( $field['description'] );
966
+        if (!empty($field['description'])) {
967
+            $description = wp_kses_post($field['description']);
968 968
             echo "<small class='form-text text-muted'>$description</small>";
969 969
         }
970 970
 
@@ -975,16 +975,16 @@  discard block
 block discarded – undo
975 975
     /**
976 976
      * Renders the edit radio element template.
977 977
      */
978
-    public function edit_radio_template( $field ) {
979
-        $restrict = $this->get_restrict_markup( $field, 'radio' );
980
-        $label    = __( 'Field Label', 'invoicing' );
978
+    public function edit_radio_template($field) {
979
+        $restrict = $this->get_restrict_markup($field, 'radio');
980
+        $label    = __('Field Label', 'invoicing');
981 981
         $id       = $field . '.id + "_edit"';
982
-        $label2   = __( 'Help text', 'invoicing' );
983
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
982
+        $label2   = __('Help text', 'invoicing');
983
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
984 984
         $id2      = $field . '.id + "_edit3"';
985
-        $label4   = __( 'Is this field required?', 'invoicing' );
985
+        $label4   = __('Is this field required?', 'invoicing');
986 986
         $id3      = $field . '.id + "_edit4"';
987
-        $label5   = __( 'Available Options', 'invoicing' );
987
+        $label5   = __('Available Options', 'invoicing');
988 988
         echo "
989 989
             <div $restrict>
990 990
                 <div class='form-group'>
@@ -1018,8 +1018,8 @@  discard block
 block discarded – undo
1018 1018
     /**
1019 1019
      * Renders the address element template.
1020 1020
      */
1021
-    public function render_address_template( $field ) {
1022
-        $restrict    = $this->get_restrict_markup( $field, 'address' );
1021
+    public function render_address_template($field) {
1022
+        $restrict = $this->get_restrict_markup($field, 'address');
1023 1023
 
1024 1024
         echo "
1025 1025
             <div class='wpinv-address-wrapper' $restrict>
@@ -1041,75 +1041,75 @@  discard block
 block discarded – undo
1041 1041
     /**
1042 1042
      * Renders the address element on the frontend.
1043 1043
      */
1044
-    public function frontend_render_address_template( $field ) {
1044
+    public function frontend_render_address_template($field) {
1045 1045
         
1046 1046
         echo "<div class='wpinv-address-fields'>";
1047 1047
 
1048 1048
         $country = '';
1049
-        if ( is_user_logged_in() ) {
1050
-            $user  = wp_get_current_user();
1051
-            $country = sanitize_text_field( get_user_meta( $user->ID, '_wpinv_country', true ) );
1049
+        if (is_user_logged_in()) {
1050
+            $user = wp_get_current_user();
1051
+            $country = sanitize_text_field(get_user_meta($user->ID, '_wpinv_country', true));
1052 1052
         }
1053 1053
 
1054
-        if ( empty( $country ) ) {
1054
+        if (empty($country)) {
1055 1055
             $country = wpinv_get_default_country();
1056 1056
         }
1057 1057
 
1058
-        foreach( $field['fields'] as $address_field ) {
1058
+        foreach ($field['fields'] as $address_field) {
1059 1059
 
1060
-            if ( empty( $address_field['visible'] ) ) {
1060
+            if (empty($address_field['visible'])) {
1061 1061
                 continue;
1062 1062
             }
1063 1063
 
1064
-            $class = esc_attr( $address_field['name'] );
1064
+            $class = esc_attr($address_field['name']);
1065 1065
             echo "<div class='form-group $class'>";
1066 1066
 
1067 1067
             $label = $address_field['label'];
1068 1068
 
1069
-            if ( ! empty( $address_field['required'] ) ) {
1069
+            if (!empty($address_field['required'])) {
1070 1070
                 $label .= "<span class='text-danger'> *</span>";
1071 1071
             }
1072 1072
 
1073 1073
             // Default value.
1074 1074
             $value     = '';
1075
-            if ( is_user_logged_in() ) {
1075
+            if (is_user_logged_in()) {
1076 1076
                 $user  = wp_get_current_user();
1077
-                $value = sanitize_text_field( get_user_meta( $user->ID, '_' . $address_field['name'], true ) );
1077
+                $value = sanitize_text_field(get_user_meta($user->ID, '_' . $address_field['name'], true));
1078 1078
             }
1079 1079
 
1080
-            if ( 'wpinv_country' == $address_field['name'] ) {
1080
+            if ('wpinv_country' == $address_field['name']) {
1081 1081
 
1082
-                echo aui()->select( array(
1082
+                echo aui()->select(array(
1083 1083
                     'options'          => wpinv_get_country_list(),
1084
-                    'name'             => esc_attr( $address_field['name'] ),
1085
-                    'id'               => esc_attr( $address_field['name'] ),
1084
+                    'name'             => esc_attr($address_field['name']),
1085
+                    'id'               => esc_attr($address_field['name']),
1086 1086
                     'value'            => $country,
1087
-                    'placeholder'      => esc_attr( $address_field['placeholder'] ),
1087
+                    'placeholder'      => esc_attr($address_field['placeholder']),
1088 1088
                     'required'         => (bool) $address_field['required'],
1089 1089
                     'no_wrap'          => true,
1090
-                    'label'            => wp_kses_post( $label ),
1090
+                    'label'            => wp_kses_post($label),
1091 1091
                     'select2'          => false,
1092 1092
                 ));
1093 1093
     
1094
-            } else if ( 'wpinv_state' == $address_field['name'] ) {
1094
+            } else if ('wpinv_state' == $address_field['name']) {
1095 1095
 
1096
-                $states = wpinv_get_country_states( $country );
1096
+                $states = wpinv_get_country_states($country);
1097 1097
 
1098
-                if ( empty( $value ) ) {
1098
+                if (empty($value)) {
1099 1099
                     $value = wpinv_get_default_state();
1100 1100
                 }
1101 1101
 
1102
-                if ( ! empty( $states ) ) {
1102
+                if (!empty($states)) {
1103 1103
 
1104
-                    echo aui()->select( array(
1104
+                    echo aui()->select(array(
1105 1105
                         'options'          => $states,
1106
-                        'name'             => esc_attr( $address_field['name'] ),
1107
-                        'id'               => esc_attr( $address_field['name'] ),
1106
+                        'name'             => esc_attr($address_field['name']),
1107
+                        'id'               => esc_attr($address_field['name']),
1108 1108
                         'value'            => $value,
1109
-                        'placeholder'      => esc_attr( $address_field['placeholder'] ),
1109
+                        'placeholder'      => esc_attr($address_field['placeholder']),
1110 1110
                         'required'         => (bool) $address_field['required'],
1111 1111
                         'no_wrap'          => true,
1112
-                        'label'            => wp_kses_post( $label ),
1112
+                        'label'            => wp_kses_post($label),
1113 1113
                         'select2'          => false,
1114 1114
                     ));
1115 1115
 
@@ -1117,10 +1117,10 @@  discard block
 block discarded – undo
1117 1117
 
1118 1118
                     echo aui()->input(
1119 1119
                         array(
1120
-                            'name'       => esc_attr( $address_field['name'] ),
1121
-                            'id'         => esc_attr( $address_field['name'] ),
1120
+                            'name'       => esc_attr($address_field['name']),
1121
+                            'id'         => esc_attr($address_field['name']),
1122 1122
                             'required'   => (bool) $address_field['required'],
1123
-                            'label'      => wp_kses_post( $label ),
1123
+                            'label'      => wp_kses_post($label),
1124 1124
                             'no_wrap'    => true,
1125 1125
                             'type'       => 'text',
1126 1126
                             'value'      => $value,
@@ -1133,12 +1133,12 @@  discard block
 block discarded – undo
1133 1133
 
1134 1134
                 echo aui()->input(
1135 1135
                     array(
1136
-                        'name'       => esc_attr( $address_field['name'] ),
1137
-                        'id'         => esc_attr( $address_field['name'] ),
1136
+                        'name'       => esc_attr($address_field['name']),
1137
+                        'id'         => esc_attr($address_field['name']),
1138 1138
                         'required'   => (bool) $address_field['required'],
1139
-                        'label'      => wp_kses_post( $label ),
1139
+                        'label'      => wp_kses_post($label),
1140 1140
                         'no_wrap'    => true,
1141
-                        'placeholder' => esc_attr( $address_field['placeholder'] ),
1141
+                        'placeholder' => esc_attr($address_field['placeholder']),
1142 1142
                         'type'       => 'text',
1143 1143
                         'value'      => $value,
1144 1144
                     )
@@ -1147,8 +1147,8 @@  discard block
 block discarded – undo
1147 1147
             }
1148 1148
             
1149 1149
 
1150
-            if ( ! empty( $address_field['description'] ) ) {
1151
-                $description = wp_kses_post( $address_field['description'] );
1150
+            if (!empty($address_field['description'])) {
1151
+                $description = wp_kses_post($address_field['description']);
1152 1152
                 echo "<small class='form-text text-muted'>$description</small>";
1153 1153
             }
1154 1154
     
@@ -1163,13 +1163,13 @@  discard block
 block discarded – undo
1163 1163
     /**
1164 1164
      * Renders the edit address element template.
1165 1165
      */
1166
-    public function edit_address_template( $field ) {
1167
-        $restrict  = $this->get_restrict_markup( $field, 'address' );
1168
-        $label     = __( 'Field Label', 'invoicing' );
1169
-        $label2    = __( 'Placeholder', 'invoicing' );
1170
-        $label3    = __( 'Description', 'invoicing' );
1171
-        $label4    = __( 'Is required', 'invoicing' );
1172
-        $label5    = __( 'Is visible', 'invoicing' );
1166
+    public function edit_address_template($field) {
1167
+        $restrict  = $this->get_restrict_markup($field, 'address');
1168
+        $label     = __('Field Label', 'invoicing');
1169
+        $label2    = __('Placeholder', 'invoicing');
1170
+        $label3    = __('Description', 'invoicing');
1171
+        $label4    = __('Is required', 'invoicing');
1172
+        $label5    = __('Is visible', 'invoicing');
1173 1173
         $id        = $field . '.id + "_edit_label"';
1174 1174
         $id2       = $field . '.id + "_edit_placeholder"';
1175 1175
         $id3       = $field . '.id + "_edit_description"';
@@ -1237,8 +1237,8 @@  discard block
 block discarded – undo
1237 1237
     /**
1238 1238
      * Renders the email element template.
1239 1239
      */
1240
-    public function render_email_template( $field ) {
1241
-        $restrict = $this->get_restrict_markup( $field, 'email' );
1240
+    public function render_email_template($field) {
1241
+        $restrict = $this->get_restrict_markup($field, 'email');
1242 1242
         $label    = "$field.label";
1243 1243
         echo "
1244 1244
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1253,8 +1253,8 @@  discard block
 block discarded – undo
1253 1253
     /**
1254 1254
      * Renders the billing_email element template.
1255 1255
      */
1256
-    public function render_billing_email_template( $field ) {
1257
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1256
+    public function render_billing_email_template($field) {
1257
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
1258 1258
         $label    = "$field.label";
1259 1259
         echo "
1260 1260
             <div $restrict>
@@ -1268,24 +1268,24 @@  discard block
 block discarded – undo
1268 1268
     /**
1269 1269
      * Renders the email element on the frontend.
1270 1270
      */
1271
-    public function frontend_render_email_template( $field ) {
1271
+    public function frontend_render_email_template($field) {
1272 1272
         
1273 1273
         echo "<div class='form-group'>";
1274 1274
 
1275 1275
         echo aui()->input(
1276 1276
             array(
1277
-                'name'       => esc_attr( $field['id'] ),
1278
-                'id'         => esc_attr( $field['id'] ),
1277
+                'name'       => esc_attr($field['id']),
1278
+                'id'         => esc_attr($field['id']),
1279 1279
                 'required'   => (bool) $field['required'],
1280
-                'label'      => wp_kses_post( $field['label'] ),
1280
+                'label'      => wp_kses_post($field['label']),
1281 1281
                 'no_wrap'    => true,
1282
-                'placeholder' => esc_attr( $field['placeholder'] ),
1282
+                'placeholder' => esc_attr($field['placeholder']),
1283 1283
                 'type'       => 'email',
1284 1284
             )
1285 1285
         );
1286 1286
 
1287
-        if ( ! empty( $field['description'] ) ) {
1288
-            $description = wp_kses_post( $field['description'] );
1287
+        if (!empty($field['description'])) {
1288
+            $description = wp_kses_post($field['description']);
1289 1289
             echo "<small class='form-text text-muted'>$description</small>";
1290 1290
         }
1291 1291
 
@@ -1296,30 +1296,30 @@  discard block
 block discarded – undo
1296 1296
     /**
1297 1297
      * Renders the billing email element on the frontend.
1298 1298
      */
1299
-    public function frontend_render_billing_email_template( $field ) {
1299
+    public function frontend_render_billing_email_template($field) {
1300 1300
         
1301 1301
         echo "<div class='form-group'>";
1302 1302
         $value = '';
1303 1303
 
1304
-        if ( is_user_logged_in() ) {
1304
+        if (is_user_logged_in()) {
1305 1305
             $user  = wp_get_current_user();
1306
-            $value = sanitize_email( $user->user_email );
1306
+            $value = sanitize_email($user->user_email);
1307 1307
         }
1308 1308
         echo aui()->input(
1309 1309
             array(
1310 1310
                 'name'       => 'billing_email',
1311 1311
                 'value'      => $value,
1312
-                'id'         => esc_attr( $field['id'] ),
1312
+                'id'         => esc_attr($field['id']),
1313 1313
                 'required'   => true,
1314
-                'label'      => wp_kses_post( $field['label'] ),
1314
+                'label'      => wp_kses_post($field['label']),
1315 1315
                 'no_wrap'    => true,
1316
-                'placeholder' => esc_attr( $field['placeholder'] ),
1316
+                'placeholder' => esc_attr($field['placeholder']),
1317 1317
                 'type'       => 'email',
1318 1318
             )
1319 1319
         );
1320 1320
 
1321
-        if ( ! empty( $field['description'] ) ) {
1322
-            $description = wp_kses_post( $field['description'] );
1321
+        if (!empty($field['description'])) {
1322
+            $description = wp_kses_post($field['description']);
1323 1323
             echo "<small class='form-text text-muted'>$description</small>";
1324 1324
         }
1325 1325
 
@@ -1330,16 +1330,16 @@  discard block
 block discarded – undo
1330 1330
     /**
1331 1331
      * Renders the edit email element template.
1332 1332
      */
1333
-    public function edit_email_template( $field ) {
1334
-        $restrict = $this->get_restrict_markup( $field, 'email' );
1335
-        $label    = __( 'Field Label', 'invoicing' );
1333
+    public function edit_email_template($field) {
1334
+        $restrict = $this->get_restrict_markup($field, 'email');
1335
+        $label    = __('Field Label', 'invoicing');
1336 1336
         $id       = $field . '.id + "_edit"';
1337
-        $label2   = __( 'Placeholder text', 'invoicing' );
1337
+        $label2   = __('Placeholder text', 'invoicing');
1338 1338
         $id2      = $field . '.id + "_edit2"';
1339
-        $label3   = __( 'Help text', 'invoicing' );
1340
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1339
+        $label3   = __('Help text', 'invoicing');
1340
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1341 1341
         $id3      = $field . '.id + "_edit3"';
1342
-        $label5   = __( 'Is this field required?', 'invoicing' );
1342
+        $label5   = __('Is this field required?', 'invoicing');
1343 1343
         $id4      = $field . '.id + "_edit4"';
1344 1344
         echo "
1345 1345
             <div $restrict>
@@ -1367,16 +1367,16 @@  discard block
 block discarded – undo
1367 1367
     /**
1368 1368
      * Renders the edit billing_email element template.
1369 1369
      */
1370
-    public function edit_billing_email_template( $field ) {
1371
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1372
-        $label    = __( 'Field Label', 'invoicing' );
1370
+    public function edit_billing_email_template($field) {
1371
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
1372
+        $label    = __('Field Label', 'invoicing');
1373 1373
         $id       = $field . '.id + "_edit"';
1374
-        $label2   = __( 'Placeholder text', 'invoicing' );
1374
+        $label2   = __('Placeholder text', 'invoicing');
1375 1375
         $id2      = $field . '.id + "_edit2"';
1376
-        $label3   = __( 'Help text', 'invoicing' );
1377
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1376
+        $label3   = __('Help text', 'invoicing');
1377
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1378 1378
         $id3      = $field . '.id + "_edit3"';
1379
-        $label5   = __( 'Is this field required?', 'invoicing' );
1379
+        $label5   = __('Is this field required?', 'invoicing');
1380 1380
         $id4      = $field . '.id + "_edit4"';
1381 1381
         echo "
1382 1382
             <div $restrict>
@@ -1400,8 +1400,8 @@  discard block
 block discarded – undo
1400 1400
     /**
1401 1401
      * Renders the website element template.
1402 1402
      */
1403
-    public function render_website_template( $field ) {
1404
-        $restrict = $this->get_restrict_markup( $field, 'website' );
1403
+    public function render_website_template($field) {
1404
+        $restrict = $this->get_restrict_markup($field, 'website');
1405 1405
         $label    = "$field.label";
1406 1406
         echo "
1407 1407
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1416,24 +1416,24 @@  discard block
 block discarded – undo
1416 1416
     /**
1417 1417
      * Renders the website element on the frontend.
1418 1418
      */
1419
-    public function frontend_render_website_template( $field ) {
1419
+    public function frontend_render_website_template($field) {
1420 1420
         
1421 1421
         echo "<div class='form-group'>";
1422 1422
 
1423 1423
         echo aui()->input(
1424 1424
             array(
1425
-                'name'       => esc_attr( $field['id'] ),
1426
-                'id'         => esc_attr( $field['id'] ),
1425
+                'name'       => esc_attr($field['id']),
1426
+                'id'         => esc_attr($field['id']),
1427 1427
                 'required'   => (bool) $field['required'],
1428
-                'label'      => wp_kses_post( $field['label'] ),
1428
+                'label'      => wp_kses_post($field['label']),
1429 1429
                 'no_wrap'    => true,
1430
-                'placeholder' => esc_attr( $field['placeholder'] ),
1430
+                'placeholder' => esc_attr($field['placeholder']),
1431 1431
                 'type'       => 'url',
1432 1432
             )
1433 1433
         );
1434 1434
 
1435
-        if ( ! empty( $field['description'] ) ) {
1436
-            $description = wp_kses_post( $field['description'] );
1435
+        if (!empty($field['description'])) {
1436
+            $description = wp_kses_post($field['description']);
1437 1437
             echo "<small class='form-text text-muted'>$description</small>";
1438 1438
         }
1439 1439
 
@@ -1444,16 +1444,16 @@  discard block
 block discarded – undo
1444 1444
     /**
1445 1445
      * Renders the edit website element template.
1446 1446
      */
1447
-    public function edit_website_template( $field ) {
1448
-        $restrict = $this->get_restrict_markup( $field, 'website' );
1449
-        $label    = __( 'Field Label', 'invoicing' );
1447
+    public function edit_website_template($field) {
1448
+        $restrict = $this->get_restrict_markup($field, 'website');
1449
+        $label    = __('Field Label', 'invoicing');
1450 1450
         $id       = $field . '.id + "_edit"';
1451
-        $label2   = __( 'Placeholder text', 'invoicing' );
1451
+        $label2   = __('Placeholder text', 'invoicing');
1452 1452
         $id2      = $field . '.id + "_edit2"';
1453
-        $label3   = __( 'Help text', 'invoicing' );
1454
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1453
+        $label3   = __('Help text', 'invoicing');
1454
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1455 1455
         $id3      = $field . '.id + "_edit3"';
1456
-        $label5   = __( 'Is this field required?', 'invoicing' );
1456
+        $label5   = __('Is this field required?', 'invoicing');
1457 1457
         $id4      = $field . '.id + "_edit4"';
1458 1458
         echo "
1459 1459
             <div $restrict>
@@ -1481,8 +1481,8 @@  discard block
 block discarded – undo
1481 1481
     /**
1482 1482
      * Renders the date element template.
1483 1483
      */
1484
-    public function render_date_template( $field ) {
1485
-        $restrict = $this->get_restrict_markup( $field, 'date' );
1484
+    public function render_date_template($field) {
1485
+        $restrict = $this->get_restrict_markup($field, 'date');
1486 1486
         $label    = "$field.label";
1487 1487
         echo "
1488 1488
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1497,23 +1497,23 @@  discard block
 block discarded – undo
1497 1497
     /**
1498 1498
      * Renders the date element on the frontend.
1499 1499
      */
1500
-    public function frontend_render_date_template( $field ) {
1500
+    public function frontend_render_date_template($field) {
1501 1501
         
1502 1502
         echo "<div class='form-group'>";
1503 1503
 
1504 1504
         echo aui()->input(
1505 1505
             array(
1506
-                'name'       => esc_attr( $field['id'] ),
1507
-                'id'         => esc_attr( $field['id'] ),
1506
+                'name'       => esc_attr($field['id']),
1507
+                'id'         => esc_attr($field['id']),
1508 1508
                 'required'   => (bool) $field['required'],
1509
-                'label'      => wp_kses_post( $field['label'] ),
1509
+                'label'      => wp_kses_post($field['label']),
1510 1510
                 'no_wrap'    => true,
1511 1511
                 'type'       => 'date',
1512 1512
             )
1513 1513
         );
1514 1514
 
1515
-        if ( ! empty( $field['description'] ) ) {
1516
-            $description = wp_kses_post( $field['description'] );
1515
+        if (!empty($field['description'])) {
1516
+            $description = wp_kses_post($field['description']);
1517 1517
             echo "<small class='form-text text-muted'>$description</small>";
1518 1518
         }
1519 1519
 
@@ -1524,14 +1524,14 @@  discard block
 block discarded – undo
1524 1524
     /**
1525 1525
      * Renders the edit date element template.
1526 1526
      */
1527
-    public function edit_date_template( $field ) {
1528
-        $restrict = $this->get_restrict_markup( $field, 'date' );
1529
-        $label    = __( 'Field Label', 'invoicing' );
1527
+    public function edit_date_template($field) {
1528
+        $restrict = $this->get_restrict_markup($field, 'date');
1529
+        $label    = __('Field Label', 'invoicing');
1530 1530
         $id       = $field . '.id + "_edit"';
1531
-        $label3   = __( 'Help text', 'invoicing' );
1532
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1531
+        $label3   = __('Help text', 'invoicing');
1532
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1533 1533
         $id3      = $field . '.id + "_edit3"';
1534
-        $label5   = __( 'Is this field required?', 'invoicing' );
1534
+        $label5   = __('Is this field required?', 'invoicing');
1535 1535
         $id4      = $field . '.id + "_edit4"';
1536 1536
         echo "
1537 1537
             <div $restrict>
@@ -1555,8 +1555,8 @@  discard block
 block discarded – undo
1555 1555
     /**
1556 1556
      * Renders the time element template.
1557 1557
      */
1558
-    public function render_time_template( $field ) {
1559
-        $restrict = $this->get_restrict_markup( $field, 'time' );
1558
+    public function render_time_template($field) {
1559
+        $restrict = $this->get_restrict_markup($field, 'time');
1560 1560
         $label    = "$field.label";
1561 1561
         echo "
1562 1562
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1571,23 +1571,23 @@  discard block
 block discarded – undo
1571 1571
     /**
1572 1572
      * Renders the time element on the frontend.
1573 1573
      */
1574
-    public function frontend_render_time_template( $field ) {
1574
+    public function frontend_render_time_template($field) {
1575 1575
         
1576 1576
         echo "<div class='form-group'>";
1577 1577
 
1578 1578
         echo aui()->input(
1579 1579
             array(
1580
-                'name'       => esc_attr( $field['id'] ),
1581
-                'id'         => esc_attr( $field['id'] ),
1580
+                'name'       => esc_attr($field['id']),
1581
+                'id'         => esc_attr($field['id']),
1582 1582
                 'required'   => (bool) $field['required'],
1583
-                'label'      => wp_kses_post( $field['label'] ),
1583
+                'label'      => wp_kses_post($field['label']),
1584 1584
                 'no_wrap'    => true,
1585 1585
                 'type'       => 'time',
1586 1586
             )
1587 1587
         );
1588 1588
 
1589
-        if ( ! empty( $field['description'] ) ) {
1590
-            $description = wp_kses_post( $field['description'] );
1589
+        if (!empty($field['description'])) {
1590
+            $description = wp_kses_post($field['description']);
1591 1591
             echo "<small class='form-text text-muted'>$description</small>";
1592 1592
         }
1593 1593
 
@@ -1598,14 +1598,14 @@  discard block
 block discarded – undo
1598 1598
     /**
1599 1599
      * Renders the edit time element template.
1600 1600
      */
1601
-    public function edit_time_template( $field ) {
1602
-        $restrict = $this->get_restrict_markup( $field, 'time' );
1603
-        $label    = __( 'Field Label', 'invoicing' );
1601
+    public function edit_time_template($field) {
1602
+        $restrict = $this->get_restrict_markup($field, 'time');
1603
+        $label    = __('Field Label', 'invoicing');
1604 1604
         $id       = $field . '.id + "_edit"';
1605
-        $label3   = __( 'Help text', 'invoicing' );
1606
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1605
+        $label3   = __('Help text', 'invoicing');
1606
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1607 1607
         $id3      = $field . '.id + "_edit3"';
1608
-        $label5   = __( 'Is this field required?', 'invoicing' );
1608
+        $label5   = __('Is this field required?', 'invoicing');
1609 1609
         $id4      = $field . '.id + "_edit4"';
1610 1610
         echo "
1611 1611
             <div $restrict>
@@ -1629,8 +1629,8 @@  discard block
 block discarded – undo
1629 1629
     /**
1630 1630
      * Renders the number element template.
1631 1631
      */
1632
-    public function render_number_template( $field ) {
1633
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1632
+    public function render_number_template($field) {
1633
+        $restrict = $this->get_restrict_markup($field, 'number');
1634 1634
         $label    = "$field.label";
1635 1635
         echo "
1636 1636
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1645,24 +1645,24 @@  discard block
 block discarded – undo
1645 1645
     /**
1646 1646
      * Renders the number element on the frontend.
1647 1647
      */
1648
-    public function frontend_render_number_template( $field ) {
1648
+    public function frontend_render_number_template($field) {
1649 1649
         
1650 1650
         echo "<div class='form-group'>";
1651 1651
 
1652 1652
         echo aui()->input(
1653 1653
             array(
1654
-                'name'       => esc_attr( $field['id'] ),
1655
-                'id'         => esc_attr( $field['id'] ),
1654
+                'name'       => esc_attr($field['id']),
1655
+                'id'         => esc_attr($field['id']),
1656 1656
                 'required'   => (bool) $field['required'],
1657
-                'label'      => wp_kses_post( $field['label'] ),
1658
-                'placeholder' => esc_attr( $field['placeholder'] ),
1657
+                'label'      => wp_kses_post($field['label']),
1658
+                'placeholder' => esc_attr($field['placeholder']),
1659 1659
                 'no_wrap'    => true,
1660 1660
                 'type'       => 'number',
1661 1661
             )
1662 1662
         );
1663 1663
 
1664
-        if ( ! empty( $field['description'] ) ) {
1665
-            $description = wp_kses_post( $field['description'] );
1664
+        if (!empty($field['description'])) {
1665
+            $description = wp_kses_post($field['description']);
1666 1666
             echo "<small class='form-text text-muted'>$description</small>";
1667 1667
         }
1668 1668
 
@@ -1673,16 +1673,16 @@  discard block
 block discarded – undo
1673 1673
     /**
1674 1674
      * Renders the edit number element template.
1675 1675
      */
1676
-    public function edit_number_template( $field ) {
1677
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1678
-        $label    = __( 'Field Label', 'invoicing' );
1676
+    public function edit_number_template($field) {
1677
+        $restrict = $this->get_restrict_markup($field, 'number');
1678
+        $label    = __('Field Label', 'invoicing');
1679 1679
         $id       = $field . '.id + "_edit"';
1680
-        $label2   = __( 'Placeholder text', 'invoicing' );
1680
+        $label2   = __('Placeholder text', 'invoicing');
1681 1681
         $id2      = $field . '.id + "_edit2"';
1682
-        $label3   = __( 'Help text', 'invoicing' );
1683
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1682
+        $label3   = __('Help text', 'invoicing');
1683
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1684 1684
         $id3      = $field . '.id + "_edit3"';
1685
-        $label5   = __( 'Is this field required?', 'invoicing' );
1685
+        $label5   = __('Is this field required?', 'invoicing');
1686 1686
         $id4      = $field . '.id + "_edit4"';
1687 1687
         echo "
1688 1688
             <div $restrict>
@@ -1710,23 +1710,23 @@  discard block
 block discarded – undo
1710 1710
     /**
1711 1711
      * Renders the separator element template.
1712 1712
      */
1713
-    public function render_separator_template( $field ) {
1714
-        $restrict = $this->get_restrict_markup( $field, 'separator' );
1713
+    public function render_separator_template($field) {
1714
+        $restrict = $this->get_restrict_markup($field, 'separator');
1715 1715
         echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1716 1716
     }
1717 1717
 
1718 1718
     /**
1719 1719
      * Renders the separator element on the frontend.
1720 1720
      */
1721
-    public function frontend_render_separator_template( $field ) {
1721
+    public function frontend_render_separator_template($field) {
1722 1722
         echo '<hr class="featurette-divider mt-0 mb-2" />';
1723 1723
     }
1724 1724
 
1725 1725
     /**
1726 1726
      * Renders the pay button element template.
1727 1727
      */
1728
-    public function render_pay_button_template( $field ) {
1729
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1728
+    public function render_pay_button_template($field) {
1729
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1730 1730
         $label    = "$field.label";
1731 1731
         echo "
1732 1732
             <div $restrict>
@@ -1739,28 +1739,28 @@  discard block
 block discarded – undo
1739 1739
     /**
1740 1740
      * Renders the pay_button element on the frontend.
1741 1741
      */
1742
-    public function frontend_render_pay_button_template( $field ) {
1742
+    public function frontend_render_pay_button_template($field) {
1743 1743
 
1744 1744
         echo "<div class='mt-4 mb-4'>";
1745
-            do_action( 'wpinv_payment_mode_select' );
1745
+            do_action('wpinv_payment_mode_select');
1746 1746
         echo "</div>";
1747 1747
 
1748 1748
         echo "<div class='form-group'>";
1749 1749
 
1750
-        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1750
+        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class($field['class']);
1751 1751
         echo aui()->input(
1752 1752
             array(
1753
-                'name'       => esc_attr( $field['id'] ),
1754
-                'id'         => esc_attr( $field['id'] ),
1755
-                'value'      => esc_attr( $field['label'] ),
1753
+                'name'       => esc_attr($field['id']),
1754
+                'id'         => esc_attr($field['id']),
1755
+                'value'      => esc_attr($field['label']),
1756 1756
                 'no_wrap'    => true,
1757 1757
                 'type'       => 'submit',
1758 1758
                 'class'      => $class,
1759 1759
             )
1760 1760
         );
1761 1761
 
1762
-        if ( ! empty( $field['description'] ) ) {
1763
-            $description = wp_kses_post( $field['description'] );
1762
+        if (!empty($field['description'])) {
1763
+            $description = wp_kses_post($field['description']);
1764 1764
             echo "<small class='form-text text-muted'>$description</small>";
1765 1765
         }
1766 1766
 
@@ -1771,14 +1771,14 @@  discard block
 block discarded – undo
1771 1771
     /**
1772 1772
      * Renders the pay button element template.
1773 1773
      */
1774
-    public function edit_pay_button_template( $field ) {
1775
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1776
-        $label    = __( 'Button Text', 'invoicing' );
1774
+    public function edit_pay_button_template($field) {
1775
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1776
+        $label    = __('Button Text', 'invoicing');
1777 1777
         $id       = $field . '.id + "_edit"';
1778
-        $label2   = __( 'Help text', 'invoicing' );
1779
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1778
+        $label2   = __('Help text', 'invoicing');
1779
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1780 1780
         $id2      = $field . '.id + "_edit2"';
1781
-        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1781
+        $label4   = esc_attr__('Button Type', 'invoicing');
1782 1782
         $id3      = $field . '.id + "_edit3"';
1783 1783
         echo "
1784 1784
             <div $restrict>
@@ -1794,15 +1794,15 @@  discard block
 block discarded – undo
1794 1794
                     <label :for='$id3'>$label4</label>
1795 1795
 
1796 1796
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1797
-                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1798
-                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1799
-                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1800
-                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1801
-                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1802
-                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1803
-                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1804
-                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1805
-                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1797
+                        <option value='btn-primary'>" . __('Primary', 'invoicing') . "</option>
1798
+                        <option value='btn-secondary'>" . __('Secondary', 'invoicing') . "</option>
1799
+                        <option value='btn-success'>"   . __('Success', 'invoicing') . "</option>
1800
+                        <option value='btn-danger'>"    . __('Danger', 'invoicing') . "</option>
1801
+                        <option value='btn-warning'>"   . __('Warning', 'invoicing') . "</option>
1802
+                        <option value='btn-info'>"      . __('Info', 'invoicing') . "</option>
1803
+                        <option value='btn-light'>"     . __('Light', 'invoicing') . "</option>
1804
+                        <option value='btn-dark'>"      . __('Dark', 'invoicing') . "</option>
1805
+                        <option value='btn-link'>"      . __('Link', 'invoicing') . "</option>
1806 1806
                     </select>
1807 1807
                 </div>
1808 1808
             </div>
@@ -1813,8 +1813,8 @@  discard block
 block discarded – undo
1813 1813
     /**
1814 1814
      * Renders the alert element template.
1815 1815
      */
1816
-    public function render_alert_template( $field ) {
1817
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1816
+    public function render_alert_template($field) {
1817
+        $restrict = $this->get_restrict_markup($field, 'alert');
1818 1818
         $text     = "$field.text";
1819 1819
         echo "
1820 1820
             <div $restrict class='alert' :class='$field.class' role='alert'>
@@ -1829,15 +1829,15 @@  discard block
 block discarded – undo
1829 1829
     /**
1830 1830
      * Renders the alert element on the frontend.
1831 1831
      */
1832
-    public function frontend_render_alert_template( $field ) {
1832
+    public function frontend_render_alert_template($field) {
1833 1833
         
1834 1834
         echo "<div class='form-group'>";
1835 1835
 
1836 1836
         echo aui()->alert(
1837 1837
             array(
1838
-                'content'     => wp_kses_post( $field['text'] ),
1838
+                'content'     => wp_kses_post($field['text']),
1839 1839
                 'dismissible' => $field['dismissible'],
1840
-                'type'        => str_replace( 'alert-', '', $field['class'] ),
1840
+                'type'        => str_replace('alert-', '', $field['class']),
1841 1841
             )
1842 1842
         );
1843 1843
 
@@ -1848,14 +1848,14 @@  discard block
 block discarded – undo
1848 1848
     /**
1849 1849
      * Renders the alert element template.
1850 1850
      */
1851
-    public function edit_alert_template( $field ) {
1852
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1853
-        $label    = __( 'Alert Text', 'invoicing' );
1854
-        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1851
+    public function edit_alert_template($field) {
1852
+        $restrict = $this->get_restrict_markup($field, 'alert');
1853
+        $label    = __('Alert Text', 'invoicing');
1854
+        $label2   = esc_attr__('Enter your alert text here', 'invoicing');
1855 1855
         $id       = $field . '.id + "_edit"';
1856
-        $label3   = __( 'Is Dismissible?', 'invoicing' );
1856
+        $label3   = __('Is Dismissible?', 'invoicing');
1857 1857
         $id2      = $field . '.id + "_edit2"';
1858
-        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1858
+        $label4   = esc_attr__('Alert Type', 'invoicing');
1859 1859
         $id3      = $field . '.id + "_edit3"';
1860 1860
         echo "
1861 1861
             <div $restrict>
@@ -1871,14 +1871,14 @@  discard block
 block discarded – undo
1871 1871
                     <label :for='$id3'>$label4</label>
1872 1872
 
1873 1873
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1874
-                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1875
-                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1876
-                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1877
-                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1878
-                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1879
-                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1880
-                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1881
-                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1874
+                        <option value='alert-primary'>" . __('Primary', 'invoicing') . "</option>
1875
+                        <option value='alert-secondary'>" . __('Secondary', 'invoicing') . "</option>
1876
+                        <option value='alert-success'>"   . __('Success', 'invoicing') . "</option>
1877
+                        <option value='alert-danger'>"    . __('Danger', 'invoicing') . "</option>
1878
+                        <option value='alert-warning'>"   . __('Warning', 'invoicing') . "</option>
1879
+                        <option value='alert-info'>"      . __('Info', 'invoicing') . "</option>
1880
+                        <option value='alert-light'>"     . __('Light', 'invoicing') . "</option>
1881
+                        <option value='alert-dark'>"      . __('Dark', 'invoicing') . "</option>
1882 1882
                     </select>
1883 1883
                 </div>
1884 1884
             </div>
@@ -1889,8 +1889,8 @@  discard block
 block discarded – undo
1889 1889
     /**
1890 1890
      * Renders the discount element template.
1891 1891
      */
1892
-    public function render_discount_template( $field ) {
1893
-        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1892
+    public function render_discount_template($field) {
1893
+        $restrict = $this->get_restrict_markup($field, 'discount');
1894 1894
         ?>
1895 1895
 
1896 1896
             <div <?php echo $restrict; ?> class="discount_field border rounded p-3 wpinv-payment-form-field-preview">
@@ -1908,13 +1908,13 @@  discard block
 block discarded – undo
1908 1908
     /**
1909 1909
      * Renders the discount element on the frontend.
1910 1910
      */
1911
-    public function frontend_render_discount_template( $field ) {
1911
+    public function frontend_render_discount_template($field) {
1912 1912
         
1913
-        $placeholder = esc_attr( $field['input_label'] );
1914
-        $label       = sanitize_text_field( $field['button_label'] );
1913
+        $placeholder = esc_attr($field['input_label']);
1914
+        $label       = sanitize_text_field($field['button_label']);
1915 1915
         $description = '';
1916 1916
 
1917
-        if ( ! empty( $field['description'] ) ) {
1917
+        if (!empty($field['description'])) {
1918 1918
             $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1919 1919
         }
1920 1920
 ?>
@@ -1936,12 +1936,12 @@  discard block
 block discarded – undo
1936 1936
     /**
1937 1937
      * Renders the discount element template.
1938 1938
      */
1939
-    public function edit_discount_template( $field ) {
1940
-        $restrict = $this->get_restrict_markup( $field, 'discount' );
1941
-        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1942
-        $label2   = __( 'Help Text', 'invoicing' );
1943
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1944
-        $label4   = __( 'Button Text', 'invoicing' );
1939
+    public function edit_discount_template($field) {
1940
+        $restrict = $this->get_restrict_markup($field, 'discount');
1941
+        $label    = __('Discount Input Placeholder', 'invoicing');
1942
+        $label2   = __('Help Text', 'invoicing');
1943
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1944
+        $label4   = __('Button Text', 'invoicing');
1945 1945
         $id       = $field . '.id + "_edit"';
1946 1946
         $id2      = $field . '.id + "_edit2"';
1947 1947
         $id3      = $field . '.id + "_edit3"';
@@ -1970,12 +1970,12 @@  discard block
 block discarded – undo
1970 1970
     /**
1971 1971
      * Renders the items element template.
1972 1972
      */
1973
-    public function render_items_template( $field ) {
1974
-        $restrict  = $this->get_restrict_markup( $field, 'items' );
1975
-        $label     = __( 'Item totals will appear here. Click to set items.', 'invoicing' );
1976
-        $label2    = __( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' );
1977
-        $label2   .= ' ' . __( 'To prevent this, limit customers to selecting a single item.', 'invoicing' );
1978
-        $label3    = __( 'Item totals will appear here.', 'invoicing' );
1973
+    public function render_items_template($field) {
1974
+        $restrict  = $this->get_restrict_markup($field, 'items');
1975
+        $label     = __('Item totals will appear here. Click to set items.', 'invoicing');
1976
+        $label2    = __('Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing');
1977
+        $label2   .= ' ' . __('To prevent this, limit customers to selecting a single item.', 'invoicing');
1978
+        $label3    = __('Item totals will appear here.', 'invoicing');
1979 1979
         echo "
1980 1980
             <div $restrict class='item_totals text-center'>
1981 1981
                 <div v-if='!is_default'>
@@ -1992,17 +1992,17 @@  discard block
 block discarded – undo
1992 1992
     /**
1993 1993
      * Renders the items element on the frontend.
1994 1994
      */
1995
-    public function frontend_render_items_template( $field, $items ) {
1995
+    public function frontend_render_items_template($field, $items) {
1996 1996
 
1997 1997
         echo "<div class='form-group item_totals'>";
1998 1998
         
1999
-        $id = esc_attr( $field['id'] );
1999
+        $id = esc_attr($field['id']);
2000 2000
 
2001
-        if ( empty( $field[ 'items_type' ] ) ) {
2002
-            $field[ 'items_type' ] = 'total';
2001
+        if (empty($field['items_type'])) {
2002
+            $field['items_type'] = 'total';
2003 2003
         }
2004 2004
 
2005
-        if ( 'total' == $field[ 'items_type' ] ) {
2005
+        if ('total' == $field['items_type']) {
2006 2006
             $total     = 0;
2007 2007
             $tax       = 0;
2008 2008
             $sub_total = 0;
@@ -2011,16 +2011,16 @@  discard block
 block discarded – undo
2011 2011
             <div class="border item_totals_type_total">
2012 2012
 
2013 2013
                 <?php
2014
-                    foreach( $items as $item ) {
2014
+                    foreach ($items as $item) {
2015 2015
 
2016
-                        $amount = floatval( $item['price'] );
2016
+                        $amount = floatval($item['price']);
2017 2017
 
2018
-                        if ( wpinv_use_taxes() ) {
2018
+                        if (wpinv_use_taxes()) {
2019 2019
 
2020
-                            $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2020
+                            $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2021 2021
 
2022
-                            if ( wpinv_prices_include_tax() ) {
2023
-                                $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2022
+                            if (wpinv_prices_include_tax()) {
2023
+                                $pre_tax  = ($amount - $amount * $rate * 0.01);
2024 2024
                                 $item_tax = $amount - $pre_tax;
2025 2025
                             } else {
2026 2026
                                 $pre_tax  = $amount;
@@ -2032,32 +2032,32 @@  discard block
 block discarded – undo
2032 2032
                             $total     = $sub_total + $tax;
2033 2033
 
2034 2034
                         } else {
2035
-                            $total  = $total + $amount;
2035
+                            $total = $total + $amount;
2036 2036
                         }
2037 2037
 
2038 2038
                         $class  = 'col-8';
2039 2039
                         $class2 = '';
2040 2040
 
2041
-                        if ( ! empty( $item['allow_quantities'] ) ) {
2041
+                        if (!empty($item['allow_quantities'])) {
2042 2042
                             $class = 'col-6 pt-2';
2043 2043
                             $class2 = 'pt-2';
2044 2044
                         }
2045 2045
 
2046
-                        if ( ! empty( $item['custom_price'] ) ) {
2046
+                        if (!empty($item['custom_price'])) {
2047 2047
                             $class .= ' pt-2';
2048 2048
                         }
2049 2049
 
2050 2050
                         $quantity = 1;
2051
-                        if ( ! empty( $item['quantity'] ) ) {
2052
-                            $quantity = absint( $item['quantity'] );
2051
+                        if (!empty($item['quantity'])) {
2052
+                            $quantity = absint($item['quantity']);
2053 2053
                         }
2054 2054
             
2055 2055
                 ?>
2056 2056
                     <div  class="item_totals_item">
2057 2057
                         <div class='row pl-2 pr-2 pt-2'>
2058
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2058
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2059 2059
 
2060
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2060
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2061 2061
 
2062 2062
                                 <div class='col-2'>
2063 2063
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='<?php echo $quantity ?>' min='1' required>
@@ -2065,11 +2065,11 @@  discard block
 block discarded – undo
2065 2065
 
2066 2066
                             <?php } else { ?>
2067 2067
                                 <input type='hidden' class='wpinv-item-quantity-input' value='<?php echo $quantity ?>'>
2068
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2068
+                            <?php } if (empty($item['custom_price'])) { ?>
2069 2069
 
2070 2070
                                 <div class='col-4 <?php echo $class2; ?>'>
2071
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2072
-                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2071
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2072
+                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2073 2073
                                 </div>
2074 2074
 
2075 2075
                             <?php } else {?>
@@ -2077,15 +2077,15 @@  discard block
 block discarded – undo
2077 2077
                                 <div class='col-4'>
2078 2078
                                     <div class='input-group'>
2079 2079
 
2080
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2080
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2081 2081
                                             <div class='input-group-prepend'>
2082 2082
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2083 2083
                                             </div>
2084 2084
                                         <?php } ?>
2085 2085
 
2086
-                                        <input type='text' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2086
+                                        <input type='text' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2087 2087
                                     
2088
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2088
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2089 2089
                                             <div class='input-group-append'>
2090 2090
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2091 2091
                                             </div>
@@ -2096,8 +2096,8 @@  discard block
 block discarded – undo
2096 2096
                             <?php } ?>
2097 2097
 
2098 2098
                         </div>
2099
-                        <?php if ( ! empty( $item['description'] )) { ?>
2100
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2099
+                        <?php if (!empty($item['description'])) { ?>
2100
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2101 2101
                         <?php } ?>
2102 2102
                     </div>
2103 2103
                 <?php } ?>
@@ -2105,25 +2105,25 @@  discard block
 block discarded – undo
2105 2105
                 <div class='mt-4 border-top item_totals_total p-2'>
2106 2106
 
2107 2107
                     <div class='row'>
2108
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2109
-                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2108
+                        <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2109
+                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2110 2110
                     </div>
2111 2111
 
2112 2112
                     <div class='row' style='display: none;'>
2113
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
2114
-                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div>
2113
+                        <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div>
2114
+                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div>
2115 2115
                     </div>
2116 2116
 
2117
-                    <?php if ( wpinv_use_taxes() ) { ?>
2117
+                    <?php if (wpinv_use_taxes()) { ?>
2118 2118
                         <div class='row'>
2119
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2120
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2119
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2120
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2121 2121
                         </div>
2122 2122
                     <?php } ?>
2123 2123
 
2124 2124
                     <div class='row'>
2125
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2126
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2125
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2126
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2127 2127
                     </div>
2128 2128
 
2129 2129
                 </div>
@@ -2131,22 +2131,22 @@  discard block
 block discarded – undo
2131 2131
             </div>
2132 2132
         <?php } ?>
2133 2133
 
2134
-        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
2134
+        <?php if ('radio' == $field['items_type']) { ?>
2135 2135
             <div class="item_totals_type_radio">
2136 2136
 
2137 2137
                 <?php
2138
-                    foreach( $items as $index => $item ) {
2138
+                    foreach ($items as $index => $item) {
2139 2139
 
2140
-                        if ( ! empty( $item['required'] ) ) {
2140
+                        if (!empty($item['required'])) {
2141 2141
                             continue;
2142 2142
                         }
2143 2143
                 ?>
2144 2144
                     <div  class="form-check">
2145
-                        <input class='form-check-input wpinv-items-selector' <?php checked( ! isset( $selected_radio_item ) ); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'>
2146
-                        <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?>&nbsp;<strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) ); ?></strong></label>
2145
+                        <input class='form-check-input wpinv-items-selector' <?php checked(!isset($selected_radio_item)); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'>
2146
+                        <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field($item['title']); ?>&nbsp;<strong><?php echo wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); ?></strong></label>
2147 2147
                     </div>
2148
-                    <?php if ( ! empty( $item['description'] )) { ?>
2149
-                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2148
+                    <?php if (!empty($item['description'])) { ?>
2149
+                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2150 2150
                     <?php } ?>
2151 2151
                 <?php } ?>
2152 2152
 
@@ -2158,32 +2158,32 @@  discard block
 block discarded – undo
2158 2158
                         $tax       = 0;
2159 2159
                         $sub_total = 0;
2160 2160
 
2161
-                        foreach ( $items as $item ) {
2161
+                        foreach ($items as $item) {
2162 2162
 
2163 2163
                             $class  = 'col-8';
2164 2164
                             $class2 = '';
2165 2165
 
2166
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2166
+                            if (!empty($item['allow_quantities'])) {
2167 2167
                                 $class = 'col-6 pt-2';
2168 2168
                                 $class2 = 'pt-2';
2169 2169
                             }
2170 2170
 
2171
-                            if ( ! empty( $item['custom_price'] ) ) {
2171
+                            if (!empty($item['custom_price'])) {
2172 2172
                                 $class .= ' pt-2';
2173 2173
                             }
2174 2174
 
2175 2175
                             $class3 = 'd-none';
2176 2176
                             $name   = '';
2177
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
2177
+                            if (!empty($item['required']) || !isset($totals_selected_radio_item)) {
2178 2178
 
2179
-                                $amount = floatval( $item['price'] );
2179
+                                $amount = floatval($item['price']);
2180 2180
 
2181
-                                if ( wpinv_use_taxes() ) {
2181
+                                if (wpinv_use_taxes()) {
2182 2182
 
2183
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2183
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2184 2184
 
2185
-                                    if ( wpinv_prices_include_tax() ) {
2186
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2185
+                                    if (wpinv_prices_include_tax()) {
2186
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2187 2187
                                         $item_tax = $amount - $pre_tax;
2188 2188
                                     } else {
2189 2189
                                         $pre_tax  = $amount;
@@ -2195,13 +2195,13 @@  discard block
 block discarded – undo
2195 2195
                                     $total     = $sub_total + $tax;
2196 2196
 
2197 2197
                                 } else {
2198
-                                    $total  = $total + $amount;
2198
+                                    $total = $total + $amount;
2199 2199
                                 }
2200 2200
 
2201 2201
                                 $class3 = '';
2202 2202
                                 $name   = "wpinv-items[{$item['id']}]";
2203 2203
 
2204
-                                if ( empty( $item['required'] ) ) {
2204
+                                if (empty($item['required'])) {
2205 2205
                                     $totals_selected_radio_item = 1;
2206 2206
                                 }
2207 2207
 
@@ -2213,9 +2213,9 @@  discard block
 block discarded – undo
2213 2213
 
2214 2214
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2215 2215
                         <div class='row pl-2 pr-2 pt-2'>
2216
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2216
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2217 2217
 
2218
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2218
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2219 2219
 
2220 2220
                                 <div class='col-2'>
2221 2221
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2223,11 +2223,11 @@  discard block
 block discarded – undo
2223 2223
 
2224 2224
                             <?php } else { ?>
2225 2225
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2226
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2226
+                            <?php } if (empty($item['custom_price'])) { ?>
2227 2227
 
2228 2228
                                 <div class='col-4 <?php echo $class2; ?>'>
2229
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2230
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2229
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2230
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2231 2231
                                 </div>
2232 2232
 
2233 2233
                             <?php } else {?>
@@ -2235,15 +2235,15 @@  discard block
 block discarded – undo
2235 2235
                                 <div class='col-4'>
2236 2236
                                     <div class='input-group'>
2237 2237
 
2238
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2238
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2239 2239
                                             <div class='input-group-prepend'>
2240 2240
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2241 2241
                                             </div>
2242 2242
                                         <?php } ?>
2243 2243
 
2244
-                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2244
+                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2245 2245
                                     
2246
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2246
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2247 2247
                                             <div class='input-group-append'>
2248 2248
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2249 2249
                                             </div>
@@ -2254,8 +2254,8 @@  discard block
 block discarded – undo
2254 2254
                             <?php } ?>
2255 2255
 
2256 2256
                         </div>
2257
-                        <?php if ( ! empty( $item['description'] )) { ?>
2258
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2257
+                        <?php if (!empty($item['description'])) { ?>
2258
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2259 2259
                         <?php } ?>
2260 2260
                     </div>
2261 2261
                 <?php } ?>
@@ -2263,25 +2263,25 @@  discard block
 block discarded – undo
2263 2263
                 <div class='mt-4 border-top item_totals_total p-2'>
2264 2264
 
2265 2265
                     <div class='row'>
2266
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2267
-                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2266
+                        <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2267
+                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2268 2268
                     </div>
2269 2269
 
2270 2270
                     <div class='row' style='display: none;'>
2271
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
2271
+                        <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div>
2272 2272
                         <div class='col-4'><strong class='wpinv-items-discount'></strong></div>
2273 2273
                     </div>
2274 2274
 
2275
-                    <?php if ( wpinv_use_taxes() ) { ?>
2275
+                    <?php if (wpinv_use_taxes()) { ?>
2276 2276
                         <div class='row'>
2277
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2278
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2277
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2278
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2279 2279
                         </div>
2280 2280
                     <?php } ?>
2281 2281
 
2282 2282
                     <div class='row'>
2283
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2284
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2283
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2284
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2285 2285
                     </div>
2286 2286
                 </div>
2287 2287
 
@@ -2289,22 +2289,22 @@  discard block
 block discarded – undo
2289 2289
             </div>
2290 2290
         <?php } ?>
2291 2291
 
2292
-        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
2292
+        <?php if ('checkbox' == $field['items_type']) { ?>
2293 2293
 
2294 2294
             <div class="item_totals_type_checkbox">
2295 2295
 
2296 2296
                 <?php
2297
-                    foreach ( $items as $index => $item ) {
2297
+                    foreach ($items as $index => $item) {
2298 2298
 
2299
-                        if ( ! empty( $item['required'] ) ) {
2299
+                        if (!empty($item['required'])) {
2300 2300
                             continue;
2301 2301
                         }
2302 2302
 
2303
-                        $title = sanitize_text_field(  $item['title'] );
2304
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2305
-                        $item_id    = esc_attr( $id . "_$index" );
2306
-                        $value = esc_attr( $item['id'] );
2307
-                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
2303
+                        $title = sanitize_text_field($item['title']);
2304
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2305
+                        $item_id = esc_attr($id . "_$index");
2306
+                        $value = esc_attr($item['id']);
2307
+                        $checked = checked(!isset($selected_checkbox_item), true, false);
2308 2308
                         $selected_checkbox_item = 1;
2309 2309
 
2310 2310
                         echo "
@@ -2313,7 +2313,7 @@  discard block
 block discarded – undo
2313 2313
                                 <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
2314 2314
                             </div>";
2315 2315
 
2316
-                        if ( ! empty( $item['description'] ) ) {
2316
+                        if (!empty($item['description'])) {
2317 2317
                             echo "<small class='form-text text-muted'>{$item['description']}</small>";
2318 2318
                         }
2319 2319
                     }
@@ -2327,31 +2327,31 @@  discard block
 block discarded – undo
2327 2327
                         $tax       = 0;
2328 2328
                         $sub_total = 0;
2329 2329
 
2330
-                        foreach ( $items as $item ) {
2330
+                        foreach ($items as $item) {
2331 2331
 
2332 2332
                             $class  = 'col-8';
2333 2333
                             $class2 = '';
2334 2334
 
2335
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2335
+                            if (!empty($item['allow_quantities'])) {
2336 2336
                                 $class = 'col-6 pt-2';
2337 2337
                                 $class2 = 'pt-2';
2338 2338
                             }
2339 2339
 
2340
-                            if ( ! empty( $item['custom_price'] ) ) {
2340
+                            if (!empty($item['custom_price'])) {
2341 2341
                                 $class .= ' pt-2';
2342 2342
                             }
2343 2343
 
2344 2344
                             $class3 = 'd-none';
2345
-                            $name  = '';
2346
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
2345
+                            $name = '';
2346
+                            if (!empty($item['required']) || !isset($totals_selected_checkbox_item)) {
2347 2347
 
2348
-                                $amount = floatval( $item['price'] );
2349
-                                if ( wpinv_use_taxes() ) {
2348
+                                $amount = floatval($item['price']);
2349
+                                if (wpinv_use_taxes()) {
2350 2350
 
2351
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2351
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2352 2352
 
2353
-                                    if ( wpinv_prices_include_tax() ) {
2354
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2353
+                                    if (wpinv_prices_include_tax()) {
2354
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2355 2355
                                         $item_tax = $amount - $pre_tax;
2356 2356
                                     } else {
2357 2357
                                         $pre_tax  = $amount;
@@ -2363,13 +2363,13 @@  discard block
 block discarded – undo
2363 2363
                                     $total     = $sub_total + $tax;
2364 2364
 
2365 2365
                                 } else {
2366
-                                    $total  = $total + $amount;
2366
+                                    $total = $total + $amount;
2367 2367
                                 }
2368 2368
 
2369 2369
                                 $class3 = '';
2370
-                                $name  = "wpinv-items[{$item['id']}]";
2370
+                                $name = "wpinv-items[{$item['id']}]";
2371 2371
 
2372
-                                if ( empty( $item['required'] ) ) {
2372
+                                if (empty($item['required'])) {
2373 2373
                                     $totals_selected_checkbox_item = 1;
2374 2374
                                 }
2375 2375
 
@@ -2381,9 +2381,9 @@  discard block
 block discarded – undo
2381 2381
 
2382 2382
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2383 2383
                         <div class='row pl-2 pr-2 pt-2'>
2384
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2384
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2385 2385
 
2386
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2386
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2387 2387
 
2388 2388
                                 <div class='col-2'>
2389 2389
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2391,11 +2391,11 @@  discard block
 block discarded – undo
2391 2391
 
2392 2392
                             <?php } else { ?>
2393 2393
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2394
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2394
+                            <?php } if (empty($item['custom_price'])) { ?>
2395 2395
 
2396 2396
                                 <div class='col-4 <?php echo $class2; ?>'>
2397
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2398
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2397
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2398
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2399 2399
                                 </div>
2400 2400
 
2401 2401
                             <?php } else {?>
@@ -2403,15 +2403,15 @@  discard block
 block discarded – undo
2403 2403
                                 <div class='col-4'>
2404 2404
                                     <div class='input-group'>
2405 2405
 
2406
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2406
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2407 2407
                                             <div class='input-group-prepend'>
2408 2408
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2409 2409
                                             </div>
2410 2410
                                         <?php } ?>
2411 2411
 
2412
-                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2412
+                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2413 2413
                                     
2414
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2414
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2415 2415
                                             <div class='input-group-append'>
2416 2416
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2417 2417
                                             </div>
@@ -2422,8 +2422,8 @@  discard block
 block discarded – undo
2422 2422
                             <?php } ?>
2423 2423
 
2424 2424
                         </div>
2425
-                        <?php if ( ! empty( $item['description'] )) { ?>
2426
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2425
+                        <?php if (!empty($item['description'])) { ?>
2426
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2427 2427
                         <?php } ?>
2428 2428
                     </div>
2429 2429
                 <?php } ?>
@@ -2431,32 +2431,32 @@  discard block
 block discarded – undo
2431 2431
                 <div class='mt-4 border-top item_totals_total p-2'>
2432 2432
 
2433 2433
                     <div class='row'>
2434
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2435
-                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2434
+                        <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2435
+                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2436 2436
                     </div>
2437 2437
 
2438 2438
                     <div class='row' style='display: none;'>
2439
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
2440
-                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div>
2439
+                        <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div>
2440
+                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div>
2441 2441
                     </div>
2442 2442
 
2443
-                    <?php if ( wpinv_use_taxes() ) { ?>
2443
+                    <?php if (wpinv_use_taxes()) { ?>
2444 2444
                         <div class='row'>
2445
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2446
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2445
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2446
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2447 2447
                         </div>
2448 2448
                     <?php } ?>
2449 2449
 
2450 2450
                     <div class='row'>
2451
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2452
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2451
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2452
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2453 2453
                     </div>
2454 2454
                 </div>
2455 2455
             </div>
2456 2456
             </div>
2457 2457
         <?php } ?>
2458 2458
 
2459
-        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
2459
+        <?php if ('select' == $field['items_type']) { ?>
2460 2460
 
2461 2461
             <div class="item_totals_type_select">
2462 2462
 
@@ -2464,17 +2464,17 @@  discard block
 block discarded – undo
2464 2464
 
2465 2465
                     $options  = array();
2466 2466
                     $selected = '';
2467
-                    foreach ( $items as $index => $item ) {
2467
+                    foreach ($items as $index => $item) {
2468 2468
 
2469
-                        if ( ! empty( $item['required'] ) ) {
2469
+                        if (!empty($item['required'])) {
2470 2470
                             continue;
2471 2471
                         }
2472 2472
 
2473
-                        $title = sanitize_text_field(  $item['title'] );
2474
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2475
-                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2473
+                        $title = sanitize_text_field($item['title']);
2474
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2475
+                        $options[$item['id']] = "$title &nbsp; ($price)";
2476 2476
 
2477
-                        if ( ! isset( $selected_item ) ) {
2477
+                        if (!isset($selected_item)) {
2478 2478
                             $selected = $item['id'];
2479 2479
                             $selected_item = 1;
2480 2480
                         }
@@ -2485,7 +2485,7 @@  discard block
 block discarded – undo
2485 2485
                         array(
2486 2486
                                 'name'        => 'payment-form-items',
2487 2487
                                 'id'          => $id,
2488
-                                'placeholder' => __( 'Select an item', 'invoicing' ),
2488
+                                'placeholder' => __('Select an item', 'invoicing'),
2489 2489
                                 'no_wrap'     => true,
2490 2490
                                 'options'     => $options,
2491 2491
                                 'class'       => 'wpi_select2 wpinv-items-select-selector',
@@ -2502,31 +2502,31 @@  discard block
 block discarded – undo
2502 2502
                         $tax       = 0;
2503 2503
                         $sub_total = 0;
2504 2504
 
2505
-                        foreach ( $items as $item ) {
2505
+                        foreach ($items as $item) {
2506 2506
 
2507 2507
                             $class  = 'col-8';
2508 2508
                             $class2 = '';
2509 2509
 
2510
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2510
+                            if (!empty($item['allow_quantities'])) {
2511 2511
                                 $class = 'col-6 pt-2';
2512 2512
                                 $class2 = 'pt-2';
2513 2513
                             }
2514 2514
 
2515
-                            if ( ! empty( $item['custom_price'] ) ) {
2515
+                            if (!empty($item['custom_price'])) {
2516 2516
                                 $class .= ' pt-2';
2517 2517
                             }
2518 2518
 
2519 2519
                             $class3 = 'd-none';
2520
-                            $name  = '';
2521
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2520
+                            $name = '';
2521
+                            if (!empty($item['required']) || !isset($totals_selected_select_item)) {
2522 2522
 
2523
-                                $amount = floatval( $item['price'] );
2524
-                                if ( wpinv_use_taxes() ) {
2523
+                                $amount = floatval($item['price']);
2524
+                                if (wpinv_use_taxes()) {
2525 2525
 
2526
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2526
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2527 2527
 
2528
-                                    if ( wpinv_prices_include_tax() ) {
2529
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2528
+                                    if (wpinv_prices_include_tax()) {
2529
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2530 2530
                                         $item_tax = $amount - $pre_tax;
2531 2531
                                     } else {
2532 2532
                                         $pre_tax  = $amount;
@@ -2538,13 +2538,13 @@  discard block
 block discarded – undo
2538 2538
                                     $total     = $sub_total + $tax;
2539 2539
 
2540 2540
                                 } else {
2541
-                                    $total  = $total + $amount;
2541
+                                    $total = $total + $amount;
2542 2542
                                 }
2543 2543
 
2544 2544
                                 $class3 = '';
2545
-                                $name  = "wpinv-items[{$item['id']}]";
2545
+                                $name = "wpinv-items[{$item['id']}]";
2546 2546
 
2547
-                                if ( empty( $item['required'] ) ) {
2547
+                                if (empty($item['required'])) {
2548 2548
                                     $totals_selected_select_item = 1;
2549 2549
                                 }
2550 2550
 
@@ -2556,9 +2556,9 @@  discard block
 block discarded – undo
2556 2556
 
2557 2557
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2558 2558
                         <div class='row pl-2 pr-2 pt-2'>
2559
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2559
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2560 2560
 
2561
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2561
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2562 2562
 
2563 2563
                                 <div class='col-2'>
2564 2564
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2566,11 +2566,11 @@  discard block
 block discarded – undo
2566 2566
 
2567 2567
                             <?php } else { ?>
2568 2568
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2569
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2569
+                            <?php } if (empty($item['custom_price'])) { ?>
2570 2570
 
2571 2571
                                 <div class='col-4 <?php echo $class2; ?>'>
2572
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2573
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2572
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2573
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2574 2574
                                 </div>
2575 2575
 
2576 2576
                             <?php } else {?>
@@ -2578,15 +2578,15 @@  discard block
 block discarded – undo
2578 2578
                                 <div class='col-4'>
2579 2579
                                     <div class='input-group'>
2580 2580
 
2581
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2581
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2582 2582
                                             <div class='input-group-prepend'>
2583 2583
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2584 2584
                                             </div>
2585 2585
                                         <?php } ?>
2586 2586
 
2587
-                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2587
+                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2588 2588
                                     
2589
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2589
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2590 2590
                                             <div class='input-group-append'>
2591 2591
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2592 2592
                                             </div>
@@ -2597,8 +2597,8 @@  discard block
 block discarded – undo
2597 2597
                             <?php } ?>
2598 2598
 
2599 2599
                         </div>
2600
-                        <?php if ( ! empty( $item['description'] )) { ?>
2601
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2600
+                        <?php if (!empty($item['description'])) { ?>
2601
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2602 2602
                         <?php } ?>
2603 2603
                     </div>
2604 2604
                 <?php } ?>
@@ -2606,31 +2606,31 @@  discard block
 block discarded – undo
2606 2606
                 <div class='mt-4 border-top item_totals_total p-2'>
2607 2607
 
2608 2608
                     <div class='row'>
2609
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2610
-                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2609
+                        <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2610
+                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2611 2611
                     </div>
2612 2612
 
2613 2613
                     <div class='row' style='display: none;'>
2614
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
2615
-                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div>
2614
+                        <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div>
2615
+                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div>
2616 2616
                     </div>
2617 2617
 
2618
-                    <?php if ( wpinv_use_taxes() ) { ?>
2618
+                    <?php if (wpinv_use_taxes()) { ?>
2619 2619
                         <div class='row'>
2620
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2621
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2620
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2621
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2622 2622
                         </div>
2623 2623
                     <?php } ?>
2624 2624
                     <div class='row'>
2625
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2626
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2625
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2626
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2627 2627
                     </div>
2628 2628
                 </div>
2629 2629
 
2630 2630
             </div>
2631 2631
         <?php } ?>
2632 2632
 
2633
-        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
2633
+        <?php if ('multi_select' == $field['items_type']) { ?>
2634 2634
 
2635 2635
             <div class="item_totals_type_multi_select">
2636 2636
 
@@ -2639,18 +2639,18 @@  discard block
 block discarded – undo
2639 2639
                     $options  = array();
2640 2640
                     $selected = array();
2641 2641
 
2642
-                    foreach ( $items as $index => $item ) {
2642
+                    foreach ($items as $index => $item) {
2643 2643
 
2644
-                        if ( ! empty( $item['required'] ) ) {
2644
+                        if (!empty($item['required'])) {
2645 2645
                             continue;
2646 2646
                         }
2647 2647
 
2648
-                        $title = sanitize_text_field(  $item['title'] );
2649
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2650
-                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2648
+                        $title = sanitize_text_field($item['title']);
2649
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2650
+                        $options[$item['id']] = "$title &nbsp; ($price)";
2651 2651
 
2652
-                        if ( ! isset( $selected_item ) ) {
2653
-                            $selected = array( $item['id'] );
2652
+                        if (!isset($selected_item)) {
2653
+                            $selected = array($item['id']);
2654 2654
                             $selected_item = 1;
2655 2655
                         }
2656 2656
 
@@ -2677,31 +2677,31 @@  discard block
 block discarded – undo
2677 2677
                         $tax       = 0;
2678 2678
                         $sub_total = 0;
2679 2679
 
2680
-                        foreach ( $items as $item ) {
2680
+                        foreach ($items as $item) {
2681 2681
 
2682 2682
                             $class  = 'col-8';
2683 2683
                             $class2 = '';
2684 2684
 
2685
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2685
+                            if (!empty($item['allow_quantities'])) {
2686 2686
                                 $class = 'col-6 pt-2';
2687 2687
                                 $class2 = 'pt-2';
2688 2688
                             }
2689 2689
 
2690
-                            if ( ! empty( $item['custom_price'] ) ) {
2690
+                            if (!empty($item['custom_price'])) {
2691 2691
                                 $class .= ' pt-2';
2692 2692
                             }
2693 2693
 
2694 2694
                             $class3 = 'd-none';
2695
-                            $name  = '';
2696
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2695
+                            $name = '';
2696
+                            if (!empty($item['required']) || !isset($totals_selected_select_item)) {
2697 2697
 
2698
-                                $amount = floatval( $item['price'] );
2699
-                                if ( wpinv_use_taxes() ) {
2698
+                                $amount = floatval($item['price']);
2699
+                                if (wpinv_use_taxes()) {
2700 2700
 
2701
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2701
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2702 2702
 
2703
-                                    if ( wpinv_prices_include_tax() ) {
2704
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2703
+                                    if (wpinv_prices_include_tax()) {
2704
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2705 2705
                                         $item_tax = $amount - $pre_tax;
2706 2706
                                     } else {
2707 2707
                                         $pre_tax  = $amount;
@@ -2713,13 +2713,13 @@  discard block
 block discarded – undo
2713 2713
                                     $total     = $sub_total + $tax;
2714 2714
 
2715 2715
                                 } else {
2716
-                                    $total  = $total + $amount;
2716
+                                    $total = $total + $amount;
2717 2717
                                 }
2718 2718
 
2719 2719
                                 $class3 = '';
2720
-                                $name  = "wpinv-items[{$item['id']}]";
2720
+                                $name = "wpinv-items[{$item['id']}]";
2721 2721
 
2722
-                                if ( empty( $item['required'] ) ) {
2722
+                                if (empty($item['required'])) {
2723 2723
                                     $totals_selected_select_item = 1;
2724 2724
                                 }
2725 2725
 
@@ -2731,9 +2731,9 @@  discard block
 block discarded – undo
2731 2731
 
2732 2732
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2733 2733
                         <div class='row pl-2 pr-2 pt-2'>
2734
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2734
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2735 2735
 
2736
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2736
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2737 2737
 
2738 2738
                                 <div class='col-2'>
2739 2739
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2741,11 +2741,11 @@  discard block
 block discarded – undo
2741 2741
 
2742 2742
                             <?php } else { ?>
2743 2743
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2744
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2744
+                            <?php } if (empty($item['custom_price'])) { ?>
2745 2745
 
2746 2746
                                 <div class='col-4 <?php echo $class2; ?>'>
2747
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2748
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2747
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2748
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2749 2749
                                 </div>
2750 2750
 
2751 2751
                             <?php } else {?>
@@ -2753,15 +2753,15 @@  discard block
 block discarded – undo
2753 2753
                                 <div class='col-4'>
2754 2754
                                     <div class='input-group'>
2755 2755
 
2756
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2756
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2757 2757
                                             <div class='input-group-prepend'>
2758 2758
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2759 2759
                                             </div>
2760 2760
                                         <?php } ?>
2761 2761
 
2762
-                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2762
+                                        <input type='text' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2763 2763
                                     
2764
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2764
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2765 2765
                                             <div class='input-group-append'>
2766 2766
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2767 2767
                                             </div>
@@ -2772,8 +2772,8 @@  discard block
 block discarded – undo
2772 2772
                             <?php } ?>
2773 2773
 
2774 2774
                         </div>
2775
-                        <?php if ( ! empty( $item['description'] )) { ?>
2776
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2775
+                        <?php if (!empty($item['description'])) { ?>
2776
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2777 2777
                         <?php } ?>
2778 2778
                     </div>
2779 2779
                 <?php } ?>
@@ -2781,32 +2781,32 @@  discard block
 block discarded – undo
2781 2781
                 <div class='mt-4 border-top item_totals_total p-2'>
2782 2782
 
2783 2783
                     <div class='row'>
2784
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2785
-                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2784
+                        <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2785
+                        <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2786 2786
                     </div>
2787 2787
 
2788 2788
                     <div class='row' style='display: none;'>
2789
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Discount', 'invoicing' ); ?></strong></div>
2790
-                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price( wpinv_format_amount( 0 ) ) ?></strong></div>
2789
+                        <div class='col-8'><strong class='mr-5'><?php _e('Discount', 'invoicing'); ?></strong></div>
2790
+                        <div class='col-4'><strong class='wpinv-items-discount'><?php echo wpinv_price(wpinv_format_amount(0)) ?></strong></div>
2791 2791
                     </div>
2792 2792
 
2793
-                    <?php if ( wpinv_use_taxes() ) { ?>
2793
+                    <?php if (wpinv_use_taxes()) { ?>
2794 2794
                         <div class='row'>
2795
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2796
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2795
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2796
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2797 2797
                         </div>
2798 2798
                     <?php } ?>
2799 2799
 
2800 2800
                     <div class='row'>
2801
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2802
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2801
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2802
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2803 2803
                     </div>
2804 2804
                 </div>
2805 2805
 
2806 2806
             </div>
2807 2807
         <?php } ?>
2808
-        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
2809
-            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
2808
+        <?php if (!empty($field['description'])) { ?>
2809
+            <small class='form-text text-muted'><?php echo wp_kses_post($field['description']); ?></small>
2810 2810
         <?php } ?>
2811 2811
         </div>
2812 2812
         <?php
@@ -2815,57 +2815,57 @@  discard block
 block discarded – undo
2815 2815
     /**
2816 2816
      * Renders the items element template.
2817 2817
      */
2818
-    public function edit_items_template( $field ) {
2818
+    public function edit_items_template($field) {
2819 2819
         global $wpinv_euvat, $post;
2820 2820
 
2821
-        $restrict = $this->get_restrict_markup( $field, 'items' );
2822
-        $label    = __( 'Let customers...', 'invoicing' );
2823
-        $label2   = __( 'Available Items', 'invoicing' );
2824
-        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
2821
+        $restrict = $this->get_restrict_markup($field, 'items');
2822
+        $label    = __('Let customers...', 'invoicing');
2823
+        $label2   = __('Available Items', 'invoicing');
2824
+        $label3   = esc_attr__('Add some help text for this element', 'invoicing');
2825 2825
         $id       = $field . '.id + "_edit"';
2826 2826
         $id2      = $field . '.id + "_edit2"';
2827 2827
         $id3      = $field . '.id + "_edit3"';
2828 2828
         $id4      = $field . '.id + "_edit4"';
2829
-        $label4   = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' );
2830
-        $label5   = esc_attr__( 'Allow users to pay what they want', 'invoicing' );
2831
-        $label6   = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' );
2832
-        $label7   = esc_attr__( 'Allow users to buy several quantities', 'invoicing' );
2833
-        $label8   = esc_attr__( 'This item is required', 'invoicing' );
2829
+        $label4   = esc_attr__('This will be shown to the customer as the recommended price', 'invoicing');
2830
+        $label5   = esc_attr__('Allow users to pay what they want', 'invoicing');
2831
+        $label6   = esc_attr__('Enter the minimum price that a user can pay', 'invoicing');
2832
+        $label7   = esc_attr__('Allow users to buy several quantities', 'invoicing');
2833
+        $label8   = esc_attr__('This item is required', 'invoicing');
2834 2834
 
2835 2835
         // Item types.
2836
-        $item_types      = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
2836
+        $item_types      = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
2837 2837
         $item_types_html = '';
2838 2838
 
2839
-        foreach ( $item_types as $type => $_label ) {
2840
-            $type  = esc_attr( $type );
2841
-            $_label = esc_html( $_label );
2839
+        foreach ($item_types as $type => $_label) {
2840
+            $type = esc_attr($type);
2841
+            $_label = esc_html($_label);
2842 2842
             $item_types_html .= "<option value='$type'>$_label</type>";
2843 2843
         }
2844 2844
 
2845 2845
         // Taxes.
2846 2846
         $taxes = '';
2847
-        if ( $wpinv_euvat->allow_vat_rules() ) {
2847
+        if ($wpinv_euvat->allow_vat_rules()) {
2848 2848
             $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"rule\"'>";
2849
-            $taxes .= __( 'VAT rule type', 'invoicing' );
2849
+            $taxes .= __('VAT rule type', 'invoicing');
2850 2850
             $taxes .= "</label><select :id='$id + item.id + \"rule\"' class='form-control custom-select' v-model='item.rule'>";
2851 2851
 
2852
-            foreach ( $wpinv_euvat->get_rules() as $type => $_label ) {
2853
-                $type    = esc_attr( $type );
2854
-                $_label  = esc_html( $_label );
2852
+            foreach ($wpinv_euvat->get_rules() as $type => $_label) {
2853
+                $type    = esc_attr($type);
2854
+                $_label  = esc_html($_label);
2855 2855
                 $taxes  .= "<option value='$type'>$_label</type>";
2856 2856
             }
2857 2857
 
2858 2858
             $taxes .= '</select></div>';
2859 2859
         }
2860 2860
 
2861
-        if ( $wpinv_euvat->allow_vat_classes() ) {
2861
+        if ($wpinv_euvat->allow_vat_classes()) {
2862 2862
             $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"class\"'>";
2863
-            $taxes .= __( 'VAT class', 'invoicing' );
2863
+            $taxes .= __('VAT class', 'invoicing');
2864 2864
             $taxes .= "</label><select :id='$id + item.id + \"class\"' class='form-control custom-select' v-model='item.class'>";
2865 2865
 
2866
-            foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) {
2867
-                $type    = esc_attr( $type );
2868
-                $_label  = esc_html( $_label );
2866
+            foreach ($wpinv_euvat->get_all_classes() as $type => $_label) {
2867
+                $type    = esc_attr($type);
2868
+                $_label  = esc_html($_label);
2869 2869
                 $taxes  .= "<option value='$type'>$_label</type>";
2870 2870
             }
2871 2871
 
@@ -2950,7 +2950,7 @@  discard block
 block discarded – undo
2950 2950
                 <div class='form-group mt-2' v-if='!is_default'>
2951 2951
 
2952 2952
                     <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'>
2953
-                        <option value=''>"        . __( 'Add an existing item to the form', 'invoicing' ) ."</option>
2953
+                        <option value=''>" . __('Add an existing item to the form', 'invoicing') . "</option>
2954 2954
                         <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
2955 2955
                     </select>
2956 2956
 
@@ -2965,11 +2965,11 @@  discard block
 block discarded – undo
2965 2965
                     <label :for='$id2'>$label</label>
2966 2966
 
2967 2967
                     <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
2968
-                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
2969
-                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
2970
-                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
2971
-                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
2972
-                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
2968
+                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Buy all items on the list', 'invoicing') . "</option>
2969
+                        <option value='radio'>"        . __('Select a single item from the list', 'invoicing') . "</option>
2970
+                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select one or more items on the list', 'invoicing') . "</option>
2971
+                        <option value='select'>"       . __('Select a single item from a dropdown', 'invoicing') . "</option>
2972
+                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select a one or more items from a dropdown', 'invoicing') . "</option>
2973 2973
                     </select>
2974 2974
 
2975 2975
                 </div>
@@ -2994,7 +2994,7 @@  discard block
 block discarded – undo
2994 2994
             'orderby'        => 'title',
2995 2995
             'order'          => 'ASC',
2996 2996
             'posts_per_page' => -1,
2997
-            'post_status'    => array( 'publish' ),
2997
+            'post_status'    => array('publish'),
2998 2998
             'meta_query'     => array(
2999 2999
                 array(
3000 3000
                     'key'       => '_wpinv_type',
@@ -3004,24 +3004,24 @@  discard block
 block discarded – undo
3004 3004
             )
3005 3005
         );
3006 3006
     
3007
-        $items = get_posts( apply_filters( 'wpinv_payment_form_item_dropdown_query_args', $item_args ) );
3007
+        $items = get_posts(apply_filters('wpinv_payment_form_item_dropdown_query_args', $item_args));
3008 3008
 
3009
-        if ( empty( $items ) ) {
3009
+        if (empty($items)) {
3010 3010
             return array();
3011 3011
         }
3012 3012
 
3013
-        $options    = array();
3014
-        foreach ( $items as $item ) {
3015
-            $title            = esc_html( $item->post_title );
3016
-            $title           .= wpinv_get_item_suffix( $item->ID, false );
3017
-            $id               = absint( $item->ID );
3018
-            $price            = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
3019
-            $recurring        = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
3013
+        $options = array();
3014
+        foreach ($items as $item) {
3015
+            $title            = esc_html($item->post_title);
3016
+            $title           .= wpinv_get_item_suffix($item->ID, false);
3017
+            $id               = absint($item->ID);
3018
+            $price            = wpinv_sanitize_amount(get_post_meta($id, '_wpinv_price', true));
3019
+            $recurring        = (bool) get_post_meta($id, '_wpinv_is_recurring', true);
3020 3020
             $description      = $item->post_excerpt;
3021
-            $custom_price     = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true );
3022
-            $minimum_price    = (float) get_post_meta( $id, '_minimum_price', true );
3021
+            $custom_price     = (bool) get_post_meta($id, '_wpinv_dynamic_pricing', true);
3022
+            $minimum_price    = (float) get_post_meta($id, '_minimum_price', true);
3023 3023
             $allow_quantities = false;
3024
-            $options[]        = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' );
3024
+            $options[]        = compact('title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities');
3025 3025
 
3026 3026
         }
3027 3027
         return $options;
@@ -3031,44 +3031,44 @@  discard block
 block discarded – undo
3031 3031
     /**
3032 3032
      * Returns an array of items for the currently being edited form.
3033 3033
      */
3034
-    public function get_form_items( $id = false ) {
3034
+    public function get_form_items($id = false) {
3035 3035
         
3036
-        if ( empty( $id ) ) {
3037
-            return wpinv_get_data( 'sample-payment-form-items' );
3036
+        if (empty($id)) {
3037
+            return wpinv_get_data('sample-payment-form-items');
3038 3038
         }
3039 3039
         
3040
-        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
3040
+        $form_elements = get_post_meta($id, 'wpinv_form_items', true);
3041 3041
 
3042
-        if ( is_array( $form_elements ) ) {
3042
+        if (is_array($form_elements)) {
3043 3043
             return $form_elements;
3044 3044
         }
3045 3045
 
3046
-        return wpinv_get_data( 'sample-payment-form-items' );
3046
+        return wpinv_get_data('sample-payment-form-items');
3047 3047
 
3048 3048
     }
3049 3049
 
3050 3050
     /**
3051 3051
      * Converts form items for use.
3052 3052
      */
3053
-    public function convert_checkout_items( $items, $invoice ) {
3053
+    public function convert_checkout_items($items, $invoice) {
3054 3054
 
3055 3055
         $converted = array();
3056
-        foreach ( $items as $item ) {
3056
+        foreach ($items as $item) {
3057 3057
 
3058 3058
             $item_id = $item['id'];
3059
-            $_item   = new WPInv_Item( $item_id );
3059
+            $_item   = new WPInv_Item($item_id);
3060 3060
 
3061
-            if( ! $_item ) {
3061
+            if (!$_item) {
3062 3062
                 continue;
3063 3063
             }
3064 3064
 
3065 3065
             $converted[] = array(
3066
-                'title'            => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ),
3066
+                'title'            => esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($_item),
3067 3067
                 'id'               => $item['id'],
3068 3068
                 'price'            => $item['subtotal'],
3069 3069
                 'custom_price'     => $_item->get_is_dynamic_pricing(),
3070 3070
                 'recurring'        => $_item->is_recurring(),
3071
-                'description'      => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ),
3071
+                'description'      => apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice),
3072 3072
                 'minimum_price'    => $_item->get_minimum_price(),
3073 3073
                 'allow_quantities' => false,
3074 3074
                 'quantity'         => $item['quantity'],
@@ -3082,27 +3082,27 @@  discard block
 block discarded – undo
3082 3082
     /**
3083 3083
      * Converts an array of id => quantity for use.
3084 3084
      */
3085
-    public function convert_normal_items( $items ) {
3085
+    public function convert_normal_items($items) {
3086 3086
 
3087 3087
         $converted = array();
3088
-        foreach ( $items as $item_id => $quantity ) {
3088
+        foreach ($items as $item_id => $quantity) {
3089 3089
 
3090
-            $item   = new WPInv_Item( $item_id );
3090
+            $item = new WPInv_Item($item_id);
3091 3091
 
3092
-            if( ! $item ) {
3092
+            if (!$item) {
3093 3093
                 continue;
3094 3094
             }
3095 3095
 
3096 3096
             $converted[] = array(
3097
-                'title'            => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ),
3097
+                'title'            => esc_html($item->get_name()) . wpinv_get_item_suffix($item),
3098 3098
                 'id'               => $item_id,
3099 3099
                 'price'            => $item->get_price(),
3100 3100
                 'custom_price'     => $item->get_is_dynamic_pricing(),
3101 3101
                 'recurring'        => $item->is_recurring(),
3102 3102
                 'description'      => $item->get_summary(),
3103 3103
                 'minimum_price'    => $item->get_minimum_price(),
3104
-                'allow_quantities' => ! empty( $quantity ),
3105
-                'quantity'         => empty( $quantity ) ? 1 : $quantity,
3104
+                'allow_quantities' => !empty($quantity),
3105
+                'quantity'         => empty($quantity) ? 1 : $quantity,
3106 3106
                 'required'         => true,
3107 3107
             );
3108 3108
 
@@ -3115,28 +3115,28 @@  discard block
 block discarded – undo
3115 3115
     /**
3116 3116
      * Returns an array of elements for the currently being edited form.
3117 3117
      */
3118
-    public function get_form_elements( $id = false ) {
3118
+    public function get_form_elements($id = false) {
3119 3119
 
3120
-        if ( empty( $id ) ) {
3121
-            return wpinv_get_data( 'sample-payment-form' );
3120
+        if (empty($id)) {
3121
+            return wpinv_get_data('sample-payment-form');
3122 3122
         }
3123 3123
         
3124
-        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
3124
+        $form_elements = get_post_meta($id, 'wpinv_form_elements', true);
3125 3125
 
3126
-        if ( is_array( $form_elements ) ) {
3126
+        if (is_array($form_elements)) {
3127 3127
             return $form_elements;
3128 3128
         }
3129 3129
 
3130
-        return wpinv_get_data( 'sample-payment-form' );
3130
+        return wpinv_get_data('sample-payment-form');
3131 3131
     }
3132 3132
 
3133 3133
     /**
3134 3134
      * Sends a redrect response to payment details.
3135 3135
      *
3136 3136
      */
3137
-    public function send_redirect_response( $url ) {
3138
-        $url = urlencode( $url );
3139
-        wp_send_json_success( $url );
3137
+    public function send_redirect_response($url) {
3138
+        $url = urlencode($url);
3139
+        wp_send_json_success($url);
3140 3140
     }
3141 3141
 
3142 3142
     /**
@@ -3147,12 +3147,12 @@  discard block
 block discarded – undo
3147 3147
 
3148 3148
         $errors = wpinv_get_errors();
3149 3149
 
3150
-        if ( ! empty( $errors ) ) {
3150
+        if (!empty($errors)) {
3151 3151
             wpinv_print_errors();
3152 3152
             exit;
3153 3153
         }
3154 3154
 
3155
-        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
3155
+        wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing'));
3156 3156
         exit;
3157 3157
 
3158 3158
     }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +472 added lines, -472 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -82,41 +82,41 @@  discard block
 block discarded – undo
82 82
             'buy_items' => true,
83 83
         );
84 84
 
85
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
86
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
87
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
85
+        foreach ($ajax_events as $ajax_event => $nopriv) {
86
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
87
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
88 88
             
89
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
90
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
89
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
90
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
91 91
             }
92 92
 
93
-            if ( $nopriv ) {
94
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
95
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
93
+            if ($nopriv) {
94
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
95
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
96 96
 
97
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
97
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
98 98
             }
99 99
         }
100 100
     }
101 101
     
102 102
     public static function add_note() {
103
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
103
+        check_ajax_referer('add-invoice-note', '_nonce');
104 104
 
105
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
105
+        if (!wpinv_current_user_can_manage_invoicing()) {
106 106
             die(-1);
107 107
         }
108 108
 
109
-        $post_id   = absint( $_POST['post_id'] );
110
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
111
-        $note_type = sanitize_text_field( $_POST['note_type'] );
109
+        $post_id   = absint($_POST['post_id']);
110
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
111
+        $note_type = sanitize_text_field($_POST['note_type']);
112 112
 
113 113
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
114 114
 
115
-        if ( $post_id > 0 ) {
116
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
115
+        if ($post_id > 0) {
116
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
117 117
 
118
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
119
-                wpinv_get_invoice_note_line_item( $note_id );
118
+            if ($note_id > 0 && !is_wp_error($note_id)) {
119
+                wpinv_get_invoice_note_line_item($note_id);
120 120
             }
121 121
         }
122 122
 
@@ -124,16 +124,16 @@  discard block
 block discarded – undo
124 124
     }
125 125
 
126 126
     public static function delete_note() {
127
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
127
+        check_ajax_referer('delete-invoice-note', '_nonce');
128 128
 
129
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
129
+        if (!wpinv_current_user_can_manage_invoicing()) {
130 130
             die(-1);
131 131
         }
132 132
 
133
-        $note_id = (int)$_POST['note_id'];
133
+        $note_id = (int) $_POST['note_id'];
134 134
 
135
-        if ( $note_id > 0 ) {
136
-            wp_delete_comment( $note_id, true );
135
+        if ($note_id > 0) {
136
+            wp_delete_comment($note_id, true);
137 137
         }
138 138
 
139 139
         die();
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
     }
147 147
     
148 148
     public static function checkout() {
149
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
150
-            define( 'WPINV_CHECKOUT', true );
149
+        if (!defined('WPINV_CHECKOUT')) {
150
+            define('WPINV_CHECKOUT', true);
151 151
         }
152 152
 
153 153
         wpinv_process_checkout();
@@ -156,53 +156,53 @@  discard block
 block discarded – undo
156 156
     
157 157
     public static function add_invoice_item() {
158 158
         global $wpi_userID, $wpinv_ip_address_country;
159
-        check_ajax_referer( 'invoice-item', '_nonce' );
160
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
159
+        check_ajax_referer('invoice-item', '_nonce');
160
+        if (!wpinv_current_user_can_manage_invoicing()) {
161 161
             die(-1);
162 162
         }
163 163
         
164
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
165
-        $invoice_id = absint( $_POST['invoice_id'] );
164
+        $item_id    = sanitize_text_field($_POST['item_id']);
165
+        $invoice_id = absint($_POST['invoice_id']);
166 166
         
167
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
167
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
168 168
             die();
169 169
         }
170 170
         
171
-        $invoice    = wpinv_get_invoice( $invoice_id );
172
-        if ( empty( $invoice ) ) {
171
+        $invoice = wpinv_get_invoice($invoice_id);
172
+        if (empty($invoice)) {
173 173
             die();
174 174
         }
175 175
         
176
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
176
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
177 177
             die(); // Don't allow modify items for paid invoice.
178 178
         }
179 179
         
180
-        if ( !empty( $_POST['user_id'] ) ) {
181
-            $wpi_userID = absint( $_POST['user_id'] ); 
180
+        if (!empty($_POST['user_id'])) {
181
+            $wpi_userID = absint($_POST['user_id']); 
182 182
         }
183 183
 
184
-        $item = new WPInv_Item( $item_id );
185
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
184
+        $item = new WPInv_Item($item_id);
185
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
186 186
             die();
187 187
         }
188 188
         
189 189
         // Validate item before adding to invoice because recurring item must be paid individually.
190
-        if ( !empty( $invoice->cart_details ) ) {
190
+        if (!empty($invoice->cart_details)) {
191 191
             $valid = true;
192 192
             
193
-            if ( $recurring_item = $invoice->get_recurring() ) {
194
-                if ( $recurring_item != $item_id ) {
193
+            if ($recurring_item = $invoice->get_recurring()) {
194
+                if ($recurring_item != $item_id) {
195 195
                     $valid = false;
196 196
                 }
197
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
197
+            } else if (wpinv_is_recurring_item($item_id)) {
198 198
                 $valid = false;
199 199
             }
200 200
             
201
-            if ( !$valid ) {
201
+            if (!$valid) {
202 202
                 $response               = array();
203 203
                 $response['success']    = false;
204
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
205
-                wp_send_json( $response );
204
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
205
+                wp_send_json($response);
206 206
             }
207 207
         }
208 208
         
@@ -210,11 +210,11 @@  discard block
 block discarded – undo
210 210
         
211 211
         $data                   = array();
212 212
         $data['invoice_id']     = $invoice_id;
213
-        $data['cart_discounts'] = $invoice->get_discounts( true );
213
+        $data['cart_discounts'] = $invoice->get_discounts(true);
214 214
         
215
-        wpinv_set_checkout_session( $data );
215
+        wpinv_set_checkout_session($data);
216 216
         
217
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
217
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
218 218
 
219 219
         $args = array(
220 220
             'id'            => $item_id,
@@ -227,21 +227,21 @@  discard block
 block discarded – undo
227 227
             'fees'          => array()
228 228
         );
229 229
 
230
-        $invoice->add_item( $item_id, $args );
230
+        $invoice->add_item($item_id, $args);
231 231
         $invoice->save();
232 232
         
233
-        if ( empty( $_POST['country'] ) ) {
233
+        if (empty($_POST['country'])) {
234 234
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
235 235
         }
236
-        if ( empty( $_POST['state'] ) ) {
236
+        if (empty($_POST['state'])) {
237 237
             $_POST['state'] = $invoice->state;
238 238
         }
239 239
          
240
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
241
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
240
+        $invoice->country   = sanitize_text_field($_POST['country']);
241
+        $invoice->state     = sanitize_text_field($_POST['state']);
242 242
         
243
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
244
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
243
+        $invoice->set('country', sanitize_text_field($_POST['country']));
244
+        $invoice->set('state', sanitize_text_field($_POST['state']));
245 245
         
246 246
         $wpinv_ip_address_country = $invoice->country;
247 247
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         
250 250
         $response                       = array();
251 251
         $response['success']            = true;
252
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
252
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
253 253
         $response['data']['subtotal']   = $invoice->get_subtotal();
254 254
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
255 255
         $response['data']['tax']        = $invoice->get_tax();
@@ -261,41 +261,41 @@  discard block
 block discarded – undo
261 261
         
262 262
         wpinv_set_checkout_session($checkout_session);
263 263
         
264
-        wp_send_json( $response );
264
+        wp_send_json($response);
265 265
     }
266 266
 
267 267
 
268 268
     public static function remove_invoice_item() {
269 269
         global $wpi_userID, $wpinv_ip_address_country;
270 270
         
271
-        check_ajax_referer( 'invoice-item', '_nonce' );
272
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
271
+        check_ajax_referer('invoice-item', '_nonce');
272
+        if (!wpinv_current_user_can_manage_invoicing()) {
273 273
             die(-1);
274 274
         }
275 275
         
276
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
277
-        $invoice_id = absint( $_POST['invoice_id'] );
278
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
276
+        $item_id    = sanitize_text_field($_POST['item_id']);
277
+        $invoice_id = absint($_POST['invoice_id']);
278
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
279 279
         
280
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
280
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
281 281
             die();
282 282
         }
283 283
 
284
-        $invoice    = wpinv_get_invoice( $invoice_id );
285
-        if ( empty( $invoice ) ) {
284
+        $invoice = wpinv_get_invoice($invoice_id);
285
+        if (empty($invoice)) {
286 286
             die();
287 287
         }
288 288
         
289
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
289
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
290 290
             die(); // Don't allow modify items for paid invoice.
291 291
         }
292 292
         
293
-        if ( !empty( $_POST['user_id'] ) ) {
294
-            $wpi_userID = absint( $_POST['user_id'] ); 
293
+        if (!empty($_POST['user_id'])) {
294
+            $wpi_userID = absint($_POST['user_id']); 
295 295
         }
296 296
 
297
-        $item       = new WPInv_Item( $item_id );
298
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
297
+        $item = new WPInv_Item($item_id);
298
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
299 299
             die();
300 300
         }
301 301
         
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
         
304 304
         $data                   = array();
305 305
         $data['invoice_id']     = $invoice_id;
306
-        $data['cart_discounts'] = $invoice->get_discounts( true );
306
+        $data['cart_discounts'] = $invoice->get_discounts(true);
307 307
         
308
-        wpinv_set_checkout_session( $data );
308
+        wpinv_set_checkout_session($data);
309 309
 
310 310
         $args = array(
311 311
             'id'         => $item_id,
@@ -313,21 +313,21 @@  discard block
 block discarded – undo
313 313
             'cart_index' => $cart_index
314 314
         );
315 315
 
316
-        $invoice->remove_item( $item_id, $args );
316
+        $invoice->remove_item($item_id, $args);
317 317
         $invoice->save();
318 318
         
319
-        if ( empty( $_POST['country'] ) ) {
319
+        if (empty($_POST['country'])) {
320 320
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
321 321
         }
322
-        if ( empty( $_POST['state'] ) ) {
322
+        if (empty($_POST['state'])) {
323 323
             $_POST['state'] = $invoice->state;
324 324
         }
325 325
          
326
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
327
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
326
+        $invoice->country   = sanitize_text_field($_POST['country']);
327
+        $invoice->state     = sanitize_text_field($_POST['state']);
328 328
         
329
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
330
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
329
+        $invoice->set('country', sanitize_text_field($_POST['country']));
330
+        $invoice->set('state', sanitize_text_field($_POST['state']));
331 331
         
332 332
         $wpinv_ip_address_country = $invoice->country;
333 333
         
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
         
336 336
         $response                       = array();
337 337
         $response['success']            = true;
338
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
338
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
339 339
         $response['data']['subtotal']   = $invoice->get_subtotal();
340 340
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
341 341
         $response['data']['tax']        = $invoice->get_tax();
@@ -347,55 +347,55 @@  discard block
 block discarded – undo
347 347
         
348 348
         wpinv_set_checkout_session($checkout_session);
349 349
         
350
-        wp_send_json( $response );
350
+        wp_send_json($response);
351 351
     }
352 352
     
353 353
     public static function create_invoice_item() {
354
-        check_ajax_referer( 'invoice-item', '_nonce' );
355
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
354
+        check_ajax_referer('invoice-item', '_nonce');
355
+        if (!wpinv_current_user_can_manage_invoicing()) {
356 356
             die(-1);
357 357
         }
358 358
         
359
-        $invoice_id = absint( $_POST['invoice_id'] );
359
+        $invoice_id = absint($_POST['invoice_id']);
360 360
 
361 361
         // Find the item
362
-        if ( !is_numeric( $invoice_id ) ) {
362
+        if (!is_numeric($invoice_id)) {
363 363
             die();
364 364
         }        
365 365
         
366
-        $invoice     = wpinv_get_invoice( $invoice_id );
367
-        if ( empty( $invoice ) ) {
366
+        $invoice = wpinv_get_invoice($invoice_id);
367
+        if (empty($invoice)) {
368 368
             die();
369 369
         }
370 370
         
371 371
         // Validate item before adding to invoice because recurring item must be paid individually.
372
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
372
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
373 373
             $response               = array();
374 374
             $response['success']    = false;
375
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
376
-            wp_send_json( $response );
375
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
376
+            wp_send_json($response);
377 377
         }        
378 378
         
379
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
379
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
380 380
         
381 381
         $meta               = array();
382 382
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
383
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
383
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
384 384
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
385 385
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
386 386
         
387 387
         $data                   = array();
388 388
         $data['post_title']     = sanitize_text_field($save_item['name']);
389 389
         $data['post_status']    = 'publish';
390
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
390
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
391 391
         $data['meta']           = $meta;
392 392
         
393 393
         $item = new WPInv_Item();
394
-        $item->create( $data );
394
+        $item->create($data);
395 395
         
396
-        if ( !empty( $item ) ) {
396
+        if (!empty($item)) {
397 397
             $_POST['item_id']   = $item->ID;
398
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
398
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
399 399
             
400 400
             self::add_invoice_item();
401 401
         }
@@ -403,15 +403,15 @@  discard block
 block discarded – undo
403 403
     }
404 404
     
405 405
     public static function get_billing_details() {
406
-        check_ajax_referer( 'get-billing-details', '_nonce' );
406
+        check_ajax_referer('get-billing-details', '_nonce');
407 407
         
408
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
408
+        if (!wpinv_current_user_can_manage_invoicing()) {
409 409
             die(-1);
410 410
         }
411 411
 
412
-        $user_id            = (int)$_POST['user_id'];
412
+        $user_id            = (int) $_POST['user_id'];
413 413
         $billing_details    = wpinv_get_user_address($user_id);
414
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
414
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
415 415
         
416 416
         if (isset($billing_details['user_id'])) {
417 417
             unset($billing_details['user_id']);
@@ -425,20 +425,20 @@  discard block
 block discarded – undo
425 425
         $response['success']                    = true;
426 426
         $response['data']['billing_details']    = $billing_details;
427 427
         
428
-        wp_send_json( $response );
428
+        wp_send_json($response);
429 429
     }
430 430
     
431 431
     public static function admin_recalculate_totals() {
432 432
         global $wpi_userID, $wpinv_ip_address_country;
433 433
         
434
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
435
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
434
+        check_ajax_referer('wpinv-nonce', '_nonce');
435
+        if (!wpinv_current_user_can_manage_invoicing()) {
436 436
             die(-1);
437 437
         }
438 438
         
439
-        $invoice_id = absint( $_POST['invoice_id'] );        
440
-        $invoice    = wpinv_get_invoice( $invoice_id );
441
-        if ( empty( $invoice ) ) {
439
+        $invoice_id = absint($_POST['invoice_id']);        
440
+        $invoice    = wpinv_get_invoice($invoice_id);
441
+        if (empty($invoice)) {
442 442
             die();
443 443
         }
444 444
 
@@ -446,29 +446,29 @@  discard block
 block discarded – undo
446 446
 
447 447
         $data                   = array();
448 448
         $data['invoice_id']     = $invoice_id;
449
-        $data['cart_discounts'] = $invoice->get_discounts( true );
449
+        $data['cart_discounts'] = $invoice->get_discounts(true);
450 450
 
451
-        wpinv_set_checkout_session( $data );
451
+        wpinv_set_checkout_session($data);
452 452
         
453
-        if ( !empty( $_POST['user_id'] ) ) {
454
-            $wpi_userID = absint( $_POST['user_id'] ); 
453
+        if (!empty($_POST['user_id'])) {
454
+            $wpi_userID = absint($_POST['user_id']); 
455 455
         }
456 456
         
457
-        if ( empty( $_POST['country'] ) ) {
457
+        if (empty($_POST['country'])) {
458 458
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
459 459
         }
460 460
 
461 461
         $disable_taxes = 0;
462
-        if ( ! empty( $_POST['disable_taxes'] ) ) {
462
+        if (!empty($_POST['disable_taxes'])) {
463 463
             $disable_taxes = 1;
464 464
         }
465
-        $invoice->set( 'disable_taxes', $disable_taxes );
465
+        $invoice->set('disable_taxes', $disable_taxes);
466 466
 
467
-        $invoice->country = sanitize_text_field( $_POST['country'] );
468
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
469
-        if ( isset( $_POST['state'] ) ) {
470
-            $invoice->state = sanitize_text_field( $_POST['state'] );
471
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
467
+        $invoice->country = sanitize_text_field($_POST['country']);
468
+        $invoice->set('country', sanitize_text_field($_POST['country']));
469
+        if (isset($_POST['state'])) {
470
+            $invoice->state = sanitize_text_field($_POST['state']);
471
+            $invoice->set('state', sanitize_text_field($_POST['state']));
472 472
         }
473 473
         
474 474
         $wpinv_ip_address_country = $invoice->country;
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
         
478 478
         $response                       = array();
479 479
         $response['success']            = true;
480
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
480
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
481 481
         $response['data']['subtotal']   = $invoice->get_subtotal();
482 482
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
483 483
         $response['data']['tax']        = $invoice->get_tax();
@@ -489,25 +489,25 @@  discard block
 block discarded – undo
489 489
         
490 490
         wpinv_set_checkout_session($checkout_session);
491 491
 
492
-        wp_send_json( $response );
492
+        wp_send_json($response);
493 493
     }
494 494
     
495 495
     public static function admin_apply_discount() {
496 496
         global $wpi_userID;
497 497
         
498
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
499
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
498
+        check_ajax_referer('wpinv-nonce', '_nonce');
499
+        if (!wpinv_current_user_can_manage_invoicing()) {
500 500
             die(-1);
501 501
         }
502 502
         
503
-        $invoice_id = absint( $_POST['invoice_id'] );
504
-        $discount_code = sanitize_text_field( $_POST['code'] );
505
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
503
+        $invoice_id = absint($_POST['invoice_id']);
504
+        $discount_code = sanitize_text_field($_POST['code']);
505
+        if (empty($invoice_id) || empty($discount_code)) {
506 506
             die();
507 507
         }
508 508
         
509
-        $invoice = wpinv_get_invoice( $invoice_id );
510
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
509
+        $invoice = wpinv_get_invoice($invoice_id);
510
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
511 511
             die();
512 512
         }
513 513
         
@@ -515,49 +515,49 @@  discard block
 block discarded – undo
515 515
         
516 516
         $data                   = array();
517 517
         $data['invoice_id']     = $invoice_id;
518
-        $data['cart_discounts'] = $invoice->get_discounts( true );
518
+        $data['cart_discounts'] = $invoice->get_discounts(true);
519 519
         
520
-        wpinv_set_checkout_session( $data );
520
+        wpinv_set_checkout_session($data);
521 521
         
522 522
         $response               = array();
523 523
         $response['success']    = false;
524
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
524
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
525 525
         $response['data']['code'] = $discount_code;
526 526
         
527
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
528
-            $discounts = wpinv_set_cart_discount( $discount_code );
527
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
528
+            $discounts = wpinv_set_cart_discount($discount_code);
529 529
             
530 530
             $response['success'] = true;
531
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
532
-        }  else {
531
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
532
+        } else {
533 533
             $errors = wpinv_get_errors();
534
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
534
+            if (!empty($errors['wpinv-discount-error'])) {
535 535
                 $response['msg'] = $errors['wpinv-discount-error'];
536 536
             }
537
-            wpinv_unset_error( 'wpinv-discount-error' );
537
+            wpinv_unset_error('wpinv-discount-error');
538 538
         }
539 539
         
540 540
         wpinv_set_checkout_session($checkout_session);
541 541
         
542
-        wp_send_json( $response );
542
+        wp_send_json($response);
543 543
     }
544 544
     
545 545
     public static function admin_remove_discount() {
546 546
         global $wpi_userID;
547 547
         
548
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
549
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
548
+        check_ajax_referer('wpinv-nonce', '_nonce');
549
+        if (!wpinv_current_user_can_manage_invoicing()) {
550 550
             die(-1);
551 551
         }
552 552
         
553
-        $invoice_id = absint( $_POST['invoice_id'] );
554
-        $discount_code = sanitize_text_field( $_POST['code'] );
555
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
553
+        $invoice_id = absint($_POST['invoice_id']);
554
+        $discount_code = sanitize_text_field($_POST['code']);
555
+        if (empty($invoice_id) || empty($discount_code)) {
556 556
             die();
557 557
         }
558 558
         
559
-        $invoice = wpinv_get_invoice( $invoice_id );
560
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
559
+        $invoice = wpinv_get_invoice($invoice_id);
560
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
561 561
             die();
562 562
         }
563 563
         
@@ -565,38 +565,38 @@  discard block
 block discarded – undo
565 565
         
566 566
         $data                   = array();
567 567
         $data['invoice_id']     = $invoice_id;
568
-        $data['cart_discounts'] = $invoice->get_discounts( true );
568
+        $data['cart_discounts'] = $invoice->get_discounts(true);
569 569
         
570
-        wpinv_set_checkout_session( $data );
570
+        wpinv_set_checkout_session($data);
571 571
         
572 572
         $response               = array();
573 573
         $response['success']    = false;
574 574
         $response['msg']        = NULL;
575 575
         
576
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
576
+        $discounts = wpinv_unset_cart_discount($discount_code);
577 577
         $response['success'] = true;
578
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
578
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
579 579
         
580 580
         wpinv_set_checkout_session($checkout_session);
581 581
         
582
-        wp_send_json( $response );
582
+        wp_send_json($response);
583 583
     }
584 584
     
585 585
     public static function check_email() {
586
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
587
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
586
+        check_ajax_referer('wpinv-nonce', '_nonce');
587
+        if (!wpinv_current_user_can_manage_invoicing()) {
588 588
             die(-1);
589 589
         }
590 590
         
591
-        $email = sanitize_text_field( $_POST['email'] );
591
+        $email = sanitize_text_field($_POST['email']);
592 592
         
593 593
         $response = array();
594
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
594
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
595 595
             $user_id            = $user_data->ID;
596 596
             $user_login         = $user_data->user_login;
597 597
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
598 598
             $billing_details    = wpinv_get_user_address($user_id);
599
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
599
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
600 600
             
601 601
             if (isset($billing_details['user_id'])) {
602 602
                 unset($billing_details['user_id']);
@@ -612,54 +612,54 @@  discard block
 block discarded – undo
612 612
             $response['data']['billing_details']    = $billing_details;
613 613
         }
614 614
         
615
-        wp_send_json( $response );
615
+        wp_send_json($response);
616 616
     }
617 617
     
618 618
     public static function run_tool() {
619
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
620
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
619
+        check_ajax_referer('wpinv-nonce', '_nonce');
620
+        if (!wpinv_current_user_can_manage_invoicing()) {
621 621
             die(-1);
622 622
         }
623 623
         
624
-        $tool = sanitize_text_field( $_POST['tool'] );
624
+        $tool = sanitize_text_field($_POST['tool']);
625 625
         
626
-        do_action( 'wpinv_run_tool' );
626
+        do_action('wpinv_run_tool');
627 627
         
628
-        if ( !empty( $tool ) ) {
629
-            do_action( 'wpinv_tool_' . $tool );
628
+        if (!empty($tool)) {
629
+            do_action('wpinv_tool_' . $tool);
630 630
         }
631 631
     }
632 632
     
633 633
     public static function apply_discount() {
634 634
         global $wpi_userID;
635 635
         
636
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
636
+        check_ajax_referer('wpinv-nonce', '_nonce');
637 637
         
638 638
         $response = array();
639 639
         
640
-        if ( isset( $_POST['code'] ) ) {
641
-            $discount_code = sanitize_text_field( $_POST['code'] );
640
+        if (isset($_POST['code'])) {
641
+            $discount_code = sanitize_text_field($_POST['code']);
642 642
 
643 643
             $response['success']        = false;
644 644
             $response['msg']            = '';
645 645
             $response['data']['code']   = $discount_code;
646 646
             
647 647
             $invoice = wpinv_get_invoice_cart();
648
-            if ( empty( $invoice->ID ) ) {
649
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
650
-                wp_send_json( $response );
648
+            if (empty($invoice->ID)) {
649
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
650
+                wp_send_json($response);
651 651
             }
652 652
 
653 653
             $wpi_userID = $invoice->get_user_id();
654 654
 
655
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
656
-                $discount       = wpinv_get_discount_by_code( $discount_code );
657
-                $discounts      = wpinv_set_cart_discount( $discount_code );
658
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
659
-                $total          = wpinv_get_cart_total( null, $discounts );
660
-                $cart_totals    = wpinv_recalculate_tax( true );
655
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
656
+                $discount       = wpinv_get_discount_by_code($discount_code);
657
+                $discounts      = wpinv_set_cart_discount($discount_code);
658
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
659
+                $total          = wpinv_get_cart_total(null, $discounts);
660
+                $cart_totals    = wpinv_recalculate_tax(true);
661 661
             
662
-                if ( !empty( $cart_totals ) ) {
662
+                if (!empty($cart_totals)) {
663 663
                     $response['success']        = true;
664 664
                     $response['data']           = $cart_totals;
665 665
                     $response['data']['code']   = $discount_code;
@@ -668,29 +668,29 @@  discard block
 block discarded – undo
668 668
                 }
669 669
             } else {
670 670
                 $errors = wpinv_get_errors();
671
-                $response['msg']  = $errors['wpinv-discount-error'];
672
-                wpinv_unset_error( 'wpinv-discount-error' );
671
+                $response['msg'] = $errors['wpinv-discount-error'];
672
+                wpinv_unset_error('wpinv-discount-error');
673 673
             }
674 674
 
675 675
             // Allow for custom discount code handling
676
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
676
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
677 677
         }
678 678
         
679
-        wp_send_json( $response );
679
+        wp_send_json($response);
680 680
     }
681 681
     
682 682
     public static function remove_discount() {
683
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
683
+        check_ajax_referer('wpinv-nonce', '_nonce');
684 684
         
685 685
         $response = array();
686 686
         
687
-        if ( isset( $_POST['code'] ) ) {
688
-            $discount_code  = sanitize_text_field( $_POST['code'] );
689
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
690
-            $total          = wpinv_get_cart_total( null, $discounts );
691
-            $cart_totals    = wpinv_recalculate_tax( true );
687
+        if (isset($_POST['code'])) {
688
+            $discount_code  = sanitize_text_field($_POST['code']);
689
+            $discounts      = wpinv_unset_cart_discount($discount_code);
690
+            $total          = wpinv_get_cart_total(null, $discounts);
691
+            $cart_totals    = wpinv_recalculate_tax(true);
692 692
             
693
-            if ( !empty( $cart_totals ) ) {
693
+            if (!empty($cart_totals)) {
694 694
                 $response['success']        = true;
695 695
                 $response['data']           = $cart_totals;
696 696
                 $response['data']['code']   = $discount_code;
@@ -699,10 +699,10 @@  discard block
 block discarded – undo
699 699
             }
700 700
             
701 701
             // Allow for custom discount code handling
702
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
702
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
703 703
         }
704 704
         
705
-        wp_send_json( $response );
705
+        wp_send_json($response);
706 706
     }
707 707
 
708 708
     /**
@@ -711,30 +711,30 @@  discard block
 block discarded – undo
711 711
     public static function get_payment_form() {
712 712
 
713 713
         // Check nonce.
714
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
715
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
714
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
715
+            _e('Error: Reload the page and try again.', 'invoicing');
716 716
             exit;
717 717
         }
718 718
 
719 719
         // Is the request set up correctly?
720
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
720
+		if (empty($_GET['form']) && empty($_GET['item'])) {
721 721
 			echo aui()->alert(
722 722
 				array(
723 723
 					'type'    => 'warning',
724
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
724
+					'content' => __('No payment form or item provided', 'invoicing'),
725 725
 				)
726 726
             );
727 727
             exit;
728 728
         }
729 729
 
730 730
         // Payment form or button?
731
-		if ( ! empty( $_GET['form'] ) ) {
732
-            echo getpaid_display_payment_form( $_GET['form'] );
733
-		} else if( $_GET['invoice'] ) {
734
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
731
+		if (!empty($_GET['form'])) {
732
+            echo getpaid_display_payment_form($_GET['form']);
733
+		} else if ($_GET['invoice']) {
734
+		    echo getpaid_display_invoice_payment_form($_GET['invoice']);
735 735
         } else {
736
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
737
-		    echo getpaid_display_item_payment_form( $items );
736
+			$items = getpaid_convert_items_to_array($_GET['item']);
737
+		    echo getpaid_display_item_payment_form($items);
738 738
         }
739 739
         
740 740
         exit;
@@ -750,72 +750,72 @@  discard block
 block discarded – undo
750 750
         global $invoicing, $wpi_checkout_id, $cart_total;
751 751
 
752 752
         // Check nonce.
753
-        if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) {
754
-            wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) );
753
+        if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) {
754
+            wp_send_json_error(__('Security checks failed.', 'invoicing'));
755 755
         }
756 756
 
757 757
         // Prepare submitted data...
758
-        $data = wp_unslash( $_POST );
758
+        $data = wp_unslash($_POST);
759 759
 
760 760
         // ... form fields...
761
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
762
-            wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) );
761
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
762
+            wp_send_json_error(__('This payment form is no longer active.', 'invoicing'));
763 763
         }
764 764
 
765
-        if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) {
766
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
765
+        if (empty($data['billing_email']) || !is_email($data['billing_email'])) {
766
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
767 767
         }
768 768
 
769 769
         $prepared = array(
770
-            'billing_email'                    => sanitize_email( $data['billing_email'] ),
771
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ),
772
-            __( 'Form Id', 'invoicing' )       => absint( $data['form_id'] ),
770
+            'billing_email'                    => sanitize_email($data['billing_email']),
771
+            __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']),
772
+            __('Form Id', 'invoicing')       => absint($data['form_id']),
773 773
         );
774 774
 
775 775
         // Do we have a discount?
776 776
         $discount = 0;
777
-        if ( ! empty( $data['discount'] ) ) {
777
+        if (!empty($data['discount'])) {
778 778
 
779 779
             // Validate discount.
780
-            $discount = self::payment_form_validate_discount( $data );
780
+            $discount = self::payment_form_validate_discount($data);
781 781
 
782
-            if ( is_string( $discount ) ){
783
-                wp_send_json_error( $discount );
782
+            if (is_string($discount)) {
783
+                wp_send_json_error($discount);
784 784
             }
785 785
 
786
-            if ( is_array( $discount ) ){
787
-                $discount = $discount[ 'discount' ];
786
+            if (is_array($discount)) {
787
+                $discount = $discount['discount'];
788 788
             }
789 789
 
790
-            if ( ! $discount ) {
790
+            if (!$discount) {
791 791
                 $discount = 0;
792 792
             }
793 793
 
794 794
         }
795 795
 
796
-        $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] );
796
+        $fields = $invoicing->form_elements->get_form_elements($data['form_id']);
797 797
 
798 798
         // ... and form items.
799
-        if ( ! empty( $data['invoice_id'] ) ) {
800
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
799
+        if (!empty($data['invoice_id'])) {
800
+            $invoice = wpinv_get_invoice($data['invoice_id']);
801 801
 
802
-            if ( empty( $invoice ) ) {
803
-                wp_send_json_error( __( 'Invalid invoice.', 'invoicing' ) );
802
+            if (empty($invoice)) {
803
+                wp_send_json_error(__('Invalid invoice.', 'invoicing'));
804 804
             }
805 805
 
806
-            if ( $invoice->is_paid() ) {
807
-                wp_send_json_error( __( 'This invoice has already been paid.', 'invoicing' ) );
806
+            if ($invoice->is_paid()) {
807
+                wp_send_json_error(__('This invoice has already been paid.', 'invoicing'));
808 808
             }
809 809
 
810
-            $items   = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
810
+            $items = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
811 811
 
812 812
         } else {
813 813
 
814
-            if ( isset( $data['form_items'] ) ) {
815
-                $items = getpaid_convert_items_to_array( $data['form_items'] );
816
-                $items = $invoicing->form_elements->convert_normal_items( $items );
814
+            if (isset($data['form_items'])) {
815
+                $items = getpaid_convert_items_to_array($data['form_items']);
816
+                $items = $invoicing->form_elements->convert_normal_items($items);
817 817
             } else {
818
-                $items = $invoicing->form_elements->get_form_items( $data['form_id'] );
818
+                $items = $invoicing->form_elements->get_form_items($data['form_id']);
819 819
             }
820 820
 
821 821
             $invoice = 0;
@@ -824,44 +824,44 @@  discard block
 block discarded – undo
824 824
         $prepared_items = array();
825 825
         $address_fields = array();
826 826
 
827
-        if ( ! empty( $data['wpinv-items'] ) ) {
827
+        if (!empty($data['wpinv-items'])) {
828 828
 
829
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
829
+            $selected_items = wpinv_clean($data['wpinv-items']);
830 830
 
831
-            foreach ( $items as $item ) {
831
+            foreach ($items as $item) {
832 832
 
833
-                if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) {
834
-                    wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) );
833
+                if (!empty($item['required']) && !isset($selected_items[$item['id']])) {
834
+                    wp_send_json_error(__('A required item is missing.', 'invoicing'));
835 835
                 }
836 836
 
837
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
837
+                if (!isset($selected_items[$item['id']])) {
838 838
                     continue;
839 839
                 }
840 840
 
841
-                $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] );
841
+                $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']);
842 842
 
843
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
843
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
844 844
 
845
-                    $_quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
845
+                    $_quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
846 846
 
847
-                    if ( ! empty( $_quantity ) ) {
847
+                    if (!empty($_quantity)) {
848 848
                         $quantity = $_quantity;
849 849
                     }
850 850
                 }
851 851
 
852 852
                 // Custom pricing.
853
-                if ( ! empty( $item['custom_price'] ) ) {
853
+                if (!empty($item['custom_price'])) {
854 854
 
855
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
856
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
855
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
856
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
857 857
 
858
-                    if ( $set_price < $minimum_price ) {
859
-                        wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) );
858
+                    if ($set_price < $minimum_price) {
859
+                        wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing'));
860 860
                     }
861 861
 
862 862
                     $prepared_items[] = array(
863 863
                         'id'           =>$item['id'],
864
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
864
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
865 865
                         'custom_price' => $set_price,
866 866
                         'name'         => $item['title'],
867 867
                         'quantity'     => $quantity,
@@ -871,8 +871,8 @@  discard block
 block discarded – undo
871 871
 
872 872
                     $prepared_items[] = array(
873 873
                         'id'           => $item['id'],
874
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
875
-                        'custom_price' => wpinv_sanitize_amount( $item['price'] ),
874
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
875
+                        'custom_price' => wpinv_sanitize_amount($item['price']),
876 876
                         'name'         => $item['title'],
877 877
                         'quantity'     => $quantity,
878 878
                     );
@@ -883,72 +883,72 @@  discard block
 block discarded – undo
883 883
 
884 884
         } else {
885 885
 
886
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
886
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
887 887
 
888 888
         }
889 889
 
890 890
         // Are all required fields provided?
891
-        foreach ( $fields as $field ) {
891
+        foreach ($fields as $field) {
892 892
 
893
-            if ( ! empty( $field['premade'] ) ) {
893
+            if (!empty($field['premade'])) {
894 894
                 continue;
895 895
             }
896 896
 
897
-            if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) {
898
-                wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
897
+            if (!empty($field['required']) && empty($data[$field['id']])) {
898
+                wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
899 899
             }
900 900
 
901
-            if ( $field['type'] == 'address' ) {
901
+            if ($field['type'] == 'address') {
902 902
 
903
-                foreach ( $field['fields'] as $address_field ) {
903
+                foreach ($field['fields'] as $address_field) {
904 904
 
905
-                    if ( empty( $address_field['visible'] ) ) {
905
+                    if (empty($address_field['visible'])) {
906 906
                         continue;
907 907
                     }
908 908
 
909
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
910
-                        wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
909
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
910
+                        wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
911 911
                     }
912 912
 
913
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
914
-                        $label = str_replace( 'wpinv_', '', $address_field['name'] );
915
-                        $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] );
913
+                    if (isset($data[$address_field['name']])) {
914
+                        $label = str_replace('wpinv_', '', $address_field['name']);
915
+                        $address_fields[$label] = wpinv_clean($data[$address_field['name']]);
916 916
                     }
917 917
 
918 918
                 }
919 919
 
920
-            } else if ( isset( $data[ $field['id'] ] ) ) {
920
+            } else if (isset($data[$field['id']])) {
921 921
                 $label = $field['id'];
922 922
 
923
-                if ( isset( $field['label'] ) ) {
923
+                if (isset($field['label'])) {
924 924
                     $label = $field['label'];
925 925
                 }
926 926
 
927
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
927
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
928 928
             }
929 929
 
930 930
         }
931 931
 
932
-        $user = get_user_by( 'email', $prepared['billing_email'] );
932
+        $user = get_user_by('email', $prepared['billing_email']);
933 933
 
934
-        if ( empty( $user ) ) {
935
-            $user = wpinv_create_user( $prepared['billing_email'] );
934
+        if (empty($user)) {
935
+            $user = wpinv_create_user($prepared['billing_email']);
936 936
         }
937 937
 
938
-        if ( is_wp_error( $user ) ) {
939
-            wp_send_json_error( $user->get_error_message() );
938
+        if (is_wp_error($user)) {
939
+            wp_send_json_error($user->get_error_message());
940 940
         }
941 941
 
942
-        if ( is_numeric( $user ) ) {
943
-            $user = get_user_by( 'id', $user );
942
+        if (is_numeric($user)) {
943
+            $user = get_user_by('id', $user);
944 944
         }
945 945
 
946
-        if ( $discount ) {
947
-            $address_fields['discount'] = array( $data['discount'] );
946
+        if ($discount) {
947
+            $address_fields['discount'] = array($data['discount']);
948 948
         }
949 949
 
950 950
         // Create the invoice.
951
-        if ( empty( $invoice ) ) {
951
+        if (empty($invoice)) {
952 952
 
953 953
             $invoice = wpinv_insert_invoice(
954 954
                 array(
@@ -976,34 +976,34 @@  discard block
 block discarded – undo
976 976
         }
977 977
         
978 978
 
979
-        if ( is_wp_error( $invoice ) ) {
980
-            wp_send_json_error( $invoice->get_error_message() );
979
+        if (is_wp_error($invoice)) {
980
+            wp_send_json_error($invoice->get_error_message());
981 981
         }
982 982
 
983
-        if ( empty( $invoice ) ) {
984
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
983
+        if (empty($invoice)) {
984
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
985 985
         }
986 986
 
987
-        unset( $prepared['billing_email'] );
988
-        update_post_meta( $invoice->ID, 'payment_form_data', $prepared );
987
+        unset($prepared['billing_email']);
988
+        update_post_meta($invoice->ID, 'payment_form_data', $prepared);
989 989
 
990 990
         $wpi_checkout_id = $invoice->ID;
991 991
         $cart_total = wpinv_price(
992 992
             wpinv_format_amount(
993
-                wpinv_get_cart_total( $invoice->get_cart_details(), NULL, $invoice ) ),
993
+                wpinv_get_cart_total($invoice->get_cart_details(), NULL, $invoice) ),
994 994
                 $invoice->get_currency()
995 995
         );
996 996
 
997 997
         $data                   = array();
998 998
         $data['invoice_id']     = $invoice->ID;
999
-        $data['cart_discounts'] = $invoice->get_discounts( true );
999
+        $data['cart_discounts'] = $invoice->get_discounts(true);
1000 1000
 
1001
-        wpinv_set_checkout_session( $data );
1002
-        add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) );
1003
-        add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) );
1001
+        wpinv_set_checkout_session($data);
1002
+        add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response'));
1003
+        add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error'));
1004 1004
         
1005
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
1006
-            define( 'WPINV_CHECKOUT', true );
1005
+        if (!defined('WPINV_CHECKOUT')) {
1006
+            define('WPINV_CHECKOUT', true);
1007 1007
         }
1008 1008
 
1009 1009
         wpinv_process_checkout();
@@ -1021,51 +1021,51 @@  discard block
 block discarded – undo
1021 1021
     public static function get_payment_form_states_field() {
1022 1022
         global $invoicing;
1023 1023
 
1024
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
1024
+        if (empty($_GET['country']) || empty($_GET['form'])) {
1025 1025
             exit;
1026 1026
         }
1027 1027
 
1028
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
1028
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
1029 1029
 
1030
-        if ( empty( $elements ) ) {
1030
+        if (empty($elements)) {
1031 1031
             exit;
1032 1032
         }
1033 1033
 
1034 1034
         $address_fields = array();
1035
-        foreach ( $elements as $element ) {
1036
-            if ( 'address' === $element['type'] ) {
1035
+        foreach ($elements as $element) {
1036
+            if ('address' === $element['type']) {
1037 1037
                 $address_fields = $element;
1038 1038
                 break;
1039 1039
             }
1040 1040
         }
1041 1041
 
1042
-        if ( empty( $address_fields ) ) {
1042
+        if (empty($address_fields)) {
1043 1043
             exit;
1044 1044
         }
1045 1045
 
1046
-        foreach( $address_fields['fields'] as $address_field ) {
1046
+        foreach ($address_fields['fields'] as $address_field) {
1047 1047
 
1048
-            if ( 'wpinv_state' == $address_field['name'] ) {
1048
+            if ('wpinv_state' == $address_field['name']) {
1049 1049
 
1050 1050
                 $label = $address_field['label'];
1051 1051
 
1052
-                if ( ! empty( $address_field['required'] ) ) {
1052
+                if (!empty($address_field['required'])) {
1053 1053
                     $label .= "<span class='text-danger'> *</span>";
1054 1054
                 }
1055 1055
 
1056
-                $states = wpinv_get_country_states( $_GET['country'] );
1056
+                $states = wpinv_get_country_states($_GET['country']);
1057 1057
 
1058
-                if ( ! empty( $states ) ) {
1058
+                if (!empty($states)) {
1059 1059
 
1060 1060
                     $html = aui()->select(
1061 1061
                             array(
1062 1062
                                 'options'          => $states,
1063
-                                'name'             => esc_attr( $address_field['name'] ),
1064
-                                'id'               => esc_attr( $address_field['name'] ),
1065
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
1063
+                                'name'             => esc_attr($address_field['name']),
1064
+                                'id'               => esc_attr($address_field['name']),
1065
+                                'placeholder'      => esc_attr($address_field['placeholder']),
1066 1066
                                 'required'         => (bool) $address_field['required'],
1067 1067
                                 'no_wrap'          => true,
1068
-                                'label'            => wp_kses_post( $label ),
1068
+                                'label'            => wp_kses_post($label),
1069 1069
                                 'select2'          => false,
1070 1070
                             )
1071 1071
                         );
@@ -1074,10 +1074,10 @@  discard block
 block discarded – undo
1074 1074
 
1075 1075
                     $html = aui()->input(
1076 1076
                             array(
1077
-                                'name'       => esc_attr( $address_field['name'] ),
1078
-                                'id'         => esc_attr( $address_field['name'] ),
1077
+                                'name'       => esc_attr($address_field['name']),
1078
+                                'id'         => esc_attr($address_field['name']),
1079 1079
                                 'required'   => (bool) $address_field['required'],
1080
-                                'label'      => wp_kses_post( $label ),
1080
+                                'label'      => wp_kses_post($label),
1081 1081
                                 'no_wrap'    => true,
1082 1082
                                 'type'       => 'text',
1083 1083
                             )
@@ -1085,7 +1085,7 @@  discard block
 block discarded – undo
1085 1085
 
1086 1086
                 }
1087 1087
 
1088
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
1088
+                wp_send_json_success(str_replace('sr-only', '', $html));
1089 1089
                 exit;
1090 1090
 
1091 1091
             }
@@ -1104,49 +1104,49 @@  discard block
 block discarded – undo
1104 1104
         global $invoicing;
1105 1105
 
1106 1106
         // Check nonce.
1107
-        check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' );
1107
+        check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form');
1108 1108
 
1109 1109
         // Prepare submitted data...
1110
-        $data = wp_unslash( $_POST );
1110
+        $data = wp_unslash($_POST);
1111 1111
 
1112 1112
         // ... form fields...
1113
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
1113
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
1114 1114
             exit;
1115 1115
         }
1116 1116
 
1117 1117
         // Do we have a discount?
1118
-        if ( ! empty( $data['discount'] ) ) {
1118
+        if (!empty($data['discount'])) {
1119 1119
 
1120 1120
             // Validate discount.
1121
-            $discount = self::payment_form_validate_discount( $data );
1121
+            $discount = self::payment_form_validate_discount($data);
1122 1122
 
1123
-            if ( is_array( $discount ) ){
1124
-                $discount = array_map( 'wpinv_format_amount', $discount );
1125
-                $discount = array_map( 'wpinv_price', $discount );
1126
-                wp_send_json_success( $discount );
1123
+            if (is_array($discount)) {
1124
+                $discount = array_map('wpinv_format_amount', $discount);
1125
+                $discount = array_map('wpinv_price', $discount);
1126
+                wp_send_json_success($discount);
1127 1127
             }
1128 1128
 
1129 1129
         }        
1130 1130
 
1131 1131
         // For existing invoices.
1132
-        if ( ! empty( $data['invoice_id'] ) ) {
1133
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
1132
+        if (!empty($data['invoice_id'])) {
1133
+            $invoice = wpinv_get_invoice($data['invoice_id']);
1134 1134
 
1135
-            if ( empty( $invoice ) ) {
1135
+            if (empty($invoice)) {
1136 1136
                 exit;
1137 1137
             }
1138 1138
 
1139
-            $items   = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1139
+            $items   = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
1140 1140
             $country = $invoice->country;
1141 1141
             $state   = $invoice->state;
1142 1142
 
1143 1143
         } else {
1144 1144
 
1145
-            if ( isset( $data['form_items'] ) ) {
1146
-                $items = getpaid_convert_items_to_array( $data['form_items'] );
1147
-                $items = $invoicing->form_elements->convert_normal_items( $items );
1145
+            if (isset($data['form_items'])) {
1146
+                $items = getpaid_convert_items_to_array($data['form_items']);
1147
+                $items = $invoicing->form_elements->convert_normal_items($items);
1148 1148
             } else {
1149
-                $items = $invoicing->form_elements->get_form_items( $data['form_id'] );
1149
+                $items = $invoicing->form_elements->get_form_items($data['form_id']);
1150 1150
             }
1151 1151
 
1152 1152
             $country   = wpinv_default_billing_country();
@@ -1158,59 +1158,59 @@  discard block
 block discarded – undo
1158 1158
         $tax       = 0;
1159 1159
         $sub_total = 0;
1160 1160
 
1161
-        if ( ! empty( $data['wpinv_country'] ) ) {
1161
+        if (!empty($data['wpinv_country'])) {
1162 1162
             $country = $data['wpinv_country'];
1163 1163
         }
1164 1164
 
1165
-        if ( ! empty( $data['wpinv_state'] ) ) {
1165
+        if (!empty($data['wpinv_state'])) {
1166 1166
             $state = $data['wpinv_state'];
1167 1167
         }
1168 1168
 
1169
-        if ( ! empty( $data['wpinv-items'] ) ) {
1169
+        if (!empty($data['wpinv-items'])) {
1170 1170
 
1171
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
1171
+            $selected_items = wpinv_clean($data['wpinv-items']);
1172 1172
 
1173
-            foreach ( $items as $item ) {
1173
+            foreach ($items as $item) {
1174 1174
 
1175
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
1175
+                if (!isset($selected_items[$item['id']])) {
1176 1176
                     continue;
1177 1177
                 }
1178 1178
 
1179
-                $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] );
1179
+                $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']);
1180 1180
 
1181
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
1181
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
1182 1182
 
1183
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
1183
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
1184 1184
 
1185
-                    if ( 1 > $quantity ) {
1185
+                    if (1 > $quantity) {
1186 1186
                         $quantity = 1;
1187 1187
                     }
1188 1188
 
1189 1189
                 }
1190 1190
 
1191 1191
                 // Custom pricing.
1192
-                $price = wpinv_sanitize_amount( $item['price'] );
1193
-                if ( ! empty( $item['custom_price'] ) ) {
1192
+                $price = wpinv_sanitize_amount($item['price']);
1193
+                if (!empty($item['custom_price'])) {
1194 1194
 
1195
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
1196
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
1195
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
1196
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
1197 1197
 
1198
-                    if ( $set_price < $minimum_price ) {
1198
+                    if ($set_price < $minimum_price) {
1199 1199
                         $set_price = $minimum_price;
1200 1200
                     }
1201 1201
 
1202
-                    $price = wpinv_sanitize_amount( $set_price );
1202
+                    $price = wpinv_sanitize_amount($set_price);
1203 1203
 
1204 1204
                 }
1205 1205
 
1206
-                $price  = $quantity * floatval( $price );
1206
+                $price = $quantity * floatval($price);
1207 1207
 
1208
-                if ( wpinv_use_taxes() ) {
1208
+                if (wpinv_use_taxes()) {
1209 1209
 
1210
-                    $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] );
1210
+                    $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']);
1211 1211
 
1212
-                    if ( wpinv_prices_include_tax() ) {
1213
-                        $pre_tax  = ( $price - $price * $rate * 0.01 );
1212
+                    if (wpinv_prices_include_tax()) {
1213
+                        $pre_tax  = ($price - $price * $rate * 0.01);
1214 1214
                         $item_tax = $price - $pre_tax;
1215 1215
                     } else {
1216 1216
                         $pre_tax  = $price;
@@ -1222,17 +1222,17 @@  discard block
 block discarded – undo
1222 1222
                     $total     = $sub_total + $tax;
1223 1223
 
1224 1224
                 } else {
1225
-                    $total  = $total + $price;
1225
+                    $total = $total + $price;
1226 1226
                 }
1227 1227
 
1228 1228
             }
1229 1229
 
1230 1230
         }
1231 1231
 
1232
-        wp_send_json_success( array(
1233
-            'total'     => wpinv_price( wpinv_format_amount( $total ) ),
1234
-            'tax'       => wpinv_price( wpinv_format_amount( $tax ) ),
1235
-            'sub_total' => wpinv_price( wpinv_format_amount( $sub_total ) ),
1232
+        wp_send_json_success(array(
1233
+            'total'     => wpinv_price(wpinv_format_amount($total)),
1234
+            'tax'       => wpinv_price(wpinv_format_amount($tax)),
1235
+            'sub_total' => wpinv_price(wpinv_format_amount($sub_total)),
1236 1236
             'discount'  => false,
1237 1237
         ));
1238 1238
         exit;
@@ -1246,38 +1246,38 @@  discard block
 block discarded – undo
1246 1246
     public static function payment_form_discount() {
1247 1247
 
1248 1248
         // Check nonce.
1249
-        check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' );
1249
+        check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form');
1250 1250
 
1251 1251
         // Prepare submitted data...
1252
-        $data = wp_unslash( $_POST );
1252
+        $data = wp_unslash($_POST);
1253 1253
 
1254 1254
         // ... form fields...
1255
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
1255
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
1256 1256
             exit;
1257 1257
         }
1258 1258
 
1259 1259
         // Do we have a discount?
1260
-        if ( empty( $data['discount'] ) ) {
1261
-            _e( 'Please enter your discount code', 'invoicing' );
1260
+        if (empty($data['discount'])) {
1261
+            _e('Please enter your discount code', 'invoicing');
1262 1262
             exit;
1263 1263
         }
1264 1264
 
1265 1265
         // Validate discount.
1266
-        $data = self::payment_form_validate_discount( $data );
1266
+        $data = self::payment_form_validate_discount($data);
1267 1267
 
1268
-        if ( false === $data ) {
1269
-            _e( 'There was an error applying your discount code', 'invoicing' );
1268
+        if (false === $data) {
1269
+            _e('There was an error applying your discount code', 'invoicing');
1270 1270
             exit;
1271 1271
         }
1272 1272
 
1273
-        if ( is_string( $data ) ) {
1273
+        if (is_string($data)) {
1274 1274
             echo $data;
1275 1275
             exit;
1276 1276
         }
1277 1277
 
1278
-        $data = array_map( 'wpinv_format_amount', $data );
1279
-        $data = array_map( 'wpinv_price', $data );
1280
-        wp_send_json_success( $data );
1278
+        $data = array_map('wpinv_format_amount', $data);
1279
+        $data = array_map('wpinv_price', $data);
1280
+        wp_send_json_success($data);
1281 1281
         exit;
1282 1282
 
1283 1283
     }
@@ -1287,54 +1287,54 @@  discard block
 block discarded – undo
1287 1287
      *
1288 1288
      * @since 1.0.19
1289 1289
      */
1290
-    public static function payment_form_validate_discount( $data ) {
1290
+    public static function payment_form_validate_discount($data) {
1291 1291
         global $invoicing;
1292 1292
 
1293 1293
         // Do we have a discount?
1294
-        if ( empty( $data['discount'] ) ) {
1294
+        if (empty($data['discount'])) {
1295 1295
             return false;
1296 1296
         }
1297 1297
 
1298 1298
         // If yes, ensure that it exists.
1299
-        $discount = wpinv_get_discount_obj( $data['discount'] );
1299
+        $discount = wpinv_get_discount_obj($data['discount']);
1300 1300
 
1301 1301
         // Ensure it is active.
1302
-        if ( ! $discount->exists() || ! $discount->is_active() || ! $discount->has_started() || $discount->is_expired() ) {
1303
-            return __( 'This discount code is not valid', 'invoicing' );
1302
+        if (!$discount->exists() || !$discount->is_active() || !$discount->has_started() || $discount->is_expired()) {
1303
+            return __('This discount code is not valid', 'invoicing');
1304 1304
         }
1305 1305
 
1306 1306
         // If it can only be used once per user...
1307
-        if ( $discount->is_single_use ) {
1307
+        if ($discount->is_single_use) {
1308 1308
 
1309
-            if ( empty( $data['billing_email'] ) ) {
1310
-                return __( 'Please enter your billing email before applying this discount', 'invoicing' );
1309
+            if (empty($data['billing_email'])) {
1310
+                return __('Please enter your billing email before applying this discount', 'invoicing');
1311 1311
             }
1312 1312
 
1313
-            if ( ! $discount->is_valid_for_user( $data['billing_email'] ) ) {
1314
-                return __( 'You have already used this discount', 'invoicing' );
1313
+            if (!$discount->is_valid_for_user($data['billing_email'])) {
1314
+                return __('You have already used this discount', 'invoicing');
1315 1315
             }
1316 1316
 
1317 1317
         }
1318 1318
 
1319 1319
         // Prepare items.
1320
-        if ( ! empty( $data['invoice_id'] ) ) {
1321
-            $invoice = wpinv_get_invoice( $data['invoice_id'] );
1320
+        if (!empty($data['invoice_id'])) {
1321
+            $invoice = wpinv_get_invoice($data['invoice_id']);
1322 1322
 
1323
-            if ( empty( $invoice ) ) {
1323
+            if (empty($invoice)) {
1324 1324
                 return false;
1325 1325
             }
1326 1326
 
1327 1327
             $country = $invoice->country;
1328 1328
             $state   = $invoice->state;
1329
-            $items   = $invoicing->form_elements->convert_checkout_items( $invoice->cart_details, $invoice );
1329
+            $items   = $invoicing->form_elements->convert_checkout_items($invoice->cart_details, $invoice);
1330 1330
 
1331 1331
         } else {
1332 1332
 
1333
-            if ( isset( $data['form_items'] ) ) {
1334
-                $items = getpaid_convert_items_to_array( $data['form_items'] );
1335
-                $items = $invoicing->form_elements->convert_normal_items( $items );
1333
+            if (isset($data['form_items'])) {
1334
+                $items = getpaid_convert_items_to_array($data['form_items']);
1335
+                $items = $invoicing->form_elements->convert_normal_items($items);
1336 1336
             } else {
1337
-                $items = $invoicing->form_elements->get_form_items( $data['form_id'] );
1337
+                $items = $invoicing->form_elements->get_form_items($data['form_id']);
1338 1338
             }
1339 1339
 
1340 1340
             $country   = wpinv_default_billing_country();
@@ -1347,64 +1347,64 @@  discard block
 block discarded – undo
1347 1347
         $tax       = 0;
1348 1348
         $sub_total = 0;
1349 1349
 
1350
-        if ( ! empty( $data['wpinv_country'] ) ) {
1350
+        if (!empty($data['wpinv_country'])) {
1351 1351
             $country = $data['wpinv_country'];
1352 1352
         }
1353 1353
 
1354
-        if ( ! empty( $data['wpinv_state'] ) ) {
1354
+        if (!empty($data['wpinv_state'])) {
1355 1355
             $state = $data['wpinv_state'];
1356 1356
         }
1357 1357
 
1358
-        if ( ! empty( $data['wpinv-items'] ) ) {
1358
+        if (!empty($data['wpinv-items'])) {
1359 1359
 
1360
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
1360
+            $selected_items = wpinv_clean($data['wpinv-items']);
1361 1361
 
1362 1362
             // Check if it is valid for the selected items.
1363
-            if ( ! $discount->is_valid_for_items( array_keys( $selected_items ) ) ) {
1364
-                return __( 'This discount is not valid for the items in your cart', 'invoicing' );
1363
+            if (!$discount->is_valid_for_items(array_keys($selected_items))) {
1364
+                return __('This discount is not valid for the items in your cart', 'invoicing');
1365 1365
             }
1366 1366
 
1367
-            foreach ( $items as $item ) {
1367
+            foreach ($items as $item) {
1368 1368
 
1369
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
1369
+                if (!isset($selected_items[$item['id']])) {
1370 1370
                     continue;
1371 1371
                 }
1372 1372
 
1373
-                $quantity = empty( $item['quantity'] ) ? 1 : absint( $item['quantity'] );
1373
+                $quantity = empty($item['quantity']) ? 1 : absint($item['quantity']);
1374 1374
 
1375
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
1375
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
1376 1376
 
1377
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
1377
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
1378 1378
 
1379
-                    if ( 1 > $quantity ) {
1379
+                    if (1 > $quantity) {
1380 1380
                         $quantity = 1;
1381 1381
                     }
1382 1382
 
1383 1383
                 }
1384 1384
 
1385 1385
                 // Custom pricing.
1386
-                $price = wpinv_sanitize_amount( $item['price'] );
1387
-                if ( ! empty( $item['custom_price'] ) ) {
1386
+                $price = wpinv_sanitize_amount($item['price']);
1387
+                if (!empty($item['custom_price'])) {
1388 1388
 
1389
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
1390
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
1389
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
1390
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
1391 1391
 
1392
-                    if ( $set_price < $minimum_price ) {
1392
+                    if ($set_price < $minimum_price) {
1393 1393
                         $set_price = $minimum_price;
1394 1394
                     }
1395 1395
 
1396
-                    $price = wpinv_sanitize_amount( $set_price );
1396
+                    $price = wpinv_sanitize_amount($set_price);
1397 1397
 
1398 1398
                 }
1399 1399
 
1400
-                $price  = $quantity * floatval( $price );
1400
+                $price = $quantity * floatval($price);
1401 1401
 
1402
-                if ( wpinv_use_taxes() ) {
1402
+                if (wpinv_use_taxes()) {
1403 1403
 
1404
-                    $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] );
1404
+                    $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']);
1405 1405
 
1406
-                    if ( wpinv_prices_include_tax() ) {
1407
-                        $pre_tax  = ( $price - $price * $rate * 0.01 );
1406
+                    if (wpinv_prices_include_tax()) {
1407
+                        $pre_tax  = ($price - $price * $rate * 0.01);
1408 1408
                         $item_tax = $price - $pre_tax;
1409 1409
                     } else {
1410 1410
                         $pre_tax  = $price;
@@ -1416,26 +1416,26 @@  discard block
 block discarded – undo
1416 1416
                     $total     = $sub_total + $tax;
1417 1417
 
1418 1418
                 } else {
1419
-                    $total  = $total + $price;
1419
+                    $total = $total + $price;
1420 1420
                 }
1421 1421
 
1422 1422
             }
1423 1423
 
1424 1424
         }
1425 1425
 
1426
-        if ( ! $discount->is_minimum_amount_met( $total ) ) {
1427
-            $min = wpinv_price( wpinv_format_amount( $discount->min_total ) );
1428
-            return sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min );
1426
+        if (!$discount->is_minimum_amount_met($total)) {
1427
+            $min = wpinv_price(wpinv_format_amount($discount->min_total));
1428
+            return sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min);
1429 1429
         }
1430 1430
 
1431
-        if ( ! $discount->is_maximum_amount_met( $total ) ) {
1432
-            $max = wpinv_price( wpinv_format_amount( $discount->max_total ) );
1433
-            return sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max );
1431
+        if (!$discount->is_maximum_amount_met($total)) {
1432
+            $max = wpinv_price(wpinv_format_amount($discount->max_total));
1433
+            return sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max);
1434 1434
         }
1435 1435
 
1436
-        $discount = $discount->get_discounted_amount( $total );
1436
+        $discount = $discount->get_discounted_amount($total);
1437 1437
         $total    = $total - $discount;
1438
-        return compact( 'total', 'tax', 'sub_total', 'discount' );
1438
+        return compact('total', 'tax', 'sub_total', 'discount');
1439 1439
 
1440 1440
     }
1441 1441
 
@@ -1447,53 +1447,53 @@  discard block
 block discarded – undo
1447 1447
     public static function buy_items() {
1448 1448
         $user_id = get_current_user_id();
1449 1449
 
1450
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
1451
-            wp_send_json( array(
1452
-                'success' => wp_login_url( wp_get_referer() )
1453
-            ) );
1450
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
1451
+            wp_send_json(array(
1452
+                'success' => wp_login_url(wp_get_referer())
1453
+            ));
1454 1454
         } else {
1455 1455
             // Only check nonce if logged in as it could be cached when logged out.
1456
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
1457
-                wp_send_json( array(
1458
-                    'error' => __( 'Security checks failed.', 'invoicing' )
1459
-                ) );
1456
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
1457
+                wp_send_json(array(
1458
+                    'error' => __('Security checks failed.', 'invoicing')
1459
+                ));
1460 1460
                 wp_die();
1461 1461
             }
1462 1462
 
1463 1463
             // allow to set a custom price through post_id
1464 1464
             $items = $_POST['items'];
1465
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
1466
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
1465
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
1466
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
1467 1467
 
1468 1468
             $cart_items = array();
1469
-            if ( $items ) {
1470
-                $items = explode( ',', $items );
1469
+            if ($items) {
1470
+                $items = explode(',', $items);
1471 1471
 
1472
-                foreach( $items as $item ) {
1472
+                foreach ($items as $item) {
1473 1473
                     $item_id = $item;
1474 1474
                     $quantity = 1;
1475 1475
 
1476
-                    if ( strpos( $item, '|' ) !== false ) {
1477
-                        $item_parts = explode( '|', $item );
1476
+                    if (strpos($item, '|') !== false) {
1477
+                        $item_parts = explode('|', $item);
1478 1478
                         $item_id = $item_parts[0];
1479 1479
                         $quantity = $item_parts[1];
1480 1480
                     }
1481 1481
 
1482
-                    if ( $item_id && $quantity ) {
1482
+                    if ($item_id && $quantity) {
1483 1483
                         $cart_items_arr = array(
1484
-                            'id'            => (int)$item_id,
1485
-                            'quantity'      => (int)$quantity
1484
+                            'id'            => (int) $item_id,
1485
+                            'quantity'      => (int) $quantity
1486 1486
                         );
1487 1487
 
1488 1488
                         // If there is a related post id then add it to meta
1489
-                        if ( $related_post_id ) {
1489
+                        if ($related_post_id) {
1490 1490
                             $cart_items_arr['meta'] = array(
1491 1491
                                 'post_id'   => $related_post_id
1492 1492
                             );
1493 1493
                         }
1494 1494
 
1495 1495
                         // If there is a custom price then set it.
1496
-                        if ( $custom_item_price ) {
1496
+                        if ($custom_item_price) {
1497 1497
                             $cart_items_arr['custom_price'] = $custom_item_price;
1498 1498
                         }
1499 1499
 
@@ -1509,37 +1509,37 @@  discard block
 block discarded – undo
1509 1509
              * @param int $related_post_id The related post id if any.
1510 1510
              * @since 1.0.0
1511 1511
              */
1512
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
1512
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
1513 1513
 
1514 1514
             // Make sure its not in the cart already, if it is then redirect to checkout.
1515 1515
             $cart_invoice = wpinv_get_invoice_cart();
1516 1516
 
1517
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
1518
-                wp_send_json( array(
1517
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
1518
+                wp_send_json(array(
1519 1519
                     'success' =>  $cart_invoice->get_checkout_payment_url()
1520
-                ) );
1520
+                ));
1521 1521
                 wp_die();
1522 1522
             }
1523 1523
 
1524 1524
             // Check if user has invoice with same items waiting to be paid.
1525
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
1526
-            if ( !empty( $user_invoices ) ) {
1527
-                foreach( $user_invoices as $user_invoice ) {
1525
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
1526
+            if (!empty($user_invoices)) {
1527
+                foreach ($user_invoices as $user_invoice) {
1528 1528
                     $user_cart_details = array();
1529
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
1529
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
1530 1530
                     $cart_details = $invoice->get_cart_details();
1531 1531
 
1532
-                    if ( !empty( $cart_details ) ) {
1533
-                        foreach ( $cart_details as $invoice_item ) {
1532
+                    if (!empty($cart_details)) {
1533
+                        foreach ($cart_details as $invoice_item) {
1534 1534
                             $ii_arr = array();
1535
-                            $ii_arr['id'] = (int)$invoice_item['id'];
1536
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
1535
+                            $ii_arr['id'] = (int) $invoice_item['id'];
1536
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
1537 1537
 
1538
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
1538
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
1539 1539
                                 $ii_arr['meta'] = $invoice_item['meta'];
1540 1540
                             }
1541 1541
 
1542
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1542
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1543 1543
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1544 1544
                             }
1545 1545
 
@@ -1547,17 +1547,17 @@  discard block
 block discarded – undo
1547 1547
                         }
1548 1548
                     }
1549 1549
 
1550
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1551
-                        wp_send_json( array(
1550
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1551
+                        wp_send_json(array(
1552 1552
                             'success' =>  $invoice->get_checkout_payment_url()
1553
-                        ) );
1553
+                        ));
1554 1554
                         wp_die();
1555 1555
                     }
1556 1556
                 }
1557 1557
             }
1558 1558
 
1559 1559
             // Create invoice and send user to checkout
1560
-            if ( !empty( $cart_items ) ) {
1560
+            if (!empty($cart_items)) {
1561 1561
                 $invoice_data = array(
1562 1562
                     'status'        =>  'wpi-pending',
1563 1563
                     'created_via'   =>  'wpi',
@@ -1565,21 +1565,21 @@  discard block
 block discarded – undo
1565 1565
                     'cart_details'  =>  $cart_items,
1566 1566
                 );
1567 1567
 
1568
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1568
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1569 1569
 
1570
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1571
-                    wp_send_json( array(
1570
+                if (!empty($invoice) && isset($invoice->ID)) {
1571
+                    wp_send_json(array(
1572 1572
                         'success' =>  $invoice->get_checkout_payment_url()
1573
-                    ) );
1573
+                    ));
1574 1574
                 } else {
1575
-                    wp_send_json( array(
1576
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1577
-                    ) );
1575
+                    wp_send_json(array(
1576
+                        'error' => __('Invoice failed to create', 'invoicing')
1577
+                    ));
1578 1578
                 }
1579 1579
             } else {
1580
-                wp_send_json( array(
1581
-                    'error' => __( 'Items not valid.', 'invoicing' )
1582
-                ) );
1580
+                wp_send_json(array(
1581
+                    'error' => __('Items not valid.', 'invoicing')
1582
+                ));
1583 1583
             }
1584 1584
         }
1585 1585
 
Please login to merge, or discard this patch.
includes/class-wpinv-discount.php 2 patches
Indentation   +674 added lines, -674 removed lines patch added patch discarded remove patch
@@ -33,173 +33,173 @@  discard block
 block discarded – undo
33 33
  */
34 34
 class WPInv_Discount {
35 35
 	
36
-	/**
37
-	 * Discount ID.
38
-	 *
39
-	 * @since 1.0.15
40
-	 * @var integer|null
41
-	 */
42
-	public $ID = null;
43
-
44
-	/**
45
-	 * Old discount status.
46
-	 *
47
-	 * @since 1.0.15
48
-	 * @var string
49
-	 */
50
-	public $old_status = 'draft';
36
+    /**
37
+     * Discount ID.
38
+     *
39
+     * @since 1.0.15
40
+     * @var integer|null
41
+     */
42
+    public $ID = null;
43
+
44
+    /**
45
+     * Old discount status.
46
+     *
47
+     * @since 1.0.15
48
+     * @var string
49
+     */
50
+    public $old_status = 'draft';
51 51
 	
52
-	/**
53
-	 * Data array.
54
-	 *
55
-	 * @since 1.0.15
56
-	 * @var array
57
-	 */
58
-	protected $data = array();
59
-
60
-	/**
61
-	 * Discount constructor.
62
-	 *
63
-	 * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
64
-	 * @since 1.0.15
65
-	 */
66
-	public function __construct( $discount = array() ) {
52
+    /**
53
+     * Data array.
54
+     *
55
+     * @since 1.0.15
56
+     * @var array
57
+     */
58
+    protected $data = array();
59
+
60
+    /**
61
+     * Discount constructor.
62
+     *
63
+     * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
64
+     * @since 1.0.15
65
+     */
66
+    public function __construct( $discount = array() ) {
67 67
         
68 68
         // If the discount is an instance of this class...
69
-		if ( $discount instanceof WPInv_Discount ) {
70
-			$this->init( $discount->data );
71
-			return;
69
+        if ( $discount instanceof WPInv_Discount ) {
70
+            $this->init( $discount->data );
71
+            return;
72 72
         }
73 73
         
74 74
         // If the discount is an array of discount details...
75 75
         if ( is_array( $discount ) ) {
76
-			$this->init( $discount );
77
-			return;
78
-		}
76
+            $this->init( $discount );
77
+            return;
78
+        }
79 79
 		
80
-		// Try fetching the discount by its post id.
81
-		$data = false;
80
+        // Try fetching the discount by its post id.
81
+        $data = false;
82 82
 		
83
-		if ( ! empty( $discount ) && is_numeric( $discount ) ) {
84
-			$discount = absint( $discount );
85
-			$data = self::get_data_by( 'id', $discount );
86
-		}
87
-
88
-		if ( is_array( $data ) ) {
89
-			$this->init( $data );
90
-			return;
91
-		}
83
+        if ( ! empty( $discount ) && is_numeric( $discount ) ) {
84
+            $discount = absint( $discount );
85
+            $data = self::get_data_by( 'id', $discount );
86
+        }
87
+
88
+        if ( is_array( $data ) ) {
89
+            $this->init( $data );
90
+            return;
91
+        }
92 92
 		
93
-		// Try fetching the discount by its discount code.
94
-		if ( ! empty( $discount ) && is_string( $discount ) ) {
95
-			$data = self::get_data_by( 'discount_code', $discount );
96
-		}
97
-
98
-		if ( is_array( $data ) ) {
99
-			$this->init( $data );
100
-			return;
101
-		} 
93
+        // Try fetching the discount by its discount code.
94
+        if ( ! empty( $discount ) && is_string( $discount ) ) {
95
+            $data = self::get_data_by( 'discount_code', $discount );
96
+        }
97
+
98
+        if ( is_array( $data ) ) {
99
+            $this->init( $data );
100
+            return;
101
+        } 
102 102
 		
103
-		// If we are here then the discount does not exist.
104
-		$this->init( array() );
105
-	}
103
+        // If we are here then the discount does not exist.
104
+        $this->init( array() );
105
+    }
106 106
 	
107
-	/**
108
-	 * Sets up object properties
109
-	 *
110
-	 * @since 1.0.15
111
-	 * @param array $data An array containing the discount's data
112
-	 */
113
-	public function init( $data ) {
114
-		$data       	  = self::sanitize_discount_data( $data );
115
-		$this->data 	  = $data;
116
-		$this->old_status = $data['status'];
117
-		$this->ID   	  = $data['ID'];
118
-	}
107
+    /**
108
+     * Sets up object properties
109
+     *
110
+     * @since 1.0.15
111
+     * @param array $data An array containing the discount's data
112
+     */
113
+    public function init( $data ) {
114
+        $data       	  = self::sanitize_discount_data( $data );
115
+        $this->data 	  = $data;
116
+        $this->old_status = $data['status'];
117
+        $this->ID   	  = $data['ID'];
118
+    }
119 119
 	
120
-	/**
121
-	 * Fetch a discount from the db/cache
122
-	 *
123
-	 *
124
-	 * @static
125
-	 * @param string $field The field to query against: 'ID', 'discount_code'
126
-	 * @param string|int $value The field value
127
-	 * @since 1.0.15
128
-	 * @return array|bool array of discount details on success. False otherwise.
129
-	 */
130
-	public static function get_data_by( $field, $value ) {
131
-
132
-		if ( 'id' == strtolower( $field ) ) {
133
-			// Make sure the value is numeric to avoid casting objects, for example,
134
-			// to int 1.
135
-			if ( ! is_numeric( $value ) )
136
-				return false;
137
-			$value = intval( $value );
138
-			if ( $value < 1 )
139
-				return false;
140
-		}
141
-
142
-		if ( ! $value || ! is_string( $field ) ) {
143
-			return false;
144
-		}
120
+    /**
121
+     * Fetch a discount from the db/cache
122
+     *
123
+     *
124
+     * @static
125
+     * @param string $field The field to query against: 'ID', 'discount_code'
126
+     * @param string|int $value The field value
127
+     * @since 1.0.15
128
+     * @return array|bool array of discount details on success. False otherwise.
129
+     */
130
+    public static function get_data_by( $field, $value ) {
131
+
132
+        if ( 'id' == strtolower( $field ) ) {
133
+            // Make sure the value is numeric to avoid casting objects, for example,
134
+            // to int 1.
135
+            if ( ! is_numeric( $value ) )
136
+                return false;
137
+            $value = intval( $value );
138
+            if ( $value < 1 )
139
+                return false;
140
+        }
141
+
142
+        if ( ! $value || ! is_string( $field ) ) {
143
+            return false;
144
+        }
145 145
 		
146
-		$field = trim( $field );
147
-
148
-		// prepare query args
149
-		switch ( strtolower( $field ) ) {
150
-			case 'id':
151
-				$discount_id = $value;
152
-				$args		 = array( 'include' => array( $value ) );
153
-				break;
154
-			case 'discount_code':
155
-			case 'code':
156
-				$value       = trim( $value );
157
-				$discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
158
-				$args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
159
-				break;
160
-			case 'name':
161
-				$discount_id = 0;
162
-				$args		 = array( 'name' => trim( $value ) );
163
-				break;
164
-			default:
165
-				$args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
166
-				if ( ! is_array( $args ) ) {
167
-					return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
168
-				}
169
-
170
-		}
171
-
172
-		// Check if there is a cached value.
173
-		if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
174
-			return $discount;
175
-		}
176
-
177
-		$args = array_merge(
178
-			$args,
179
-			array(
180
-				'post_type'      => 'wpi_discount',
181
-				'posts_per_page' => 1,
182
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
183
-			)
184
-		);
185
-
186
-		$discount = get_posts( $args );
146
+        $field = trim( $field );
147
+
148
+        // prepare query args
149
+        switch ( strtolower( $field ) ) {
150
+            case 'id':
151
+                $discount_id = $value;
152
+                $args		 = array( 'include' => array( $value ) );
153
+                break;
154
+            case 'discount_code':
155
+            case 'code':
156
+                $value       = trim( $value );
157
+                $discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
158
+                $args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
159
+                break;
160
+            case 'name':
161
+                $discount_id = 0;
162
+                $args		 = array( 'name' => trim( $value ) );
163
+                break;
164
+            default:
165
+                $args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
166
+                if ( ! is_array( $args ) ) {
167
+                    return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
168
+                }
169
+
170
+        }
171
+
172
+        // Check if there is a cached value.
173
+        if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
174
+            return $discount;
175
+        }
176
+
177
+        $args = array_merge(
178
+            $args,
179
+            array(
180
+                'post_type'      => 'wpi_discount',
181
+                'posts_per_page' => 1,
182
+                'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
183
+            )
184
+        );
185
+
186
+        $discount = get_posts( $args );
187 187
 				
188
-		if( empty( $discount ) ) {
189
-			return false;
190
-		}
188
+        if( empty( $discount ) ) {
189
+            return false;
190
+        }
191 191
 
192
-		$discount = $discount[0];
192
+        $discount = $discount[0];
193 193
 		
194
-		// Prepare the return data.
195
-		$return = array(
194
+        // Prepare the return data.
195
+        $return = array(
196 196
             'ID'                          => $discount->ID,
197 197
             'code'                        => get_post_meta( $discount->ID, '_wpi_discount_code', true ),
198 198
             'amount'                      => get_post_meta( $discount->ID, '_wpi_discount_amount', true ),
199 199
             'date_created'                => $discount->post_date,
200
-			'date_modified'               => $discount->post_modified,
201
-			'status'               		  => $discount->post_status,
202
-			'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
200
+            'date_modified'               => $discount->post_modified,
201
+            'status'               		  => $discount->post_status,
202
+            'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
203 203
             'expiration'                  => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ),
204 204
             'type'               		  => get_post_meta( $discount->ID, '_wpi_discount_type', true ),
205 205
             'description'                 => $discount->post_excerpt,
@@ -213,38 +213,38 @@  discard block
 block discarded – undo
213 213
             'max_total'                   => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ),
214 214
         );
215 215
 		
216
-		$return = self::sanitize_discount_data( $return );
217
-		$return = apply_filters( 'wpinv_discount_properties', $return );
216
+        $return = self::sanitize_discount_data( $return );
217
+        $return = apply_filters( 'wpinv_discount_properties', $return );
218 218
 
219
-		// Update the cache with our data
220
-		wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
221
-		wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
219
+        // Update the cache with our data
220
+        wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
221
+        wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
222 222
 
223
-		return $return;
224
-	}
223
+        return $return;
224
+    }
225 225
 	
226
-	/**
227
-	 * Sanitizes discount data
228
-	 *
229
-	 * @static
230
-	 * @since 1.0.15
231
-	 * @access public
232
-	 *
233
-	 * @return array the sanitized data
234
-	 */
235
-	public static function sanitize_discount_data( $data ) {
226
+    /**
227
+     * Sanitizes discount data
228
+     *
229
+     * @static
230
+     * @since 1.0.15
231
+     * @access public
232
+     *
233
+     * @return array the sanitized data
234
+     */
235
+    public static function sanitize_discount_data( $data ) {
236 236
 		
237
-		$allowed_discount_types = array_keys( wpinv_get_discount_types() );
237
+        $allowed_discount_types = array_keys( wpinv_get_discount_types() );
238 238
 		
239
-		$return = array(
239
+        $return = array(
240 240
             'ID'                          => null,
241 241
             'code'                        => '',
242 242
             'amount'                      => 0,
243 243
             'date_created'                => current_time('mysql'),
244 244
             'date_modified'               => current_time('mysql'),
245
-			'expiration'                  => null,
246
-			'start'                  	  => current_time('mysql'),
247
-			'status'                  	  => 'draft',
245
+            'expiration'                  => null,
246
+            'start'                  	  => current_time('mysql'),
247
+            'status'                  	  => 'draft',
248 248
             'type'               		  => 'percent',
249 249
             'description'                 => '',
250 250
             'uses'                        => 0,
@@ -254,426 +254,426 @@  discard block
 block discarded – undo
254 254
             'max_uses'                    => 0,
255 255
             'is_recurring'                => false,
256 256
             'min_total'                   => '',
257
-			'max_total'              	  => '',
258
-		);
257
+            'max_total'              	  => '',
258
+        );
259 259
 		
260 260
 				
261
-		// Arrays only please.
262
-		if ( ! is_array( $data ) ) {
261
+        // Arrays only please.
262
+        if ( ! is_array( $data ) ) {
263 263
             return $return;
264 264
         }
265 265
 
266
-		// If an id is provided, ensure it is a valid discount.
266
+        // If an id is provided, ensure it is a valid discount.
267 267
         if ( ! empty( $data['ID'] ) && ( ! is_numeric( $data['ID'] ) || 'wpi_discount' !== get_post_type( $data['ID'] ) ) ) {
268 268
             return $return;
269
-		}
269
+        }
270 270
 
271 271
         $return = array_merge( $return, $data );
272 272
 
273 273
         // Sanitize some keys.
274 274
         $return['amount']         = wpinv_sanitize_amount( $return['amount'] );
275
-		$return['is_single_use']  = (bool) $return['is_single_use'];
276
-		$return['is_recurring']   = (bool) $return['is_recurring'];
277
-		$return['uses']	          = (int) $return['uses'];
278
-		$return['max_uses']	      = (int) $return['max_uses'];
279
-		$return['min_total'] 	  = wpinv_sanitize_amount( $return['min_total'] );
275
+        $return['is_single_use']  = (bool) $return['is_single_use'];
276
+        $return['is_recurring']   = (bool) $return['is_recurring'];
277
+        $return['uses']	          = (int) $return['uses'];
278
+        $return['max_uses']	      = (int) $return['max_uses'];
279
+        $return['min_total'] 	  = wpinv_sanitize_amount( $return['min_total'] );
280 280
         $return['max_total'] 	  = wpinv_sanitize_amount( $return['max_total'] );
281 281
 
282
-		// Trim all values.
283
-		$return = wpinv_clean( $return );
282
+        // Trim all values.
283
+        $return = wpinv_clean( $return );
284 284
 		
285
-		// Ensure the discount type is supported.
285
+        // Ensure the discount type is supported.
286 286
         if ( ! in_array( $return['type'], $allowed_discount_types, true ) ) {
287 287
             $return['type'] = 'percent';
288
-		}
289
-		$return['type_name'] = wpinv_get_discount_type_name( $return['type'] );
288
+        }
289
+        $return['type_name'] = wpinv_get_discount_type_name( $return['type'] );
290 290
 		
291
-		// Do not offer more than a 100% discount.
292
-		if ( $return['type'] == 'percent' && (float) $return['amount'] > 100 ) {
293
-			$return['amount'] = 100;
294
-		}
295
-
296
-		// Format dates.
297
-		foreach( wpinv_parse_list( 'date_created date_modified expiration start') as $prop ) {
298
-			if( ! empty( $return[$prop] ) ) {
299
-				$return[$prop]      = date_i18n( 'Y-m-d H:i:s', strtotime( $return[$prop] ) );
300
-			}
301
-		}
302
-
303
-		// Formart items.
304
-		foreach( array( 'excluded_items', 'items' ) as $prop ) {
305
-
306
-			if( ! empty( $return[$prop] ) ) {
307
-				// Ensure that the property is an array of non-empty integers.
308
-				$return[$prop]      = array_filter( array_map( 'intval', wpinv_parse_list( $return[$prop] ) ) );
309
-			} else {
310
-				$return[$prop]      = array();
311
-			}
312
-
313
-		}
291
+        // Do not offer more than a 100% discount.
292
+        if ( $return['type'] == 'percent' && (float) $return['amount'] > 100 ) {
293
+            $return['amount'] = 100;
294
+        }
295
+
296
+        // Format dates.
297
+        foreach( wpinv_parse_list( 'date_created date_modified expiration start') as $prop ) {
298
+            if( ! empty( $return[$prop] ) ) {
299
+                $return[$prop]      = date_i18n( 'Y-m-d H:i:s', strtotime( $return[$prop] ) );
300
+            }
301
+        }
302
+
303
+        // Formart items.
304
+        foreach( array( 'excluded_items', 'items' ) as $prop ) {
305
+
306
+            if( ! empty( $return[$prop] ) ) {
307
+                // Ensure that the property is an array of non-empty integers.
308
+                $return[$prop]      = array_filter( array_map( 'intval', wpinv_parse_list( $return[$prop] ) ) );
309
+            } else {
310
+                $return[$prop]      = array();
311
+            }
312
+
313
+        }
314 314
 		
315
-		return apply_filters( 'wpinv_sanitize_discount_data', $return, $data );
316
-	}
315
+        return apply_filters( 'wpinv_sanitize_discount_data', $return, $data );
316
+    }
317 317
 	
318
-	/**
319
-	 * Magic method for checking the existence of a certain custom field.
320
-	 *
321
-	 * @since 1.0.15
322
-	 * @access public
323
-	 *
324
-	 * @return bool Whether the given discount field is set.
325
-	 */
326
-	public function __isset( $key ){
327
-		return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
328
-	}
318
+    /**
319
+     * Magic method for checking the existence of a certain custom field.
320
+     *
321
+     * @since 1.0.15
322
+     * @access public
323
+     *
324
+     * @return bool Whether the given discount field is set.
325
+     */
326
+    public function __isset( $key ){
327
+        return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
328
+    }
329 329
 	
330
-	/**
331
-	 * Magic method for accessing discount properties.
332
-	 *
333
-	 * @since 1.0.15
334
-	 * @access public
335
-	 *
336
-	 * @param string $key Discount data to retrieve
337
-	 * @return mixed Value of the given discount property (if set).
338
-	 */
339
-	public function __get( $key ) {
340
-		return $this->get( $key );
341
-	}
342
-
343
-	/**
344
-	 * Magic method for accessing discount properties.
345
-	 *
346
-	 * @since 1.0.15
347
-	 * @access public
348
-	 *
349
-	 * @param string $key Discount data to retrieve
350
-	 * @return mixed Value of the given discount property (if set).
351
-	 */
352
-	public function get( $key ) {
330
+    /**
331
+     * Magic method for accessing discount properties.
332
+     *
333
+     * @since 1.0.15
334
+     * @access public
335
+     *
336
+     * @param string $key Discount data to retrieve
337
+     * @return mixed Value of the given discount property (if set).
338
+     */
339
+    public function __get( $key ) {
340
+        return $this->get( $key );
341
+    }
342
+
343
+    /**
344
+     * Magic method for accessing discount properties.
345
+     *
346
+     * @since 1.0.15
347
+     * @access public
348
+     *
349
+     * @param string $key Discount data to retrieve
350
+     * @return mixed Value of the given discount property (if set).
351
+     */
352
+    public function get( $key ) {
353 353
 		
354
-		if ( $key == 'id' ) {
355
-			$key = 'ID';
356
-		}
357
-
358
-		if ( method_exists( $this, "get_$key") ) {
359
-			$value 	= call_user_func( array( $this, "get_$key" ) );
360
-		} else if( isset( $this->data[$key] ) ) {
361
-			$value 	= $this->data[$key];
362
-		} else {
363
-			$value = null;
364
-		}
365
-
366
-		/**
367
-		 * Filters a discount's property value.
368
-		 * 
369
-		 * The dynamic part ($key) can be any property name e.g items, code, type etc.
370
-		 * 
371
-		 * @param mixed          $value    The property's value.
372
-		 * @param int            $ID       The discount's ID.
373
-		 * @param WPInv_Discount $discount The discount object.
374
-		 * @param string         $code     The discount's discount code.
375
-		 * @param array          $data     The discount's data array.
376
-		 */
377
-		return apply_filters( "wpinv_get_discount_{$key}", $value, $this->ID, $this, $this->data['code'], $this->data );
378
-
379
-	}
354
+        if ( $key == 'id' ) {
355
+            $key = 'ID';
356
+        }
357
+
358
+        if ( method_exists( $this, "get_$key") ) {
359
+            $value 	= call_user_func( array( $this, "get_$key" ) );
360
+        } else if( isset( $this->data[$key] ) ) {
361
+            $value 	= $this->data[$key];
362
+        } else {
363
+            $value = null;
364
+        }
365
+
366
+        /**
367
+         * Filters a discount's property value.
368
+         * 
369
+         * The dynamic part ($key) can be any property name e.g items, code, type etc.
370
+         * 
371
+         * @param mixed          $value    The property's value.
372
+         * @param int            $ID       The discount's ID.
373
+         * @param WPInv_Discount $discount The discount object.
374
+         * @param string         $code     The discount's discount code.
375
+         * @param array          $data     The discount's data array.
376
+         */
377
+        return apply_filters( "wpinv_get_discount_{$key}", $value, $this->ID, $this, $this->data['code'], $this->data );
378
+
379
+    }
380 380
 	
381
-	/**
382
-	 * Magic method for setting discount fields.
383
-	 *
384
-	 * This method does not update custom fields in the database.
385
-	 *
386
-	 * @since 1.0.15
387
-	 * @access public
388
-	 *
389
-	 */
390
-	public function __set( $key, $value ) {
381
+    /**
382
+     * Magic method for setting discount fields.
383
+     *
384
+     * This method does not update custom fields in the database.
385
+     *
386
+     * @since 1.0.15
387
+     * @access public
388
+     *
389
+     */
390
+    public function __set( $key, $value ) {
391 391
 		
392
-		if ( 'id' == strtolower( $key ) ) {
392
+        if ( 'id' == strtolower( $key ) ) {
393 393
 			
394
-			$this->ID = $value;
395
-			$this->data['ID'] = $value;
396
-			return;
394
+            $this->ID = $value;
395
+            $this->data['ID'] = $value;
396
+            return;
397 397
 			
398
-		}
398
+        }
399 399
 		
400
-		/**
401
-		 * Filters a discount's property value before it is saved.
402
-		 * 
403
-		 * 
404
-		 * 
405
-		 * The dynamic part ($key) can be any property name e.g items, code, type etc.
406
-		 * 
407
-		 * @param mixed          $value    The property's value.
408
-		 * @param int            $ID       The discount's ID.
409
-		 * @param WPInv_Discount $discount The discount object.
410
-		 * @param string         $code     The discount's discount code.
411
-		 * @param array          $data     The discount's data array.
412
-		 */
413
-		$value = apply_filters( "wpinv_set_discount_{$key}", $value, $this->ID, $this, $this->code, $this->data );
414
-
415
-		if( method_exists( $this, "set_$key") ) {
416
-			call_user_func( array( $this, "set_$key" ), $value );
417
-		} else {
418
-			$this->data[$key] = $value;
419
-		}
400
+        /**
401
+         * Filters a discount's property value before it is saved.
402
+         * 
403
+         * 
404
+         * 
405
+         * The dynamic part ($key) can be any property name e.g items, code, type etc.
406
+         * 
407
+         * @param mixed          $value    The property's value.
408
+         * @param int            $ID       The discount's ID.
409
+         * @param WPInv_Discount $discount The discount object.
410
+         * @param string         $code     The discount's discount code.
411
+         * @param array          $data     The discount's data array.
412
+         */
413
+        $value = apply_filters( "wpinv_set_discount_{$key}", $value, $this->ID, $this, $this->code, $this->data );
414
+
415
+        if( method_exists( $this, "set_$key") ) {
416
+            call_user_func( array( $this, "set_$key" ), $value );
417
+        } else {
418
+            $this->data[$key] = $value;
419
+        }
420 420
 		
421
-	}
421
+    }
422 422
 	
423
-	/**
424
-	 * Saves (or updates) a discount to the database
425
-	 *
426
-	 * @since 1.0.15
427
-	 * @access public
428
-	 * @return bool
429
-	 *
430
-	 */
431
-	public function save(){
423
+    /**
424
+     * Saves (or updates) a discount to the database
425
+     *
426
+     * @since 1.0.15
427
+     * @access public
428
+     * @return bool
429
+     *
430
+     */
431
+    public function save(){
432 432
 		
433
-		$data = self::sanitize_discount_data( $this->data );
433
+        $data = self::sanitize_discount_data( $this->data );
434 434
 
435
-		// Should we create a new post?
436
-		if( ! $data[ 'ID' ] ) {
435
+        // Should we create a new post?
436
+        if( ! $data[ 'ID' ] ) {
437 437
 
438
-			$id = wp_insert_post( array(
439
-				'post_status'           => $data['status'],
440
-				'post_type'             => 'wpi_discount',
441
-				'post_excerpt'          => $data['description'],
442
-			) );
438
+            $id = wp_insert_post( array(
439
+                'post_status'           => $data['status'],
440
+                'post_type'             => 'wpi_discount',
441
+                'post_excerpt'          => $data['description'],
442
+            ) );
443 443
 
444
-			if( empty( $id ) ) {
445
-				return false;
446
-			}
444
+            if( empty( $id ) ) {
445
+                return false;
446
+            }
447 447
 
448
-			$data[ 'ID' ] = (int) $id;
449
-			$this->ID = $data[ 'ID' ];
450
-			$this->data['ID'] = $data[ 'ID' ];
448
+            $data[ 'ID' ] = (int) $id;
449
+            $this->ID = $data[ 'ID' ];
450
+            $this->data['ID'] = $data[ 'ID' ];
451 451
 
452
-		} else {
453
-			$this->update_status( $data['status'] );
454
-		}
452
+        } else {
453
+            $this->update_status( $data['status'] );
454
+        }
455 455
 
456
-		$meta = apply_filters( 'wpinv_update_discount', $data, $this->ID, $this );
456
+        $meta = apply_filters( 'wpinv_update_discount', $data, $this->ID, $this );
457 457
 
458
-		do_action( 'wpinv_pre_update_discount', $meta, $this->ID, $this );
458
+        do_action( 'wpinv_pre_update_discount', $meta, $this->ID, $this );
459 459
 
460
-		foreach( wpinv_parse_list( 'ID date_created date_modified status description type_name' ) as $prop ) {
461
-			if ( isset( $meta[$prop] ) ) {
462
-				unset( $meta[$prop] );
463
-			}
464
-		}
460
+        foreach( wpinv_parse_list( 'ID date_created date_modified status description type_name' ) as $prop ) {
461
+            if ( isset( $meta[$prop] ) ) {
462
+                unset( $meta[$prop] );
463
+            }
464
+        }
465 465
 
466
-		if( isset( $meta['uses'] ) && empty( $meta['uses'] ) ) {
467
-			unset( $meta['uses'] );
468
-		}
466
+        if( isset( $meta['uses'] ) && empty( $meta['uses'] ) ) {
467
+            unset( $meta['uses'] );
468
+        }
469 469
 
470
-		// Save the metadata.
471
-		foreach( $meta as $key => $value ) {
472
-			update_post_meta( $this->ID, "_wpi_discount_$key", $value );
473
-		}
470
+        // Save the metadata.
471
+        foreach( $meta as $key => $value ) {
472
+            update_post_meta( $this->ID, "_wpi_discount_$key", $value );
473
+        }
474 474
 
475
-		$this->refresh();
475
+        $this->refresh();
476 476
 
477
-		do_action( 'wpinv_post_update_discount', $meta, $this->ID );
477
+        do_action( 'wpinv_post_update_discount', $meta, $this->ID );
478 478
 
479
-		return true;		
480
-	}
479
+        return true;		
480
+    }
481 481
 
482
-	/**
483
-	 * Refreshes the discount data.
484
-	 *
485
-	 * @since 1.0.15
486
-	 * @access public
487
-	 * @return bool
488
-	 *
489
-	 */
490
-	public function refresh(){
482
+    /**
483
+     * Refreshes the discount data.
484
+     *
485
+     * @since 1.0.15
486
+     * @access public
487
+     * @return bool
488
+     *
489
+     */
490
+    public function refresh(){
491 491
 
492
-		// Empty the cache for this discount.
493
-		wp_cache_delete( $this->ID, 'WPInv_Discounts' );
494
-		wp_cache_delete( $this->get( 'code' ), 'WPInv_Discount_Codes' );
492
+        // Empty the cache for this discount.
493
+        wp_cache_delete( $this->ID, 'WPInv_Discounts' );
494
+        wp_cache_delete( $this->get( 'code' ), 'WPInv_Discount_Codes' );
495 495
 
496
-		$data = self::get_data_by( 'id', $this->ID );
497
-		if( is_array( $data ) ) {
498
-			$this->init( $data );
499
-		} else {
500
-			$this->init( array() );
501
-		}
496
+        $data = self::get_data_by( 'id', $this->ID );
497
+        if( is_array( $data ) ) {
498
+            $this->init( $data );
499
+        } else {
500
+            $this->init( array() );
501
+        }
502 502
 
503
-	}
503
+    }
504 504
 
505
-	/**
506
-	 * Saves (or updates) a discount to the database
507
-	 *
508
-	 * @since 1.0.15
509
-	 * @access public
510
-	 * @return bool
511
-	 *
512
-	 */
513
-	public function update_status( $status = 'publish' ){
505
+    /**
506
+     * Saves (or updates) a discount to the database
507
+     *
508
+     * @since 1.0.15
509
+     * @access public
510
+     * @return bool
511
+     *
512
+     */
513
+    public function update_status( $status = 'publish' ){
514 514
 
515 515
 
516
-		if ( $this->exists() && $this->old_status != $status ) {
516
+        if ( $this->exists() && $this->old_status != $status ) {
517 517
 
518
-			do_action( 'wpinv_pre_update_discount_status', $this->ID, $this->old_status, $status );
519
-        	$updated = wp_update_post( array( 'ID' => $this->ID, 'post_status' => $status ) );
520
-			do_action( 'wpinv_post_update_discount_status', $this->ID, $this->old_status, $status );
518
+            do_action( 'wpinv_pre_update_discount_status', $this->ID, $this->old_status, $status );
519
+            $updated = wp_update_post( array( 'ID' => $this->ID, 'post_status' => $status ) );
520
+            do_action( 'wpinv_post_update_discount_status', $this->ID, $this->old_status, $status );
521 521
 
522
-			$this->refresh();
522
+            $this->refresh();
523 523
 
524
-			return $updated !== 0;
524
+            return $updated !== 0;
525 525
 			
526
-		}
526
+        }
527 527
 
528
-		return false;		
529
-	}
528
+        return false;		
529
+    }
530 530
 	
531 531
 	
532
-	/**
533
-	 * Checks whether a discount exists in the database or not
534
-	 * 
535
-	 * @since 1.0.15
536
-	 */
537
-	public function exists(){
538
-		return ! empty( $this->ID );
539
-	}
532
+    /**
533
+     * Checks whether a discount exists in the database or not
534
+     * 
535
+     * @since 1.0.15
536
+     */
537
+    public function exists(){
538
+        return ! empty( $this->ID );
539
+    }
540 540
 	
541
-	// Boolean methods
541
+    // Boolean methods
542 542
 	
543
-	/**
544
-	 * Checks the discount type.
545
-	 * 
546
-	 * 
547
-	 * @param  string $type the discount type to check against
548
-	 * @since 1.0.15
549
-	 * @return bool
550
-	 */
551
-	public function is_type( $type ) {
552
-		return $this->type == $type;
553
-	}
543
+    /**
544
+     * Checks the discount type.
545
+     * 
546
+     * 
547
+     * @param  string $type the discount type to check against
548
+     * @since 1.0.15
549
+     * @return bool
550
+     */
551
+    public function is_type( $type ) {
552
+        return $this->type == $type;
553
+    }
554 554
 	
555
-	/**
556
-	 * Checks whether the discount is published or not
557
-	 * 
558
-	 * @since 1.0.15
559
-	 * @return bool
560
-	 */
561
-	public function is_active() {
562
-		return $this->status == 'publish';
563
-	}
555
+    /**
556
+     * Checks whether the discount is published or not
557
+     * 
558
+     * @since 1.0.15
559
+     * @return bool
560
+     */
561
+    public function is_active() {
562
+        return $this->status == 'publish';
563
+    }
564 564
 	
565
-	/**
566
-	 * Checks whether the discount is has exided the usage limit or not
567
-	 * 
568
-	 * @since 1.0.15
569
-	 * @return bool
570
-	 */
571
-	public function has_exceeded_limit() {
572
-		if( empty( $this->max_uses ) || empty( $this->uses ) ) { 
573
-			return false ;
574
-		}
565
+    /**
566
+     * Checks whether the discount is has exided the usage limit or not
567
+     * 
568
+     * @since 1.0.15
569
+     * @return bool
570
+     */
571
+    public function has_exceeded_limit() {
572
+        if( empty( $this->max_uses ) || empty( $this->uses ) ) { 
573
+            return false ;
574
+        }
575 575
 		
576
-		$exceeded =  $this->uses >= $this->max_uses;
577
-		return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code );
578
-	}
576
+        $exceeded =  $this->uses >= $this->max_uses;
577
+        return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code );
578
+    }
579 579
 	
580
-	/**
581
-	 * Checks if the discount is expired
582
-	 * 
583
-	 * @since 1.0.15
584
-	 * @return bool
585
-	 */
586
-	public function is_expired() {
587
-		$expired = empty ( $this->expiration ) ? false : current_time( 'timestamp' ) > strtotime( $this->expiration );
588
-		return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code );
589
-	}
590
-
591
-	/**
592
-	 * Checks the discount start date.
593
-	 * 
594
-	 * @since 1.0.15
595
-	 * @return bool
596
-	 */
597
-	public function has_started() {
598
-		$started = empty ( $this->start ) ? true : current_time( 'timestamp' ) > strtotime( $this->start );
599
-		return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code );		
600
-	}
580
+    /**
581
+     * Checks if the discount is expired
582
+     * 
583
+     * @since 1.0.15
584
+     * @return bool
585
+     */
586
+    public function is_expired() {
587
+        $expired = empty ( $this->expiration ) ? false : current_time( 'timestamp' ) > strtotime( $this->expiration );
588
+        return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code );
589
+    }
590
+
591
+    /**
592
+     * Checks the discount start date.
593
+     * 
594
+     * @since 1.0.15
595
+     * @return bool
596
+     */
597
+    public function has_started() {
598
+        $started = empty ( $this->start ) ? true : current_time( 'timestamp' ) > strtotime( $this->start );
599
+        return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code );		
600
+    }
601 601
 	
602
-	/**
603
-	 * Check if a discount is valid for a given item id.
604
-	 *
605
-	 * @param  int|int[]  $item_ids
606
-	 * @since 1.0.15
607
-	 * @return boolean
608
-	 */
609
-	public function is_valid_for_items( $item_ids ) {
610
-
611
-		$item_ids = array_map( 'intval',  wpinv_parse_list( $item_ids ) );
612
-		$included = array_intersect( $item_ids, $this->items );
613
-		$excluded = array_intersect( $item_ids, $this->excluded_items );
614
-
615
-		if( ! empty( $this->excluded_items ) && ! empty( $excluded ) ) {
616
-			return false;
617
-		}
618
-
619
-		if( ! empty( $this->items ) && empty( $included ) ) {
620
-			return false;
621
-		}
622
-		return true;
623
-	}
602
+    /**
603
+     * Check if a discount is valid for a given item id.
604
+     *
605
+     * @param  int|int[]  $item_ids
606
+     * @since 1.0.15
607
+     * @return boolean
608
+     */
609
+    public function is_valid_for_items( $item_ids ) {
610
+
611
+        $item_ids = array_map( 'intval',  wpinv_parse_list( $item_ids ) );
612
+        $included = array_intersect( $item_ids, $this->items );
613
+        $excluded = array_intersect( $item_ids, $this->excluded_items );
614
+
615
+        if( ! empty( $this->excluded_items ) && ! empty( $excluded ) ) {
616
+            return false;
617
+        }
618
+
619
+        if( ! empty( $this->items ) && empty( $included ) ) {
620
+            return false;
621
+        }
622
+        return true;
623
+    }
624 624
 	
625
-	/**
626
-	 * Check if a discount is valid for the given amount
627
-	 *
628
-	 * @param  float  $amount The amount to check against
629
-	 * @since 1.0.15
630
-	 * @return boolean
631
-	 */
632
-	public function is_valid_for_amount( $amount ) {
633
-		return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
634
-	}
635
-
636
-	/**
637
-	 * Checks if the minimum amount is met
638
-	 *
639
-	 * @param  float  $amount The amount to check against
640
-	 * @since 1.0.15
641
-	 * @return boolean
642
-	 */
643
-	public function is_minimum_amount_met( $amount ) {
644
-		$amount = floatval( $amount );
645
-		$min_met= ! ( $this->min_total > 0 && $amount < $this->min_total );
646
-		return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount );
647
-	}
648
-
649
-	/**
650
-	 * Checks if the maximum amount is met
651
-	 *
652
-	 * @param  float  $amount The amount to check against
653
-	 * @since 1.0.15
654
-	 * @return boolean
655
-	 */
656
-	public function is_maximum_amount_met( $amount ) {
657
-		$amount = floatval( $amount );
658
-		$max_met= ! ( $this->max_total > 0 && $amount > $this->max_total );
659
-		return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount );
660
-	}
661
-
662
-	/**
663
-	 * Check if a discount is valid for the given user
664
-	 *
665
-	 * @param  int|string  $user
666
-	 * @since 1.0.15
667
-	 * @return boolean
668
-	 */
669
-	public function is_valid_for_user( $user ) {
670
-		global $wpi_checkout_id;
671
-
672
-		if( empty( $user ) || empty( $this->is_single_use ) ) {
673
-			return true;
674
-		}
675
-
676
-		$user_id = 0;
625
+    /**
626
+     * Check if a discount is valid for the given amount
627
+     *
628
+     * @param  float  $amount The amount to check against
629
+     * @since 1.0.15
630
+     * @return boolean
631
+     */
632
+    public function is_valid_for_amount( $amount ) {
633
+        return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
634
+    }
635
+
636
+    /**
637
+     * Checks if the minimum amount is met
638
+     *
639
+     * @param  float  $amount The amount to check against
640
+     * @since 1.0.15
641
+     * @return boolean
642
+     */
643
+    public function is_minimum_amount_met( $amount ) {
644
+        $amount = floatval( $amount );
645
+        $min_met= ! ( $this->min_total > 0 && $amount < $this->min_total );
646
+        return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount );
647
+    }
648
+
649
+    /**
650
+     * Checks if the maximum amount is met
651
+     *
652
+     * @param  float  $amount The amount to check against
653
+     * @since 1.0.15
654
+     * @return boolean
655
+     */
656
+    public function is_maximum_amount_met( $amount ) {
657
+        $amount = floatval( $amount );
658
+        $max_met= ! ( $this->max_total > 0 && $amount > $this->max_total );
659
+        return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount );
660
+    }
661
+
662
+    /**
663
+     * Check if a discount is valid for the given user
664
+     *
665
+     * @param  int|string  $user
666
+     * @since 1.0.15
667
+     * @return boolean
668
+     */
669
+    public function is_valid_for_user( $user ) {
670
+        global $wpi_checkout_id;
671
+
672
+        if( empty( $user ) || empty( $this->is_single_use ) ) {
673
+            return true;
674
+        }
675
+
676
+        $user_id = 0;
677 677
         if ( is_int( $user ) ) {
678 678
             $user_id = absint( $user );
679 679
         } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
@@ -682,168 +682,168 @@  discard block
 block discarded – undo
682 682
             $user_id = $user_data->ID;
683 683
         } else if ( absint( $user ) > 0 ) {
684 684
             $user_id = absint( $user );
685
-		}
685
+        }
686 686
 
687
-		if ( empty( $user_id ) ) {
688
-			return true;
689
-		}
687
+        if ( empty( $user_id ) ) {
688
+            return true;
689
+        }
690 690
 		
691
-		// Get all payments with matching user id
691
+        // Get all payments with matching user id
692 692
         $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false ) ); 
693
-		$code     = strtolower( $this->code );
693
+        $code     = strtolower( $this->code );
694 694
 
695
-		foreach ( $payments as $payment ) {
695
+        foreach ( $payments as $payment ) {
696 696
 
697
-			// Don't count discount used for current invoice checkout.
698
-			if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
699
-				continue;
700
-			}
697
+            // Don't count discount used for current invoice checkout.
698
+            if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
699
+                continue;
700
+            }
701 701
 			
702
-			if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
703
-				continue;
704
-			}
705
-
706
-			$discounts = $payment->get_discounts( true );
707
-			if ( empty( $discounts ) ) {
708
-				continue;
709
-			}
710
-
711
-			$discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) );
712
-			if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) {
713
-				return false;
714
-			}
715
-		}
716
-
717
-		return true;
718
-	}
719
-
720
-	/**
721
-	 * Deletes the discount from the database
722
-	 *
723
-	 * @since 1.0.15
724
-	 * @return boolean
725
-	 */
726
-	public function remove() {
727
-
728
-		if ( empty( $this->ID ) ) {
729
-			return true;
730
-		}
731
-
732
-		do_action( 'wpinv_pre_delete_discount', $this->ID, $this->data );
733
-		wp_cache_delete( $this->ID, 'WPInv_Discounts' );
734
-    	wp_delete_post( $this->ID, true );
735
-		wp_cache_delete( $this->code, 'WPInv_Discount_Codes' );
736
-    	do_action( 'wpinv_post_delete_discount', $this->ID, $this->data );
737
-
738
-		$this->ID = null;
739
-		$this->data['id'] = null;
740
-		return true;
741
-	}
742
-
743
-	/**
744
-	 * Increases a discount's usage.
745
-	 *
746
-	 * @since 1.0.15
747
-	 * @param int $by The number of usages to increas by.
748
-	 * @return int
749
-	 */
750
-	public function increase_usage( $by = 1 ) {
751
-
752
-		$this->uses = $this->uses + $by;
753
-
754
-		if( $this->uses  < 0 ) {
755
-			$this->uses = 0;
756
-			update_post_meta( $this->ID, "_wpi_discount_uses", 0 );
757
-		}
758
-
759
-		$this->save();
760
-
761
-		if( $by > 0 ) {
762
-			do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, $by );
763
-		} else {
764
-			do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) );
765
-		}
702
+            if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
703
+                continue;
704
+            }
705
+
706
+            $discounts = $payment->get_discounts( true );
707
+            if ( empty( $discounts ) ) {
708
+                continue;
709
+            }
710
+
711
+            $discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) );
712
+            if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) {
713
+                return false;
714
+            }
715
+        }
716
+
717
+        return true;
718
+    }
719
+
720
+    /**
721
+     * Deletes the discount from the database
722
+     *
723
+     * @since 1.0.15
724
+     * @return boolean
725
+     */
726
+    public function remove() {
727
+
728
+        if ( empty( $this->ID ) ) {
729
+            return true;
730
+        }
731
+
732
+        do_action( 'wpinv_pre_delete_discount', $this->ID, $this->data );
733
+        wp_cache_delete( $this->ID, 'WPInv_Discounts' );
734
+        wp_delete_post( $this->ID, true );
735
+        wp_cache_delete( $this->code, 'WPInv_Discount_Codes' );
736
+        do_action( 'wpinv_post_delete_discount', $this->ID, $this->data );
737
+
738
+        $this->ID = null;
739
+        $this->data['id'] = null;
740
+        return true;
741
+    }
742
+
743
+    /**
744
+     * Increases a discount's usage.
745
+     *
746
+     * @since 1.0.15
747
+     * @param int $by The number of usages to increas by.
748
+     * @return int
749
+     */
750
+    public function increase_usage( $by = 1 ) {
751
+
752
+        $this->uses = $this->uses + $by;
753
+
754
+        if( $this->uses  < 0 ) {
755
+            $this->uses = 0;
756
+            update_post_meta( $this->ID, "_wpi_discount_uses", 0 );
757
+        }
758
+
759
+        $this->save();
760
+
761
+        if( $by > 0 ) {
762
+            do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, $by );
763
+        } else {
764
+            do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) );
765
+        }
766 766
 		
767
-		return $this->uses;
768
-	}
769
-
770
-	/**
771
-	 * Retrieves discount data
772
-	 *
773
-	 * @since 1.0.15
774
-	 * @return array
775
-	 */
776
-	public function get_data() {
777
-		$return = array();
778
-		foreach( array_keys( $this->data ) as $key ) {
779
-			$return[ $key ] = $this->get( $key );
780
-		}
781
-		return $return;
782
-	}
783
-
784
-	/**
785
-	 * Retrieves discount data as json
786
-	 *
787
-	 * @since 1.0.15
788
-	 * @return string|false
789
-	 */
790
-	public function get_data_as_json() {
791
-		return wp_json_encode( $this->get_data() );
792
-	}
793
-
794
-	/**
795
-	 * Checks if a discount can only be used once per user.
796
-	 *
797
-	 * @since 1.0.15
798
-	 * @return bool
799
-	 */
800
-	public function get_is_single_use() {
801
-		return (bool) apply_filters( 'wpinv_is_discount_single_use', $this->data['is_single_use'], $this->ID, $this, $this->code );
802
-	}
803
-
804
-	/**
805
-	 * Checks if a discount is recurring.
806
-	 *
807
-	 * @since 1.0.15
808
-	 * @return bool
809
-	 */
810
-	public function get_is_recurring() {
811
-		return (bool) apply_filters( 'wpinv_is_discount_recurring', $this->data['is_recurring'], $this->ID, $this->code, $this );
812
-	}
813
-
814
-	/**
815
-	 * Returns a discount's included items.
816
-	 *
817
-	 * @since 1.0.15
818
-	 * @return array
819
-	 */
820
-	public function get_items() {
821
-		return wpinv_parse_list( apply_filters( 'wpinv_get_discount_item_reqs', $this->data['items'], $this->ID, $this, $this->code ) );
822
-	}
823
-
824
-	/**
825
-	 * Returns a discount's discounted amount.
826
-	 *
827
-	 * @since 1.0.15
828
-	 * @return float
829
-	 */
830
-	public function get_discounted_amount( $amount ) {
831
-
832
-		if ( $this->type == 'flat' ) {
767
+        return $this->uses;
768
+    }
769
+
770
+    /**
771
+     * Retrieves discount data
772
+     *
773
+     * @since 1.0.15
774
+     * @return array
775
+     */
776
+    public function get_data() {
777
+        $return = array();
778
+        foreach( array_keys( $this->data ) as $key ) {
779
+            $return[ $key ] = $this->get( $key );
780
+        }
781
+        return $return;
782
+    }
783
+
784
+    /**
785
+     * Retrieves discount data as json
786
+     *
787
+     * @since 1.0.15
788
+     * @return string|false
789
+     */
790
+    public function get_data_as_json() {
791
+        return wp_json_encode( $this->get_data() );
792
+    }
793
+
794
+    /**
795
+     * Checks if a discount can only be used once per user.
796
+     *
797
+     * @since 1.0.15
798
+     * @return bool
799
+     */
800
+    public function get_is_single_use() {
801
+        return (bool) apply_filters( 'wpinv_is_discount_single_use', $this->data['is_single_use'], $this->ID, $this, $this->code );
802
+    }
803
+
804
+    /**
805
+     * Checks if a discount is recurring.
806
+     *
807
+     * @since 1.0.15
808
+     * @return bool
809
+     */
810
+    public function get_is_recurring() {
811
+        return (bool) apply_filters( 'wpinv_is_discount_recurring', $this->data['is_recurring'], $this->ID, $this->code, $this );
812
+    }
813
+
814
+    /**
815
+     * Returns a discount's included items.
816
+     *
817
+     * @since 1.0.15
818
+     * @return array
819
+     */
820
+    public function get_items() {
821
+        return wpinv_parse_list( apply_filters( 'wpinv_get_discount_item_reqs', $this->data['items'], $this->ID, $this, $this->code ) );
822
+    }
823
+
824
+    /**
825
+     * Returns a discount's discounted amount.
826
+     *
827
+     * @since 1.0.15
828
+     * @return float
829
+     */
830
+    public function get_discounted_amount( $amount ) {
831
+
832
+        if ( $this->type == 'flat' ) {
833 833
             $discount = $this->amount;
834
-		} else {
834
+        } else {
835 835
             $discount = ( $amount * ( $this->amount / 100 ) );
836
-		}
836
+        }
837 837
 
838
-		if ( $discount < 0 ) {
839
-			$discount = 0;
840
-		}
838
+        if ( $discount < 0 ) {
839
+            $discount = 0;
840
+        }
841 841
 
842
-		if ( $discount > $amount ) {
843
-			$discount = $amount;
844
-		}
842
+        if ( $discount > $amount ) {
843
+            $discount = $amount;
844
+        }
845 845
 
846
-		return apply_filters( 'wpinv_discount_total_discount_amount', $discount, $amount, $this );
847
-	}
846
+        return apply_filters( 'wpinv_discount_total_discount_amount', $discount, $amount, $this );
847
+    }
848 848
 	
849 849
 }
Please login to merge, or discard this patch.
Spacing   +190 added lines, -190 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since   1.0.15
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Discount class.
@@ -63,45 +63,45 @@  discard block
 block discarded – undo
63 63
 	 * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
64 64
 	 * @since 1.0.15
65 65
 	 */
66
-	public function __construct( $discount = array() ) {
66
+	public function __construct($discount = array()) {
67 67
         
68 68
         // If the discount is an instance of this class...
69
-		if ( $discount instanceof WPInv_Discount ) {
70
-			$this->init( $discount->data );
69
+		if ($discount instanceof WPInv_Discount) {
70
+			$this->init($discount->data);
71 71
 			return;
72 72
         }
73 73
         
74 74
         // If the discount is an array of discount details...
75
-        if ( is_array( $discount ) ) {
76
-			$this->init( $discount );
75
+        if (is_array($discount)) {
76
+			$this->init($discount);
77 77
 			return;
78 78
 		}
79 79
 		
80 80
 		// Try fetching the discount by its post id.
81 81
 		$data = false;
82 82
 		
83
-		if ( ! empty( $discount ) && is_numeric( $discount ) ) {
84
-			$discount = absint( $discount );
85
-			$data = self::get_data_by( 'id', $discount );
83
+		if (!empty($discount) && is_numeric($discount)) {
84
+			$discount = absint($discount);
85
+			$data = self::get_data_by('id', $discount);
86 86
 		}
87 87
 
88
-		if ( is_array( $data ) ) {
89
-			$this->init( $data );
88
+		if (is_array($data)) {
89
+			$this->init($data);
90 90
 			return;
91 91
 		}
92 92
 		
93 93
 		// Try fetching the discount by its discount code.
94
-		if ( ! empty( $discount ) && is_string( $discount ) ) {
95
-			$data = self::get_data_by( 'discount_code', $discount );
94
+		if (!empty($discount) && is_string($discount)) {
95
+			$data = self::get_data_by('discount_code', $discount);
96 96
 		}
97 97
 
98
-		if ( is_array( $data ) ) {
99
-			$this->init( $data );
98
+		if (is_array($data)) {
99
+			$this->init($data);
100 100
 			return;
101 101
 		} 
102 102
 		
103 103
 		// If we are here then the discount does not exist.
104
-		$this->init( array() );
104
+		$this->init(array());
105 105
 	}
106 106
 	
107 107
 	/**
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 * @since 1.0.15
111 111
 	 * @param array $data An array containing the discount's data
112 112
 	 */
113
-	public function init( $data ) {
114
-		$data       	  = self::sanitize_discount_data( $data );
113
+	public function init($data) {
114
+		$data       	  = self::sanitize_discount_data($data);
115 115
 		$this->data 	  = $data;
116 116
 		$this->old_status = $data['status'];
117 117
 		$this->ID   	  = $data['ID'];
@@ -127,50 +127,50 @@  discard block
 block discarded – undo
127 127
 	 * @since 1.0.15
128 128
 	 * @return array|bool array of discount details on success. False otherwise.
129 129
 	 */
130
-	public static function get_data_by( $field, $value ) {
130
+	public static function get_data_by($field, $value) {
131 131
 
132
-		if ( 'id' == strtolower( $field ) ) {
132
+		if ('id' == strtolower($field)) {
133 133
 			// Make sure the value is numeric to avoid casting objects, for example,
134 134
 			// to int 1.
135
-			if ( ! is_numeric( $value ) )
135
+			if (!is_numeric($value))
136 136
 				return false;
137
-			$value = intval( $value );
138
-			if ( $value < 1 )
137
+			$value = intval($value);
138
+			if ($value < 1)
139 139
 				return false;
140 140
 		}
141 141
 
142
-		if ( ! $value || ! is_string( $field ) ) {
142
+		if (!$value || !is_string($field)) {
143 143
 			return false;
144 144
 		}
145 145
 		
146
-		$field = trim( $field );
146
+		$field = trim($field);
147 147
 
148 148
 		// prepare query args
149
-		switch ( strtolower( $field ) ) {
149
+		switch (strtolower($field)) {
150 150
 			case 'id':
151 151
 				$discount_id = $value;
152
-				$args		 = array( 'include' => array( $value ) );
152
+				$args = array('include' => array($value));
153 153
 				break;
154 154
 			case 'discount_code':
155 155
 			case 'code':
156
-				$value       = trim( $value );
157
-				$discount_id = wp_cache_get( $value, 'WPInv_Discount_Codes' );
158
-				$args		 = array( 'meta_key' => '_wpi_discount_code', 'meta_value' => $value );
156
+				$value       = trim($value);
157
+				$discount_id = wp_cache_get($value, 'WPInv_Discount_Codes');
158
+				$args = array('meta_key' => '_wpi_discount_code', 'meta_value' => $value);
159 159
 				break;
160 160
 			case 'name':
161 161
 				$discount_id = 0;
162
-				$args		 = array( 'name' => trim( $value ) );
162
+				$args		 = array('name' => trim($value));
163 163
 				break;
164 164
 			default:
165
-				$args		 = apply_filters( "wpinv_discount_get_data_by_{$field}_args", null, $value );
166
-				if ( ! is_array( $args ) ) {
167
-					return apply_filters( "wpinv_discount_get_data_by_$field", false, $value );
165
+				$args		 = apply_filters("wpinv_discount_get_data_by_{$field}_args", null, $value);
166
+				if (!is_array($args)) {
167
+					return apply_filters("wpinv_discount_get_data_by_$field", false, $value);
168 168
 				}
169 169
 
170 170
 		}
171 171
 
172 172
 		// Check if there is a cached value.
173
-		if ( ! empty( $discount_id ) && $discount = wp_cache_get( (int) $discount_id, 'WPInv_Discounts' ) ) {
173
+		if (!empty($discount_id) && $discount = wp_cache_get((int) $discount_id, 'WPInv_Discounts')) {
174 174
 			return $discount;
175 175
 		}
176 176
 
@@ -179,13 +179,13 @@  discard block
 block discarded – undo
179 179
 			array(
180 180
 				'post_type'      => 'wpi_discount',
181 181
 				'posts_per_page' => 1,
182
-				'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
182
+				'post_status'    => array('publish', 'pending', 'draft', 'expired')
183 183
 			)
184 184
 		);
185 185
 
186
-		$discount = get_posts( $args );
186
+		$discount = get_posts($args);
187 187
 				
188
-		if( empty( $discount ) ) {
188
+		if (empty($discount)) {
189 189
 			return false;
190 190
 		}
191 191
 
@@ -194,31 +194,31 @@  discard block
 block discarded – undo
194 194
 		// Prepare the return data.
195 195
 		$return = array(
196 196
             'ID'                          => $discount->ID,
197
-            'code'                        => get_post_meta( $discount->ID, '_wpi_discount_code', true ),
198
-            'amount'                      => get_post_meta( $discount->ID, '_wpi_discount_amount', true ),
197
+            'code'                        => get_post_meta($discount->ID, '_wpi_discount_code', true),
198
+            'amount'                      => get_post_meta($discount->ID, '_wpi_discount_amount', true),
199 199
             'date_created'                => $discount->post_date,
200 200
 			'date_modified'               => $discount->post_modified,
201 201
 			'status'               		  => $discount->post_status,
202
-			'start'                  	  => get_post_meta( $discount->ID, '_wpi_discount_start', true ),
203
-            'expiration'                  => get_post_meta( $discount->ID, '_wpi_discount_expiration', true ),
204
-            'type'               		  => get_post_meta( $discount->ID, '_wpi_discount_type', true ),
202
+			'start'                  	  => get_post_meta($discount->ID, '_wpi_discount_start', true),
203
+            'expiration'                  => get_post_meta($discount->ID, '_wpi_discount_expiration', true),
204
+            'type'               		  => get_post_meta($discount->ID, '_wpi_discount_type', true),
205 205
             'description'                 => $discount->post_excerpt,
206
-            'uses'                 		  => get_post_meta( $discount->ID, '_wpi_discount_uses', true ),
207
-            'is_single_use'               => get_post_meta( $discount->ID, '_wpi_discount_is_single_use', true ),
208
-            'items'              	      => get_post_meta( $discount->ID, '_wpi_discount_items', true ),
209
-            'excluded_items'              => get_post_meta( $discount->ID, '_wpi_discount_excluded_items', true ),
210
-            'max_uses'                    => get_post_meta( $discount->ID, '_wpi_discount_max_uses', true ),
211
-            'is_recurring'                => get_post_meta( $discount->ID, '_wpi_discount_is_recurring', true ),
212
-            'min_total'                   => get_post_meta( $discount->ID, '_wpi_discount_min_total', true ),
213
-            'max_total'                   => get_post_meta( $discount->ID, '_wpi_discount_max_total', true ),
206
+            'uses'                 		  => get_post_meta($discount->ID, '_wpi_discount_uses', true),
207
+            'is_single_use'               => get_post_meta($discount->ID, '_wpi_discount_is_single_use', true),
208
+            'items'              	      => get_post_meta($discount->ID, '_wpi_discount_items', true),
209
+            'excluded_items'              => get_post_meta($discount->ID, '_wpi_discount_excluded_items', true),
210
+            'max_uses'                    => get_post_meta($discount->ID, '_wpi_discount_max_uses', true),
211
+            'is_recurring'                => get_post_meta($discount->ID, '_wpi_discount_is_recurring', true),
212
+            'min_total'                   => get_post_meta($discount->ID, '_wpi_discount_min_total', true),
213
+            'max_total'                   => get_post_meta($discount->ID, '_wpi_discount_max_total', true),
214 214
         );
215 215
 		
216
-		$return = self::sanitize_discount_data( $return );
217
-		$return = apply_filters( 'wpinv_discount_properties', $return );
216
+		$return = self::sanitize_discount_data($return);
217
+		$return = apply_filters('wpinv_discount_properties', $return);
218 218
 
219 219
 		// Update the cache with our data
220
-		wp_cache_add( $discount->ID, $return, 'WPInv_Discounts' );
221
-		wp_cache_add( $return['code'], $discount->ID, 'WPInv_Discount_Codes' );
220
+		wp_cache_add($discount->ID, $return, 'WPInv_Discounts');
221
+		wp_cache_add($return['code'], $discount->ID, 'WPInv_Discount_Codes');
222 222
 
223 223
 		return $return;
224 224
 	}
@@ -232,9 +232,9 @@  discard block
 block discarded – undo
232 232
 	 *
233 233
 	 * @return array the sanitized data
234 234
 	 */
235
-	public static function sanitize_discount_data( $data ) {
235
+	public static function sanitize_discount_data($data) {
236 236
 		
237
-		$allowed_discount_types = array_keys( wpinv_get_discount_types() );
237
+		$allowed_discount_types = array_keys(wpinv_get_discount_types());
238 238
 		
239 239
 		$return = array(
240 240
             'ID'                          => null,
@@ -259,60 +259,60 @@  discard block
 block discarded – undo
259 259
 		
260 260
 				
261 261
 		// Arrays only please.
262
-		if ( ! is_array( $data ) ) {
262
+		if (!is_array($data)) {
263 263
             return $return;
264 264
         }
265 265
 
266 266
 		// If an id is provided, ensure it is a valid discount.
267
-        if ( ! empty( $data['ID'] ) && ( ! is_numeric( $data['ID'] ) || 'wpi_discount' !== get_post_type( $data['ID'] ) ) ) {
267
+        if (!empty($data['ID']) && (!is_numeric($data['ID']) || 'wpi_discount' !== get_post_type($data['ID']))) {
268 268
             return $return;
269 269
 		}
270 270
 
271
-        $return = array_merge( $return, $data );
271
+        $return = array_merge($return, $data);
272 272
 
273 273
         // Sanitize some keys.
274
-        $return['amount']         = wpinv_sanitize_amount( $return['amount'] );
274
+        $return['amount'] = wpinv_sanitize_amount($return['amount']);
275 275
 		$return['is_single_use']  = (bool) $return['is_single_use'];
276 276
 		$return['is_recurring']   = (bool) $return['is_recurring'];
277 277
 		$return['uses']	          = (int) $return['uses'];
278 278
 		$return['max_uses']	      = (int) $return['max_uses'];
279
-		$return['min_total'] 	  = wpinv_sanitize_amount( $return['min_total'] );
280
-        $return['max_total'] 	  = wpinv_sanitize_amount( $return['max_total'] );
279
+		$return['min_total'] = wpinv_sanitize_amount($return['min_total']);
280
+        $return['max_total'] = wpinv_sanitize_amount($return['max_total']);
281 281
 
282 282
 		// Trim all values.
283
-		$return = wpinv_clean( $return );
283
+		$return = wpinv_clean($return);
284 284
 		
285 285
 		// Ensure the discount type is supported.
286
-        if ( ! in_array( $return['type'], $allowed_discount_types, true ) ) {
286
+        if (!in_array($return['type'], $allowed_discount_types, true)) {
287 287
             $return['type'] = 'percent';
288 288
 		}
289
-		$return['type_name'] = wpinv_get_discount_type_name( $return['type'] );
289
+		$return['type_name'] = wpinv_get_discount_type_name($return['type']);
290 290
 		
291 291
 		// Do not offer more than a 100% discount.
292
-		if ( $return['type'] == 'percent' && (float) $return['amount'] > 100 ) {
292
+		if ($return['type'] == 'percent' && (float) $return['amount'] > 100) {
293 293
 			$return['amount'] = 100;
294 294
 		}
295 295
 
296 296
 		// Format dates.
297
-		foreach( wpinv_parse_list( 'date_created date_modified expiration start') as $prop ) {
298
-			if( ! empty( $return[$prop] ) ) {
299
-				$return[$prop]      = date_i18n( 'Y-m-d H:i:s', strtotime( $return[$prop] ) );
297
+		foreach (wpinv_parse_list('date_created date_modified expiration start') as $prop) {
298
+			if (!empty($return[$prop])) {
299
+				$return[$prop] = date_i18n('Y-m-d H:i:s', strtotime($return[$prop]));
300 300
 			}
301 301
 		}
302 302
 
303 303
 		// Formart items.
304
-		foreach( array( 'excluded_items', 'items' ) as $prop ) {
304
+		foreach (array('excluded_items', 'items') as $prop) {
305 305
 
306
-			if( ! empty( $return[$prop] ) ) {
306
+			if (!empty($return[$prop])) {
307 307
 				// Ensure that the property is an array of non-empty integers.
308
-				$return[$prop]      = array_filter( array_map( 'intval', wpinv_parse_list( $return[$prop] ) ) );
308
+				$return[$prop]      = array_filter(array_map('intval', wpinv_parse_list($return[$prop])));
309 309
 			} else {
310 310
 				$return[$prop]      = array();
311 311
 			}
312 312
 
313 313
 		}
314 314
 		
315
-		return apply_filters( 'wpinv_sanitize_discount_data', $return, $data );
315
+		return apply_filters('wpinv_sanitize_discount_data', $return, $data);
316 316
 	}
317 317
 	
318 318
 	/**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 *
324 324
 	 * @return bool Whether the given discount field is set.
325 325
 	 */
326
-	public function __isset( $key ){
327
-		return isset( $this->data[$key] ) || method_exists( $this, "get_$key");
326
+	public function __isset($key) {
327
+		return isset($this->data[$key]) || method_exists($this, "get_$key");
328 328
 	}
329 329
 	
330 330
 	/**
@@ -336,8 +336,8 @@  discard block
 block discarded – undo
336 336
 	 * @param string $key Discount data to retrieve
337 337
 	 * @return mixed Value of the given discount property (if set).
338 338
 	 */
339
-	public function __get( $key ) {
340
-		return $this->get( $key );
339
+	public function __get($key) {
340
+		return $this->get($key);
341 341
 	}
342 342
 
343 343
 	/**
@@ -349,15 +349,15 @@  discard block
 block discarded – undo
349 349
 	 * @param string $key Discount data to retrieve
350 350
 	 * @return mixed Value of the given discount property (if set).
351 351
 	 */
352
-	public function get( $key ) {
352
+	public function get($key) {
353 353
 		
354
-		if ( $key == 'id' ) {
354
+		if ($key == 'id') {
355 355
 			$key = 'ID';
356 356
 		}
357 357
 
358
-		if ( method_exists( $this, "get_$key") ) {
359
-			$value 	= call_user_func( array( $this, "get_$key" ) );
360
-		} else if( isset( $this->data[$key] ) ) {
358
+		if (method_exists($this, "get_$key")) {
359
+			$value 	= call_user_func(array($this, "get_$key"));
360
+		} else if (isset($this->data[$key])) {
361 361
 			$value 	= $this->data[$key];
362 362
 		} else {
363 363
 			$value = null;
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
 		 * @param string         $code     The discount's discount code.
375 375
 		 * @param array          $data     The discount's data array.
376 376
 		 */
377
-		return apply_filters( "wpinv_get_discount_{$key}", $value, $this->ID, $this, $this->data['code'], $this->data );
377
+		return apply_filters("wpinv_get_discount_{$key}", $value, $this->ID, $this, $this->data['code'], $this->data);
378 378
 
379 379
 	}
380 380
 	
@@ -387,9 +387,9 @@  discard block
 block discarded – undo
387 387
 	 * @access public
388 388
 	 *
389 389
 	 */
390
-	public function __set( $key, $value ) {
390
+	public function __set($key, $value) {
391 391
 		
392
-		if ( 'id' == strtolower( $key ) ) {
392
+		if ('id' == strtolower($key)) {
393 393
 			
394 394
 			$this->ID = $value;
395 395
 			$this->data['ID'] = $value;
@@ -410,10 +410,10 @@  discard block
 block discarded – undo
410 410
 		 * @param string         $code     The discount's discount code.
411 411
 		 * @param array          $data     The discount's data array.
412 412
 		 */
413
-		$value = apply_filters( "wpinv_set_discount_{$key}", $value, $this->ID, $this, $this->code, $this->data );
413
+		$value = apply_filters("wpinv_set_discount_{$key}", $value, $this->ID, $this, $this->code, $this->data);
414 414
 
415
-		if( method_exists( $this, "set_$key") ) {
416
-			call_user_func( array( $this, "set_$key" ), $value );
415
+		if (method_exists($this, "set_$key")) {
416
+			call_user_func(array($this, "set_$key"), $value);
417 417
 		} else {
418 418
 			$this->data[$key] = $value;
419 419
 		}
@@ -428,53 +428,53 @@  discard block
 block discarded – undo
428 428
 	 * @return bool
429 429
 	 *
430 430
 	 */
431
-	public function save(){
431
+	public function save() {
432 432
 		
433
-		$data = self::sanitize_discount_data( $this->data );
433
+		$data = self::sanitize_discount_data($this->data);
434 434
 
435 435
 		// Should we create a new post?
436
-		if( ! $data[ 'ID' ] ) {
436
+		if (!$data['ID']) {
437 437
 
438
-			$id = wp_insert_post( array(
438
+			$id = wp_insert_post(array(
439 439
 				'post_status'           => $data['status'],
440 440
 				'post_type'             => 'wpi_discount',
441 441
 				'post_excerpt'          => $data['description'],
442
-			) );
442
+			));
443 443
 
444
-			if( empty( $id ) ) {
444
+			if (empty($id)) {
445 445
 				return false;
446 446
 			}
447 447
 
448
-			$data[ 'ID' ] = (int) $id;
449
-			$this->ID = $data[ 'ID' ];
450
-			$this->data['ID'] = $data[ 'ID' ];
448
+			$data['ID'] = (int) $id;
449
+			$this->ID = $data['ID'];
450
+			$this->data['ID'] = $data['ID'];
451 451
 
452 452
 		} else {
453
-			$this->update_status( $data['status'] );
453
+			$this->update_status($data['status']);
454 454
 		}
455 455
 
456
-		$meta = apply_filters( 'wpinv_update_discount', $data, $this->ID, $this );
456
+		$meta = apply_filters('wpinv_update_discount', $data, $this->ID, $this);
457 457
 
458
-		do_action( 'wpinv_pre_update_discount', $meta, $this->ID, $this );
458
+		do_action('wpinv_pre_update_discount', $meta, $this->ID, $this);
459 459
 
460
-		foreach( wpinv_parse_list( 'ID date_created date_modified status description type_name' ) as $prop ) {
461
-			if ( isset( $meta[$prop] ) ) {
462
-				unset( $meta[$prop] );
460
+		foreach (wpinv_parse_list('ID date_created date_modified status description type_name') as $prop) {
461
+			if (isset($meta[$prop])) {
462
+				unset($meta[$prop]);
463 463
 			}
464 464
 		}
465 465
 
466
-		if( isset( $meta['uses'] ) && empty( $meta['uses'] ) ) {
467
-			unset( $meta['uses'] );
466
+		if (isset($meta['uses']) && empty($meta['uses'])) {
467
+			unset($meta['uses']);
468 468
 		}
469 469
 
470 470
 		// Save the metadata.
471
-		foreach( $meta as $key => $value ) {
472
-			update_post_meta( $this->ID, "_wpi_discount_$key", $value );
471
+		foreach ($meta as $key => $value) {
472
+			update_post_meta($this->ID, "_wpi_discount_$key", $value);
473 473
 		}
474 474
 
475 475
 		$this->refresh();
476 476
 
477
-		do_action( 'wpinv_post_update_discount', $meta, $this->ID );
477
+		do_action('wpinv_post_update_discount', $meta, $this->ID);
478 478
 
479 479
 		return true;		
480 480
 	}
@@ -487,17 +487,17 @@  discard block
 block discarded – undo
487 487
 	 * @return bool
488 488
 	 *
489 489
 	 */
490
-	public function refresh(){
490
+	public function refresh() {
491 491
 
492 492
 		// Empty the cache for this discount.
493
-		wp_cache_delete( $this->ID, 'WPInv_Discounts' );
494
-		wp_cache_delete( $this->get( 'code' ), 'WPInv_Discount_Codes' );
493
+		wp_cache_delete($this->ID, 'WPInv_Discounts');
494
+		wp_cache_delete($this->get('code'), 'WPInv_Discount_Codes');
495 495
 
496
-		$data = self::get_data_by( 'id', $this->ID );
497
-		if( is_array( $data ) ) {
498
-			$this->init( $data );
496
+		$data = self::get_data_by('id', $this->ID);
497
+		if (is_array($data)) {
498
+			$this->init($data);
499 499
 		} else {
500
-			$this->init( array() );
500
+			$this->init(array());
501 501
 		}
502 502
 
503 503
 	}
@@ -510,14 +510,14 @@  discard block
 block discarded – undo
510 510
 	 * @return bool
511 511
 	 *
512 512
 	 */
513
-	public function update_status( $status = 'publish' ){
513
+	public function update_status($status = 'publish') {
514 514
 
515 515
 
516
-		if ( $this->exists() && $this->old_status != $status ) {
516
+		if ($this->exists() && $this->old_status != $status) {
517 517
 
518
-			do_action( 'wpinv_pre_update_discount_status', $this->ID, $this->old_status, $status );
519
-        	$updated = wp_update_post( array( 'ID' => $this->ID, 'post_status' => $status ) );
520
-			do_action( 'wpinv_post_update_discount_status', $this->ID, $this->old_status, $status );
518
+			do_action('wpinv_pre_update_discount_status', $this->ID, $this->old_status, $status);
519
+        	$updated = wp_update_post(array('ID' => $this->ID, 'post_status' => $status));
520
+			do_action('wpinv_post_update_discount_status', $this->ID, $this->old_status, $status);
521 521
 
522 522
 			$this->refresh();
523 523
 
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
 	 * 
535 535
 	 * @since 1.0.15
536 536
 	 */
537
-	public function exists(){
538
-		return ! empty( $this->ID );
537
+	public function exists() {
538
+		return !empty($this->ID);
539 539
 	}
540 540
 	
541 541
 	// Boolean methods
@@ -548,7 +548,7 @@  discard block
 block discarded – undo
548 548
 	 * @since 1.0.15
549 549
 	 * @return bool
550 550
 	 */
551
-	public function is_type( $type ) {
551
+	public function is_type($type) {
552 552
 		return $this->type == $type;
553 553
 	}
554 554
 	
@@ -569,12 +569,12 @@  discard block
 block discarded – undo
569 569
 	 * @return bool
570 570
 	 */
571 571
 	public function has_exceeded_limit() {
572
-		if( empty( $this->max_uses ) || empty( $this->uses ) ) { 
573
-			return false ;
572
+		if (empty($this->max_uses) || empty($this->uses)) { 
573
+			return false;
574 574
 		}
575 575
 		
576
-		$exceeded =  $this->uses >= $this->max_uses;
577
-		return apply_filters( 'wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code );
576
+		$exceeded = $this->uses >= $this->max_uses;
577
+		return apply_filters('wpinv_is_discount_maxed_out', $exceeded, $this->ID, $this, $this->code);
578 578
 	}
579 579
 	
580 580
 	/**
@@ -584,8 +584,8 @@  discard block
 block discarded – undo
584 584
 	 * @return bool
585 585
 	 */
586 586
 	public function is_expired() {
587
-		$expired = empty ( $this->expiration ) ? false : current_time( 'timestamp' ) > strtotime( $this->expiration );
588
-		return apply_filters( 'wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code );
587
+		$expired = empty ($this->expiration) ? false : current_time('timestamp') > strtotime($this->expiration);
588
+		return apply_filters('wpinv_is_discount_expired', $expired, $this->ID, $this, $this->code);
589 589
 	}
590 590
 
591 591
 	/**
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
 	 * @return bool
596 596
 	 */
597 597
 	public function has_started() {
598
-		$started = empty ( $this->start ) ? true : current_time( 'timestamp' ) > strtotime( $this->start );
599
-		return apply_filters( 'wpinv_is_discount_started', $started, $this->ID, $this, $this->code );		
598
+		$started = empty ($this->start) ? true : current_time('timestamp') > strtotime($this->start);
599
+		return apply_filters('wpinv_is_discount_started', $started, $this->ID, $this, $this->code);		
600 600
 	}
601 601
 	
602 602
 	/**
@@ -606,17 +606,17 @@  discard block
 block discarded – undo
606 606
 	 * @since 1.0.15
607 607
 	 * @return boolean
608 608
 	 */
609
-	public function is_valid_for_items( $item_ids ) {
609
+	public function is_valid_for_items($item_ids) {
610 610
 
611
-		$item_ids = array_map( 'intval',  wpinv_parse_list( $item_ids ) );
612
-		$included = array_intersect( $item_ids, $this->items );
613
-		$excluded = array_intersect( $item_ids, $this->excluded_items );
611
+		$item_ids = array_map('intval', wpinv_parse_list($item_ids));
612
+		$included = array_intersect($item_ids, $this->items);
613
+		$excluded = array_intersect($item_ids, $this->excluded_items);
614 614
 
615
-		if( ! empty( $this->excluded_items ) && ! empty( $excluded ) ) {
615
+		if (!empty($this->excluded_items) && !empty($excluded)) {
616 616
 			return false;
617 617
 		}
618 618
 
619
-		if( ! empty( $this->items ) && empty( $included ) ) {
619
+		if (!empty($this->items) && empty($included)) {
620 620
 			return false;
621 621
 		}
622 622
 		return true;
@@ -629,8 +629,8 @@  discard block
 block discarded – undo
629 629
 	 * @since 1.0.15
630 630
 	 * @return boolean
631 631
 	 */
632
-	public function is_valid_for_amount( $amount ) {
633
-		return $this->is_minimum_amount_met( $amount ) && $this->is_maximum_amount_met( $amount );
632
+	public function is_valid_for_amount($amount) {
633
+		return $this->is_minimum_amount_met($amount) && $this->is_maximum_amount_met($amount);
634 634
 	}
635 635
 
636 636
 	/**
@@ -640,10 +640,10 @@  discard block
 block discarded – undo
640 640
 	 * @since 1.0.15
641 641
 	 * @return boolean
642 642
 	 */
643
-	public function is_minimum_amount_met( $amount ) {
644
-		$amount = floatval( $amount );
645
-		$min_met= ! ( $this->min_total > 0 && $amount < $this->min_total );
646
-		return apply_filters( 'wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount );
643
+	public function is_minimum_amount_met($amount) {
644
+		$amount = floatval($amount);
645
+		$min_met = !($this->min_total > 0 && $amount < $this->min_total);
646
+		return apply_filters('wpinv_is_discount_min_met', $min_met, $this->ID, $this, $this->code, $amount);
647 647
 	}
648 648
 
649 649
 	/**
@@ -653,10 +653,10 @@  discard block
 block discarded – undo
653 653
 	 * @since 1.0.15
654 654
 	 * @return boolean
655 655
 	 */
656
-	public function is_maximum_amount_met( $amount ) {
657
-		$amount = floatval( $amount );
658
-		$max_met= ! ( $this->max_total > 0 && $amount > $this->max_total );
659
-		return apply_filters( 'wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount );
656
+	public function is_maximum_amount_met($amount) {
657
+		$amount = floatval($amount);
658
+		$max_met = !($this->max_total > 0 && $amount > $this->max_total);
659
+		return apply_filters('wpinv_is_discount_max_met', $max_met, $this->ID, $this, $this->code, $amount);
660 660
 	}
661 661
 
662 662
 	/**
@@ -666,50 +666,50 @@  discard block
 block discarded – undo
666 666
 	 * @since 1.0.15
667 667
 	 * @return boolean
668 668
 	 */
669
-	public function is_valid_for_user( $user ) {
669
+	public function is_valid_for_user($user) {
670 670
 		global $wpi_checkout_id;
671 671
 
672
-		if( empty( $user ) || empty( $this->is_single_use ) ) {
672
+		if (empty($user) || empty($this->is_single_use)) {
673 673
 			return true;
674 674
 		}
675 675
 
676 676
 		$user_id = 0;
677
-        if ( is_int( $user ) ) {
678
-            $user_id = absint( $user );
679
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
677
+        if (is_int($user)) {
678
+            $user_id = absint($user);
679
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
680 680
             $user_id = $user_data->ID;
681
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
681
+        } else if ($user_data = get_user_by('login', $user)) {
682 682
             $user_id = $user_data->ID;
683
-        } else if ( absint( $user ) > 0 ) {
684
-            $user_id = absint( $user );
683
+        } else if (absint($user) > 0) {
684
+            $user_id = absint($user);
685 685
 		}
686 686
 
687
-		if ( empty( $user_id ) ) {
687
+		if (empty($user_id)) {
688 688
 			return true;
689 689
 		}
690 690
 		
691 691
 		// Get all payments with matching user id
692
-        $payments = wpinv_get_invoices( array( 'user' => $user_id, 'limit' => false ) ); 
693
-		$code     = strtolower( $this->code );
692
+        $payments = wpinv_get_invoices(array('user' => $user_id, 'limit' => false)); 
693
+		$code = strtolower($this->code);
694 694
 
695
-		foreach ( $payments as $payment ) {
695
+		foreach ($payments as $payment) {
696 696
 
697 697
 			// Don't count discount used for current invoice checkout.
698
-			if ( ! empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
698
+			if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
699 699
 				continue;
700 700
 			}
701 701
 			
702
-			if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
702
+			if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
703 703
 				continue;
704 704
 			}
705 705
 
706
-			$discounts = $payment->get_discounts( true );
707
-			if ( empty( $discounts ) ) {
706
+			$discounts = $payment->get_discounts(true);
707
+			if (empty($discounts)) {
708 708
 				continue;
709 709
 			}
710 710
 
711
-			$discounts = array_map( 'strtolower', wpinv_parse_list( $discounts ) );
712
-			if ( ! empty( $discounts ) && in_array( $code, $discounts ) ) {
711
+			$discounts = array_map('strtolower', wpinv_parse_list($discounts));
712
+			if (!empty($discounts) && in_array($code, $discounts)) {
713 713
 				return false;
714 714
 			}
715 715
 		}
@@ -725,15 +725,15 @@  discard block
 block discarded – undo
725 725
 	 */
726 726
 	public function remove() {
727 727
 
728
-		if ( empty( $this->ID ) ) {
728
+		if (empty($this->ID)) {
729 729
 			return true;
730 730
 		}
731 731
 
732
-		do_action( 'wpinv_pre_delete_discount', $this->ID, $this->data );
733
-		wp_cache_delete( $this->ID, 'WPInv_Discounts' );
734
-    	wp_delete_post( $this->ID, true );
735
-		wp_cache_delete( $this->code, 'WPInv_Discount_Codes' );
736
-    	do_action( 'wpinv_post_delete_discount', $this->ID, $this->data );
732
+		do_action('wpinv_pre_delete_discount', $this->ID, $this->data);
733
+		wp_cache_delete($this->ID, 'WPInv_Discounts');
734
+    	wp_delete_post($this->ID, true);
735
+		wp_cache_delete($this->code, 'WPInv_Discount_Codes');
736
+    	do_action('wpinv_post_delete_discount', $this->ID, $this->data);
737 737
 
738 738
 		$this->ID = null;
739 739
 		$this->data['id'] = null;
@@ -747,21 +747,21 @@  discard block
 block discarded – undo
747 747
 	 * @param int $by The number of usages to increas by.
748 748
 	 * @return int
749 749
 	 */
750
-	public function increase_usage( $by = 1 ) {
750
+	public function increase_usage($by = 1) {
751 751
 
752 752
 		$this->uses = $this->uses + $by;
753 753
 
754
-		if( $this->uses  < 0 ) {
754
+		if ($this->uses < 0) {
755 755
 			$this->uses = 0;
756
-			update_post_meta( $this->ID, "_wpi_discount_uses", 0 );
756
+			update_post_meta($this->ID, "_wpi_discount_uses", 0);
757 757
 		}
758 758
 
759 759
 		$this->save();
760 760
 
761
-		if( $by > 0 ) {
762
-			do_action( 'wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, $by );
761
+		if ($by > 0) {
762
+			do_action('wpinv_discount_increase_use_count', $this->uses, $this->ID, $this->code, $by);
763 763
 		} else {
764
-			do_action( 'wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint( $by ) );
764
+			do_action('wpinv_discount_decrease_use_count', $this->uses, $this->ID, $this->code, absint($by));
765 765
 		}
766 766
 		
767 767
 		return $this->uses;
@@ -775,8 +775,8 @@  discard block
 block discarded – undo
775 775
 	 */
776 776
 	public function get_data() {
777 777
 		$return = array();
778
-		foreach( array_keys( $this->data ) as $key ) {
779
-			$return[ $key ] = $this->get( $key );
778
+		foreach (array_keys($this->data) as $key) {
779
+			$return[$key] = $this->get($key);
780 780
 		}
781 781
 		return $return;
782 782
 	}
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 * @return string|false
789 789
 	 */
790 790
 	public function get_data_as_json() {
791
-		return wp_json_encode( $this->get_data() );
791
+		return wp_json_encode($this->get_data());
792 792
 	}
793 793
 
794 794
 	/**
@@ -798,7 +798,7 @@  discard block
 block discarded – undo
798 798
 	 * @return bool
799 799
 	 */
800 800
 	public function get_is_single_use() {
801
-		return (bool) apply_filters( 'wpinv_is_discount_single_use', $this->data['is_single_use'], $this->ID, $this, $this->code );
801
+		return (bool) apply_filters('wpinv_is_discount_single_use', $this->data['is_single_use'], $this->ID, $this, $this->code);
802 802
 	}
803 803
 
804 804
 	/**
@@ -808,7 +808,7 @@  discard block
 block discarded – undo
808 808
 	 * @return bool
809 809
 	 */
810 810
 	public function get_is_recurring() {
811
-		return (bool) apply_filters( 'wpinv_is_discount_recurring', $this->data['is_recurring'], $this->ID, $this->code, $this );
811
+		return (bool) apply_filters('wpinv_is_discount_recurring', $this->data['is_recurring'], $this->ID, $this->code, $this);
812 812
 	}
813 813
 
814 814
 	/**
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 	 * @return array
819 819
 	 */
820 820
 	public function get_items() {
821
-		return wpinv_parse_list( apply_filters( 'wpinv_get_discount_item_reqs', $this->data['items'], $this->ID, $this, $this->code ) );
821
+		return wpinv_parse_list(apply_filters('wpinv_get_discount_item_reqs', $this->data['items'], $this->ID, $this, $this->code));
822 822
 	}
823 823
 
824 824
 	/**
@@ -827,23 +827,23 @@  discard block
 block discarded – undo
827 827
 	 * @since 1.0.15
828 828
 	 * @return float
829 829
 	 */
830
-	public function get_discounted_amount( $amount ) {
830
+	public function get_discounted_amount($amount) {
831 831
 
832
-		if ( $this->type == 'flat' ) {
832
+		if ($this->type == 'flat') {
833 833
             $discount = $this->amount;
834 834
 		} else {
835
-            $discount = ( $amount * ( $this->amount / 100 ) );
835
+            $discount = ($amount * ($this->amount / 100));
836 836
 		}
837 837
 
838
-		if ( $discount < 0 ) {
838
+		if ($discount < 0) {
839 839
 			$discount = 0;
840 840
 		}
841 841
 
842
-		if ( $discount > $amount ) {
842
+		if ($discount > $amount) {
843 843
 			$discount = $amount;
844 844
 		}
845 845
 
846
-		return apply_filters( 'wpinv_discount_total_discount_amount', $discount, $amount, $this );
846
+		return apply_filters('wpinv_discount_total_discount_amount', $discount, $amount, $this);
847 847
 	}
848 848
 	
849 849
 }
Please login to merge, or discard this patch.