This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
1 | <?php |
||||
2 | if ( ! defined( 'ABSPATH' ) ) { |
||||
3 | exit; |
||||
4 | } |
||||
5 | |||||
6 | /** |
||||
7 | * Payment form class |
||||
8 | * |
||||
9 | */ |
||||
10 | class GetPaid_Payment_Form extends GetPaid_Data { |
||||
11 | |||||
12 | /** |
||||
13 | * Which data store to load. |
||||
14 | * |
||||
15 | * @var string |
||||
16 | */ |
||||
17 | protected $data_store_name = 'payment_form'; |
||||
18 | |||||
19 | /** |
||||
20 | * This is the name of this object type. |
||||
21 | * |
||||
22 | * @var string |
||||
23 | */ |
||||
24 | protected $object_type = 'payment_form'; |
||||
25 | |||||
26 | /** |
||||
27 | * Form Data array. This is the core form data exposed in APIs. |
||||
28 | * |
||||
29 | * @since 1.0.19 |
||||
30 | * @var array |
||||
31 | */ |
||||
32 | protected $data = array( |
||||
33 | 'status' => 'draft', |
||||
34 | 'version' => '', |
||||
35 | 'date_created' => null, |
||||
36 | 'date_modified' => null, |
||||
37 | 'name' => '', |
||||
38 | 'author' => 1, |
||||
39 | 'elements' => null, |
||||
40 | 'items' => null, |
||||
41 | 'earned' => 0, |
||||
42 | 'refunded' => 0, |
||||
43 | 'cancelled' => 0, |
||||
44 | 'failed' => 0, |
||||
45 | ); |
||||
46 | |||||
47 | /** |
||||
48 | * Stores meta in cache for future reads. |
||||
49 | * |
||||
50 | * A group must be set to to enable caching. |
||||
51 | * |
||||
52 | * @var string |
||||
53 | */ |
||||
54 | protected $cache_group = 'getpaid_forms'; |
||||
55 | |||||
56 | /** |
||||
57 | * Stores a reference to the invoice if the form is for an invoice.. |
||||
58 | * |
||||
59 | * @var WPInv_Invoice |
||||
60 | */ |
||||
61 | public $invoice = 0; |
||||
62 | |||||
63 | /** |
||||
64 | * Stores a reference to the original WP_Post object |
||||
65 | * |
||||
66 | * @var WP_Post |
||||
67 | */ |
||||
68 | protected $post = null; |
||||
69 | |||||
70 | /** |
||||
71 | * Get the form if ID is passed, otherwise the form is new and empty. |
||||
72 | * |
||||
73 | * @param int|object|GetPaid_Payment_Form|WP_Post $form Form to read. |
||||
74 | */ |
||||
75 | public function __construct( $form = 0 ) { |
||||
76 | parent::__construct( $form ); |
||||
77 | |||||
78 | if ( is_numeric( $form ) && $form > 0 ) { |
||||
79 | $this->set_id( $form ); |
||||
80 | } elseif ( $form instanceof self ) { |
||||
81 | |||||
82 | $this->set_id( $form->get_id() ); |
||||
83 | $this->invoice = $form->invoice; |
||||
84 | |||||
85 | } elseif ( ! empty( $form->ID ) ) { |
||||
86 | $this->set_id( $form->ID ); |
||||
87 | } else { |
||||
88 | $this->set_object_read( true ); |
||||
89 | } |
||||
90 | |||||
91 | // Load the datastore. |
||||
92 | $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
||||
93 | |||||
94 | if ( $this->get_id() > 0 ) { |
||||
95 | $this->post = get_post( $this->get_id() ); |
||||
0 ignored issues
–
show
|
|||||
96 | $this->data_store->read( $this ); |
||||
97 | } |
||||
98 | |||||
99 | } |
||||
100 | |||||
101 | /* |
||||
102 | |-------------------------------------------------------------------------- |
||||
103 | | CRUD methods |
||||
104 | |-------------------------------------------------------------------------- |
||||
105 | | |
||||
106 | | Methods which create, read, update and delete items from the database. |
||||
107 | | |
||||
108 | */ |
||||
109 | |||||
110 | /* |
||||
111 | |-------------------------------------------------------------------------- |
||||
112 | | Getters |
||||
113 | |-------------------------------------------------------------------------- |
||||
114 | */ |
||||
115 | |||||
116 | /** |
||||
117 | * Get plugin version when the form was created. |
||||
118 | * |
||||
119 | * @since 1.0.19 |
||||
120 | * @param string $context View or edit context. |
||||
121 | * @return string |
||||
122 | */ |
||||
123 | public function get_version( $context = 'view' ) { |
||||
124 | return $this->get_prop( 'version', $context ); |
||||
125 | } |
||||
126 | |||||
127 | /** |
||||
128 | * Get date when the form was created. |
||||
129 | * |
||||
130 | * @since 1.0.19 |
||||
131 | * @param string $context View or edit context. |
||||
132 | * @return string |
||||
133 | */ |
||||
134 | public function get_date_created( $context = 'view' ) { |
||||
135 | return $this->get_prop( 'date_created', $context ); |
||||
136 | } |
||||
137 | |||||
138 | /** |
||||
139 | * Get GMT date when the form was created. |
||||
140 | * |
||||
141 | * @since 1.0.19 |
||||
142 | * @param string $context View or edit context. |
||||
143 | * @return string |
||||
144 | */ |
||||
145 | public function get_date_created_gmt( $context = 'view' ) { |
||||
146 | $date = $this->get_date_created( $context ); |
||||
147 | |||||
148 | if ( $date ) { |
||||
149 | $date = get_gmt_from_date( $date ); |
||||
150 | } |
||||
151 | return $date; |
||||
152 | } |
||||
153 | |||||
154 | /** |
||||
155 | * Get date when the form was last modified. |
||||
156 | * |
||||
157 | * @since 1.0.19 |
||||
158 | * @param string $context View or edit context. |
||||
159 | * @return string |
||||
160 | */ |
||||
161 | public function get_date_modified( $context = 'view' ) { |
||||
162 | return $this->get_prop( 'date_modified', $context ); |
||||
163 | } |
||||
164 | |||||
165 | /** |
||||
166 | * Get GMT date when the form was last modified. |
||||
167 | * |
||||
168 | * @since 1.0.19 |
||||
169 | * @param string $context View or edit context. |
||||
170 | * @return string |
||||
171 | */ |
||||
172 | public function get_date_modified_gmt( $context = 'view' ) { |
||||
173 | $date = $this->get_date_modified( $context ); |
||||
174 | |||||
175 | if ( $date ) { |
||||
176 | $date = get_gmt_from_date( $date ); |
||||
177 | } |
||||
178 | return $date; |
||||
179 | } |
||||
180 | |||||
181 | /** |
||||
182 | * Get the form name. |
||||
183 | * |
||||
184 | * @since 1.0.19 |
||||
185 | * @param string $context View or edit context. |
||||
186 | * @return string |
||||
187 | */ |
||||
188 | public function get_name( $context = 'view' ) { |
||||
189 | return $this->get_prop( 'name', $context ); |
||||
190 | } |
||||
191 | |||||
192 | /** |
||||
193 | * Alias of self::get_name(). |
||||
194 | * |
||||
195 | * @since 1.0.19 |
||||
196 | * @param string $context View or edit context. |
||||
197 | * @return string |
||||
198 | */ |
||||
199 | public function get_title( $context = 'view' ) { |
||||
200 | return $this->get_name( $context ); |
||||
201 | } |
||||
202 | |||||
203 | /** |
||||
204 | * Get the owner of the form. |
||||
205 | * |
||||
206 | * @since 1.0.19 |
||||
207 | * @param string $context View or edit context. |
||||
208 | * @return int |
||||
209 | */ |
||||
210 | public function get_author( $context = 'view' ) { |
||||
211 | return (int) $this->get_prop( 'author', $context ); |
||||
212 | } |
||||
213 | |||||
214 | /** |
||||
215 | * Get the elements that make up the form. |
||||
216 | * |
||||
217 | * @since 1.0.19 |
||||
218 | * @param string $context View or edit context. |
||||
219 | * @return array |
||||
220 | */ |
||||
221 | public function get_elements( $context = 'view' ) { |
||||
222 | $elements = $this->get_prop( 'elements', $context ); |
||||
223 | |||||
224 | if ( empty( $elements ) || ! is_array( $elements ) ) { |
||||
225 | return wpinv_get_data( 'sample-payment-form' ); |
||||
226 | } |
||||
227 | |||||
228 | // Ensure that all required elements exist. |
||||
229 | $_elements = array(); |
||||
230 | foreach ( $elements as $element ) { |
||||
231 | |||||
232 | if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) { |
||||
233 | |||||
234 | $_elements[] = array( |
||||
235 | 'text' => __( 'Select Payment Method', 'invoicing' ), |
||||
236 | 'id' => 'gtscicd', |
||||
237 | 'name' => 'gtscicd', |
||||
238 | 'type' => 'gateway_select', |
||||
239 | 'premade' => true, |
||||
240 | |||||
241 | ); |
||||
242 | |||||
243 | } |
||||
244 | |||||
245 | $_elements[] = $element; |
||||
246 | |||||
247 | } |
||||
248 | |||||
249 | return $_elements; |
||||
250 | } |
||||
251 | |||||
252 | /** |
||||
253 | * Get the items sold via the form. |
||||
254 | * |
||||
255 | * @since 1.0.19 |
||||
256 | * @param string $context View or edit context. |
||||
257 | * @param string $return objects or arrays. |
||||
258 | * @return GetPaid_Form_Item[] |
||||
259 | */ |
||||
260 | public function get_items( $context = 'view', $return = 'objects' ) { |
||||
261 | $items = $this->get_prop( 'items', $context ); |
||||
262 | |||||
263 | if ( empty( $items ) || ! is_array( $items ) ) { |
||||
264 | $items = wpinv_get_data( 'sample-payment-form-items' ); |
||||
265 | } |
||||
266 | |||||
267 | // Convert the items. |
||||
268 | $prepared = array(); |
||||
269 | |||||
270 | foreach ( $items as $key => $value ) { |
||||
271 | |||||
272 | // Form items. |
||||
273 | if ( $value instanceof GetPaid_Form_Item ) { |
||||
274 | |||||
275 | if ( $value->can_purchase() ) { |
||||
276 | $prepared[] = $value; |
||||
277 | } |
||||
278 | |||||
279 | continue; |
||||
280 | |||||
281 | } |
||||
282 | |||||
283 | // $item_id => $quantity (buy buttons) |
||||
284 | if ( is_numeric( $key ) && is_numeric( $value ) ) { |
||||
285 | $item = new GetPaid_Form_Item( $key ); |
||||
286 | |||||
287 | if ( $item->can_purchase() ) { |
||||
288 | |||||
289 | $value = (float) $value; |
||||
290 | $item->set_quantity( $value ); |
||||
291 | if ( 0 == $value ) { |
||||
292 | $item->set_quantity( 1 ); |
||||
293 | $item->set_allow_quantities( true ); |
||||
294 | } |
||||
295 | |||||
296 | $prepared[] = $item; |
||||
297 | } |
||||
298 | |||||
299 | continue; |
||||
300 | } |
||||
301 | |||||
302 | // Items saved via payment forms editor. |
||||
303 | if ( is_array( $value ) && isset( $value['id'] ) ) { |
||||
304 | |||||
305 | $item = new GetPaid_Form_Item( $value['id'] ); |
||||
306 | |||||
307 | if ( ! $item->can_purchase() ) { |
||||
308 | continue; |
||||
309 | } |
||||
310 | |||||
311 | // Sub-total (Cart items). |
||||
312 | if ( isset( $value['subtotal'] ) ) { |
||||
313 | $item->set_price( $value['subtotal'] ); |
||||
314 | } |
||||
315 | |||||
316 | if ( isset( $value['quantity'] ) ) { |
||||
317 | $item->set_quantity( $value['quantity'] ); |
||||
318 | } |
||||
319 | |||||
320 | if ( isset( $value['allow_quantities'] ) ) { |
||||
321 | $item->set_allow_quantities( $value['allow_quantities'] ); |
||||
322 | } |
||||
323 | |||||
324 | if ( isset( $value['required'] ) ) { |
||||
325 | $item->set_is_required( $value['required'] ); |
||||
326 | } |
||||
327 | |||||
328 | if ( isset( $value['description'] ) ) { |
||||
329 | $item->set_custom_description( $value['description'] ); |
||||
330 | } |
||||
331 | |||||
332 | $prepared[] = $item; |
||||
333 | continue; |
||||
334 | |||||
335 | } |
||||
336 | |||||
337 | // $item_id => array( 'price' => 10 ) (item variations) |
||||
338 | if ( is_numeric( $key ) && is_array( $value ) ) { |
||||
339 | $item = new GetPaid_Form_Item( $key ); |
||||
340 | |||||
341 | if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) { |
||||
342 | $item->set_price( $value['price'] ); |
||||
343 | } |
||||
344 | |||||
345 | if ( $item->can_purchase() ) { |
||||
346 | $prepared[] = $item; |
||||
347 | } |
||||
348 | |||||
349 | continue; |
||||
350 | } |
||||
351 | } |
||||
352 | |||||
353 | if ( 'objects' == $return && 'view' == $context ) { |
||||
354 | return $prepared; |
||||
355 | } |
||||
356 | |||||
357 | $items = array(); |
||||
358 | foreach ( $prepared as $item ) { |
||||
359 | $items[] = $item->prepare_data_for_use(); |
||||
360 | } |
||||
361 | |||||
362 | return $items; |
||||
363 | } |
||||
364 | |||||
365 | /** |
||||
366 | * Get a single item belonging to the form. |
||||
367 | * |
||||
368 | * @since 1.0.19 |
||||
369 | * @param int $item_id The item id to return. |
||||
370 | * @return GetPaid_Form_Item|bool |
||||
371 | */ |
||||
372 | public function get_item( $item_id ) { |
||||
373 | |||||
374 | if ( empty( $item_id ) || ! is_numeric( $item_id ) ) { |
||||
375 | return false; |
||||
376 | } |
||||
377 | |||||
378 | foreach ( $this->get_items() as $item ) { |
||||
379 | if ( $item->get_id() == (int) $item_id ) { |
||||
380 | return $item; |
||||
381 | } |
||||
382 | } |
||||
383 | |||||
384 | return false; |
||||
385 | |||||
386 | } |
||||
387 | |||||
388 | /** |
||||
389 | * Gets a single element. |
||||
390 | * |
||||
391 | * @since 1.0.19 |
||||
392 | * @param string $element_type The element type to return. |
||||
393 | * @return array|bool |
||||
394 | */ |
||||
395 | public function get_element_type( $element_type ) { |
||||
396 | |||||
397 | if ( empty( $element_type ) || ! is_scalar( $element_type ) ) { |
||||
398 | return false; |
||||
399 | } |
||||
400 | |||||
401 | foreach ( $this->get_prop( 'elements' ) as $element ) { |
||||
402 | |||||
403 | if ( $element['type'] === $element_type ) { |
||||
404 | return $element; |
||||
405 | } |
||||
406 | } |
||||
407 | |||||
408 | return false; |
||||
409 | |||||
410 | } |
||||
411 | |||||
412 | /** |
||||
413 | * Get the total amount earned via this form. |
||||
414 | * |
||||
415 | * @since 1.0.19 |
||||
416 | * @param string $context View or edit context. |
||||
417 | * @return float |
||||
418 | */ |
||||
419 | public function get_earned( $context = 'view' ) { |
||||
420 | return $this->get_prop( 'earned', $context ); |
||||
421 | } |
||||
422 | |||||
423 | /** |
||||
424 | * Get the total amount refunded via this form. |
||||
425 | * |
||||
426 | * @since 1.0.19 |
||||
427 | * @param string $context View or edit context. |
||||
428 | * @return float |
||||
429 | */ |
||||
430 | public function get_refunded( $context = 'view' ) { |
||||
431 | return $this->get_prop( 'refunded', $context ); |
||||
432 | } |
||||
433 | |||||
434 | /** |
||||
435 | * Get the total amount cancelled via this form. |
||||
436 | * |
||||
437 | * @since 1.0.19 |
||||
438 | * @param string $context View or edit context. |
||||
439 | * @return float |
||||
440 | */ |
||||
441 | public function get_cancelled( $context = 'view' ) { |
||||
442 | return $this->get_prop( 'cancelled', $context ); |
||||
443 | } |
||||
444 | |||||
445 | /** |
||||
446 | * Get the total amount failed via this form. |
||||
447 | * |
||||
448 | * @since 1.0.19 |
||||
449 | * @param string $context View or edit context. |
||||
450 | * @return float |
||||
451 | */ |
||||
452 | public function get_failed( $context = 'view' ) { |
||||
453 | return $this->get_prop( 'failed', $context ); |
||||
454 | } |
||||
455 | |||||
456 | /** |
||||
457 | * Get the currency. |
||||
458 | * |
||||
459 | * @since 1.0.19 |
||||
460 | * @param string $context View or edit context. |
||||
461 | * @return string |
||||
462 | */ |
||||
463 | public function get_currency() { |
||||
464 | $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency(); |
||||
465 | return apply_filters( 'getpaid-payment-form-currency', $currency, $this ); |
||||
466 | } |
||||
467 | |||||
468 | /* |
||||
469 | |-------------------------------------------------------------------------- |
||||
470 | | Setters |
||||
471 | |-------------------------------------------------------------------------- |
||||
472 | | |
||||
473 | | Functions for setting order data. These should not update anything in the |
||||
474 | | database itself and should only change what is stored in the class |
||||
475 | | object. |
||||
476 | */ |
||||
477 | |||||
478 | /** |
||||
479 | * Set plugin version when the item was created. |
||||
480 | * |
||||
481 | * @since 1.0.19 |
||||
482 | */ |
||||
483 | public function set_version( $value ) { |
||||
484 | $this->set_prop( 'version', $value ); |
||||
485 | } |
||||
486 | |||||
487 | /** |
||||
488 | * Set date when the item was created. |
||||
489 | * |
||||
490 | * @since 1.0.19 |
||||
491 | * @param string $value Value to set. |
||||
492 | * @return bool Whether or not the date was set. |
||||
493 | */ |
||||
494 | public function set_date_created( $value ) { |
||||
495 | $date = strtotime( $value ); |
||||
496 | |||||
497 | if ( $date ) { |
||||
498 | $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) ); |
||||
499 | return true; |
||||
500 | } |
||||
501 | |||||
502 | return false; |
||||
503 | |||||
504 | } |
||||
505 | |||||
506 | /** |
||||
507 | * Set date when the item was last modified. |
||||
508 | * |
||||
509 | * @since 1.0.19 |
||||
510 | * @param string $value Value to set. |
||||
511 | * @return bool Whether or not the date was set. |
||||
512 | */ |
||||
513 | public function set_date_modified( $value ) { |
||||
514 | $date = strtotime( $value ); |
||||
515 | |||||
516 | if ( $date ) { |
||||
517 | $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) ); |
||||
518 | return true; |
||||
519 | } |
||||
520 | |||||
521 | return false; |
||||
522 | |||||
523 | } |
||||
524 | |||||
525 | /** |
||||
526 | * Set the item name. |
||||
527 | * |
||||
528 | * @since 1.0.19 |
||||
529 | * @param string $value New name. |
||||
530 | */ |
||||
531 | public function set_name( $value ) { |
||||
532 | $this->set_prop( 'name', sanitize_text_field( $value ) ); |
||||
533 | } |
||||
534 | |||||
535 | /** |
||||
536 | * Alias of self::set_name(). |
||||
537 | * |
||||
538 | * @since 1.0.19 |
||||
539 | * @param string $value New name. |
||||
540 | */ |
||||
541 | public function set_title( $value ) { |
||||
542 | $this->set_name( $value ); |
||||
543 | } |
||||
544 | |||||
545 | /** |
||||
546 | * Set the owner of the item. |
||||
547 | * |
||||
548 | * @since 1.0.19 |
||||
549 | * @param int $value New author. |
||||
550 | */ |
||||
551 | public function set_author( $value ) { |
||||
552 | $this->set_prop( 'author', (int) $value ); |
||||
553 | } |
||||
554 | |||||
555 | /** |
||||
556 | * Set the form elements. |
||||
557 | * |
||||
558 | * @since 1.0.19 |
||||
559 | * @sinve 2.3.4 Array values sanitized. |
||||
560 | * @param array $value Form elements. |
||||
561 | */ |
||||
562 | public function set_elements( $value ) { |
||||
563 | if ( is_array( $value ) ) { |
||||
0 ignored issues
–
show
|
|||||
564 | $this->set_prop( 'elements', wp_kses_post_deep( $value ) ); |
||||
565 | } |
||||
566 | } |
||||
567 | |||||
568 | /** |
||||
569 | * Sanitize array values. |
||||
570 | * |
||||
571 | * @param $value |
||||
572 | * |
||||
573 | * @return mixed |
||||
574 | */ |
||||
575 | public function sanitize_array_values( $value ) { |
||||
576 | |||||
577 | // sanitize |
||||
578 | if ( ! empty( $value ) ) { |
||||
579 | |||||
580 | foreach ( $value as $key => $val_arr ) { |
||||
581 | |||||
582 | if ( is_array( $val_arr ) ) { |
||||
583 | // check if we have sub array items. |
||||
584 | $sub_arr = array(); |
||||
585 | foreach ( $val_arr as $key2 => $val2 ) { |
||||
586 | if ( is_array( $val2 ) ) { |
||||
587 | $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 ); |
||||
588 | unset( $val_arr[ $key ][ $key2 ] ); |
||||
589 | } |
||||
590 | } |
||||
591 | |||||
592 | // we allow some html in description so we sanitize it separately. |
||||
593 | $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : ''; |
||||
594 | |||||
595 | // sanitize array elements |
||||
596 | $value[ $key ] = array_map( 'sanitize_text_field', $val_arr ); |
||||
597 | |||||
598 | // add back the description if set |
||||
599 | if ( isset( $val_arr['description'] ) ) { |
||||
600 | $value[ $key ]['description'] = $help_text;} |
||||
601 | |||||
602 | // add back sub array items after its been sanitized. |
||||
603 | if ( ! empty( $sub_arr ) ) { |
||||
604 | $value[ $key ] = array_merge( $value[ $key ], $sub_arr ); |
||||
605 | } |
||||
606 | } |
||||
607 | } |
||||
608 | } |
||||
609 | |||||
610 | return $value; |
||||
611 | } |
||||
612 | |||||
613 | /** |
||||
614 | * Set the form items. |
||||
615 | * |
||||
616 | * @since 1.0.19 |
||||
617 | * @param array $value Form elements. |
||||
618 | */ |
||||
619 | public function set_items( $value ) { |
||||
620 | if ( is_array( $value ) ) { |
||||
0 ignored issues
–
show
|
|||||
621 | $this->set_prop( 'items', $value ); |
||||
622 | } |
||||
623 | } |
||||
624 | |||||
625 | /** |
||||
626 | * Set the total amount earned via this form. |
||||
627 | * |
||||
628 | * @since 1.0.19 |
||||
629 | * @param float $value Amount earned. |
||||
630 | */ |
||||
631 | public function set_earned( $value ) { |
||||
632 | $value = max( (float) $value, 0 ); |
||||
633 | $this->set_prop( 'earned', $value ); |
||||
634 | } |
||||
635 | |||||
636 | /** |
||||
637 | * Set the total amount refunded via this form. |
||||
638 | * |
||||
639 | * @since 1.0.19 |
||||
640 | * @param float $value Amount refunded. |
||||
641 | */ |
||||
642 | public function set_refunded( $value ) { |
||||
643 | $value = max( (float) $value, 0 ); |
||||
644 | $this->set_prop( 'refunded', $value ); |
||||
645 | } |
||||
646 | |||||
647 | /** |
||||
648 | * Set the total amount cancelled via this form. |
||||
649 | * |
||||
650 | * @since 1.0.19 |
||||
651 | * @param float $value Amount cancelled. |
||||
652 | */ |
||||
653 | public function set_cancelled( $value ) { |
||||
654 | $value = max( (float) $value, 0 ); |
||||
655 | $this->set_prop( 'cancelled', $value ); |
||||
656 | } |
||||
657 | |||||
658 | /** |
||||
659 | * Set the total amount failed via this form. |
||||
660 | * |
||||
661 | * @since 1.0.19 |
||||
662 | * @param float $value Amount cancelled. |
||||
663 | */ |
||||
664 | public function set_failed( $value ) { |
||||
665 | $value = max( (float) $value, 0 ); |
||||
666 | $this->set_prop( 'failed', $value ); |
||||
667 | } |
||||
668 | |||||
669 | /** |
||||
670 | * Create an item. For backwards compatibilty. |
||||
671 | * |
||||
672 | * @deprecated |
||||
673 | * @return int item id |
||||
674 | */ |
||||
675 | public function create( $data = array() ) { |
||||
676 | |||||
677 | // Set the properties. |
||||
678 | if ( is_array( $data ) ) { |
||||
679 | $this->set_props( $data ); |
||||
680 | } |
||||
681 | |||||
682 | // Save the item. |
||||
683 | return $this->save(); |
||||
684 | |||||
685 | } |
||||
686 | |||||
687 | /** |
||||
688 | * Updates an item. For backwards compatibilty. |
||||
689 | * |
||||
690 | * @deprecated |
||||
691 | * @return int item id |
||||
692 | */ |
||||
693 | public function update( $data = array() ) { |
||||
694 | return $this->create( $data ); |
||||
0 ignored issues
–
show
The function
GetPaid_Payment_Form::create() has been deprecated.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
695 | } |
||||
696 | |||||
697 | /* |
||||
698 | |-------------------------------------------------------------------------- |
||||
699 | | Conditionals |
||||
700 | |-------------------------------------------------------------------------- |
||||
701 | | |
||||
702 | | Checks if a condition is true or false. |
||||
703 | | |
||||
704 | */ |
||||
705 | |||||
706 | /** |
||||
707 | * Checks whether this is the default payment form. |
||||
708 | * |
||||
709 | * @since 1.0.19 |
||||
710 | * @return bool |
||||
711 | */ |
||||
712 | public function is_default() { |
||||
713 | $is_default = $this->get_id() == wpinv_get_default_payment_form(); |
||||
714 | return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this ); |
||||
715 | } |
||||
716 | |||||
717 | /** |
||||
718 | * Checks whether the form is active. |
||||
719 | * |
||||
720 | * @since 1.0.19 |
||||
721 | * @return bool |
||||
722 | */ |
||||
723 | public function is_active() { |
||||
724 | $is_active = 0 !== (int) $this->get_id(); |
||||
725 | |||||
726 | if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) { |
||||
727 | $is_active = false; |
||||
728 | } |
||||
729 | |||||
730 | return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this ); |
||||
731 | } |
||||
732 | |||||
733 | /** |
||||
734 | * Checks whether the form has a given item. |
||||
735 | * |
||||
736 | * @since 1.0.19 |
||||
737 | * @return bool |
||||
738 | */ |
||||
739 | public function has_item( $item_id ) { |
||||
740 | return false !== $this->get_item( $item_id ); |
||||
741 | } |
||||
742 | |||||
743 | /** |
||||
744 | * Checks whether the form has a given element. |
||||
745 | * |
||||
746 | * @since 1.0.19 |
||||
747 | * @return bool |
||||
748 | */ |
||||
749 | public function has_element_type( $element_type ) { |
||||
750 | return false !== $this->get_element_type( $element_type ); |
||||
751 | } |
||||
752 | |||||
753 | /** |
||||
754 | * Checks whether this form is recurring or not. |
||||
755 | * |
||||
756 | * @since 1.0.19 |
||||
757 | * @return bool |
||||
758 | */ |
||||
759 | public function is_recurring() { |
||||
760 | |||||
761 | if ( ! empty( $this->invoice ) ) { |
||||
762 | return $this->invoice->is_recurring(); |
||||
763 | } |
||||
764 | |||||
765 | foreach ( $this->get_items() as $item ) { |
||||
766 | |||||
767 | if ( $item->is_recurring() ) { |
||||
768 | return true; |
||||
769 | } |
||||
770 | } |
||||
771 | |||||
772 | return false; |
||||
773 | } |
||||
774 | |||||
775 | /** |
||||
776 | * Retrieves the form's html. |
||||
777 | * |
||||
778 | * @since 1.0.19 |
||||
779 | */ |
||||
780 | public function get_html( $extra_markup = '' ) { |
||||
781 | |||||
782 | // Return the HTML. |
||||
783 | return wpinv_get_template_html( |
||||
784 | 'payment-forms/form.php', |
||||
785 | array( |
||||
786 | 'form' => $this, |
||||
787 | 'extra_markup' => $extra_markup, |
||||
788 | ) |
||||
789 | ); |
||||
790 | |||||
791 | } |
||||
792 | |||||
793 | /** |
||||
794 | * Displays the payment form. |
||||
795 | * |
||||
796 | * @since 1.0.19 |
||||
797 | */ |
||||
798 | public function display( $extra_markup = '' ) { |
||||
799 | wpinv_get_template( |
||||
800 | 'payment-forms/form.php', |
||||
801 | array( |
||||
802 | 'form' => $this, |
||||
803 | 'extra_markup' => $extra_markup, |
||||
804 | ) |
||||
805 | ); |
||||
806 | } |
||||
807 | |||||
808 | } |
||||
809 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.