Total Complexity | 163 |
Total Lines | 2548 |
Duplicated Lines | 0 % |
Changes | 10 | ||
Bugs | 0 | Features | 2 |
Complex classes like WPInv_Payment_Form_Elements often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use WPInv_Payment_Form_Elements, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
7 | class WPInv_Payment_Form_Elements { |
||
8 | |||
9 | /** |
||
10 | * @param array payment form elements |
||
11 | */ |
||
12 | protected $elements; |
||
13 | |||
14 | public function __construct() { |
||
29 | } |
||
30 | |||
31 | } |
||
32 | |||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Returns all the elements that can be added to a form. |
||
37 | */ |
||
38 | public function get_elements() { |
||
346 | } |
||
347 | |||
348 | /** |
||
349 | * Returns the restrict markup. |
||
350 | */ |
||
351 | public function get_restrict_markup( $field, $field_type ) { |
||
352 | $restrict = "$field.type=='$field_type'"; |
||
353 | return "v-if=\"$restrict\""; |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * Renders the title element template. |
||
358 | */ |
||
359 | public function render_heading_template( $field ) { |
||
360 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
361 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
||
362 | } |
||
363 | |||
364 | /** |
||
365 | * Renders the title element on the frontend. |
||
366 | */ |
||
367 | public function frontend_render_heading_template( $field ) { |
||
368 | $tag = $field['level']; |
||
369 | echo "<$tag>{$field['text']}</$tag>"; |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * Renders the edit title element template. |
||
374 | */ |
||
375 | public function edit_heading_template( $field ) { |
||
376 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
377 | $label = __( 'Heading', 'invoicing' ); |
||
378 | $label2 = __( 'Select Heading Level', 'invoicing' ); |
||
379 | $id = $field . '.id + "_edit"'; |
||
380 | $id2 = $field . '.id + "_edit2"'; |
||
381 | |||
382 | echo " |
||
383 | <div $restrict> |
||
384 | <div class='form-group'> |
||
385 | <label :for='$id'>$label</label> |
||
386 | <input class='form-control' :id='$id' v-model='$field.text' type='text' /> |
||
387 | </div> |
||
388 | |||
389 | <div class='form-group'> |
||
390 | <label :for='$id2'>$label2</label> |
||
391 | |||
392 | <select class='form-control custom-select' :id='$id2' v-model='$field.level'> |
||
393 | <option value='h1'>H1</option> |
||
394 | <option value='h2'>H2</option> |
||
395 | <option value='h3'>H3</option> |
||
396 | <option value='h4'>H4</option> |
||
397 | <option value='h5'>H5</option> |
||
398 | <option value='h6'>H6</option> |
||
399 | <option value='h7'>H7</option> |
||
400 | </select> |
||
401 | </div> |
||
402 | </div> |
||
403 | "; |
||
404 | |||
405 | } |
||
406 | |||
407 | /** |
||
408 | * Renders a paragraph element template. |
||
409 | */ |
||
410 | public function render_paragraph_template( $field ) { |
||
411 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
412 | $label = "$field.text"; |
||
413 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
||
414 | } |
||
415 | |||
416 | /** |
||
417 | * Renders the paragraph element on the frontend. |
||
418 | */ |
||
419 | public function frontend_render_paragraph_template( $field ) { |
||
420 | echo "<p>{$field['text']}</p>"; |
||
421 | } |
||
422 | |||
423 | /** |
||
424 | * Renders the edit paragraph element template. |
||
425 | */ |
||
426 | public function edit_paragraph_template( $field ) { |
||
427 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
428 | $label = __( 'Enter your text', 'invoicing' ); |
||
429 | $id = $field . '.id + "_edit"'; |
||
430 | echo " |
||
431 | <div $restrict> |
||
432 | <div class='form-group'> |
||
433 | <label :for='$id'>$label</label> |
||
434 | <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
435 | </div> |
||
436 | </div> |
||
437 | "; |
||
438 | |||
439 | } |
||
440 | |||
441 | /** |
||
442 | * Renders the text element template. |
||
443 | */ |
||
444 | public function render_text_template( $field ) { |
||
445 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
446 | $label = "$field.label"; |
||
447 | echo " |
||
448 | <div $restrict> |
||
449 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
450 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'> |
||
451 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
452 | </div> |
||
453 | "; |
||
454 | } |
||
455 | |||
456 | /** |
||
457 | * Renders the text element on the frontend. |
||
458 | */ |
||
459 | public function frontend_render_text_template( $field ) { |
||
460 | |||
461 | echo "<div class='form-group'>"; |
||
462 | |||
463 | echo aui()->input( |
||
|
|||
464 | array( |
||
465 | 'name' => esc_attr( $field['id'] ), |
||
466 | 'id' => esc_attr( $field['id'] ), |
||
467 | 'placeholder'=> esc_attr( $field['placeholder'] ), |
||
468 | 'required' => (bool) $field['required'], |
||
469 | 'label' => wp_kses_post( $field['label'] ), |
||
470 | 'no_wrap' => true, |
||
471 | ) |
||
472 | ); |
||
473 | |||
474 | if ( ! empty( $field['description'] ) ) { |
||
475 | $description = wp_kses_post( $field['description'] ); |
||
476 | echo "<small class='form-text text-muted'>$description</small>"; |
||
477 | } |
||
478 | |||
479 | echo '</div>'; |
||
480 | |||
481 | } |
||
482 | |||
483 | /** |
||
484 | * Renders the edit text element template. |
||
485 | */ |
||
486 | public function edit_text_template( $field ) { |
||
487 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
488 | $label = __( 'Field Label', 'invoicing' ); |
||
489 | $id = $field . '.id + "_edit"'; |
||
490 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
491 | $id2 = $field . '.id + "_edit2"'; |
||
492 | $label3 = __( 'Help text', 'invoicing' ); |
||
493 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
494 | $id3 = $field . '.id + "_edit3"'; |
||
495 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
496 | $id4 = $field . '.id + "_edit4"'; |
||
497 | echo " |
||
498 | <div $restrict> |
||
499 | <div class='form-group'> |
||
500 | <label :for='$id'>$label</label> |
||
501 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
502 | </div> |
||
503 | <div class='form-group'> |
||
504 | <label :for='$id2'>$label2</label> |
||
505 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
506 | </div> |
||
507 | <div class='form-group'> |
||
508 | <label :for='$id3'>$label3</label> |
||
509 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
510 | </div> |
||
511 | <div class='form-group form-check'> |
||
512 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
513 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
514 | </div> |
||
515 | </div> |
||
516 | "; |
||
517 | |||
518 | } |
||
519 | |||
520 | /** |
||
521 | * Renders the textarea element template. |
||
522 | */ |
||
523 | public function render_textarea_template( $field ) { |
||
524 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
525 | $label = "$field.label"; |
||
526 | echo " |
||
527 | <div $restrict> |
||
528 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
529 | <textarea :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea> |
||
530 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
531 | </div> |
||
532 | "; |
||
533 | } |
||
534 | |||
535 | /** |
||
536 | * Renders the textarea element on the frontend. |
||
537 | */ |
||
538 | public function frontend_render_textarea_template( $field ) { |
||
539 | |||
540 | echo "<div class='form-group'>"; |
||
541 | |||
542 | echo aui()->textarea( |
||
543 | array( |
||
544 | 'name' => esc_attr( $field['id'] ), |
||
545 | 'id' => esc_attr( $field['id'] ), |
||
546 | 'placeholder'=> esc_attr( $field['placeholder'] ), |
||
547 | 'required' => (bool) $field['required'], |
||
548 | 'label' => wp_kses_post( $field['label'] ), |
||
549 | 'no_wrap' => true, |
||
550 | 'rows' => 3, |
||
551 | ) |
||
552 | ); |
||
553 | |||
554 | if ( ! empty( $field['description'] ) ) { |
||
555 | $description = wp_kses_post( $field['description'] ); |
||
556 | echo "<small class='form-text text-muted'>$description</small>"; |
||
557 | } |
||
558 | |||
559 | echo '</div>'; |
||
560 | |||
561 | } |
||
562 | |||
563 | /** |
||
564 | * Renders the edit textarea element template. |
||
565 | */ |
||
566 | public function edit_textarea_template( $field ) { |
||
567 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
568 | $label = __( 'Field Label', 'invoicing' ); |
||
569 | $id = $field . '.id + "_edit"'; |
||
570 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
571 | $id2 = $field . '.id + "_edit2"'; |
||
572 | $label3 = __( 'Help text', 'invoicing' ); |
||
573 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
574 | $id3 = $field . '.id + "_edit3"'; |
||
575 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
576 | $id4 = $field . '.id + "_edit4"'; |
||
577 | echo " |
||
578 | <div $restrict> |
||
579 | <div class='form-group'> |
||
580 | <label :for='$id'>$label</label> |
||
581 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
582 | </div> |
||
583 | <div class='form-group'> |
||
584 | <label :for='$id2'>$label2</label> |
||
585 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
586 | </div> |
||
587 | <div class='form-group'> |
||
588 | <label :for='$id3'>$label3</label> |
||
589 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
590 | </div> |
||
591 | <div class='form-group form-check'> |
||
592 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
593 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
594 | </div> |
||
595 | </div> |
||
596 | "; |
||
597 | |||
598 | } |
||
599 | |||
600 | /** |
||
601 | * Renders the select element template. |
||
602 | */ |
||
603 | public function render_select_template( $field ) { |
||
604 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
605 | $label = "$field.label"; |
||
606 | $placeholder = "$field.placeholder"; |
||
607 | $id = $field . '.id'; |
||
608 | echo " |
||
609 | <div $restrict> |
||
610 | <label :for='$id'>{{" . $label . "}}</label> |
||
611 | <select id='$id' class='form-control custom-select' v-model='$field.value'> |
||
612 | <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option> |
||
613 | <option v-for='option in $field.options' value='option'>{{option}}</option> |
||
614 | </select> |
||
615 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
616 | </div> |
||
617 | "; |
||
618 | } |
||
619 | |||
620 | /** |
||
621 | * Renders the select element on the frontend. |
||
622 | */ |
||
623 | public function frontend_render_select_template( $field ) { |
||
624 | |||
625 | echo "<div class='form-group'>"; |
||
626 | |||
627 | echo aui()->select( |
||
628 | array( |
||
629 | 'name' => esc_attr( $field['id'] ), |
||
630 | 'id' => esc_attr( $field['id'] ), |
||
631 | 'placeholder'=> esc_attr( $field['placeholder'] ), |
||
632 | 'required' => (bool) $field['required'], |
||
633 | 'label' => wp_kses_post( $field['label'] ), |
||
634 | 'no_wrap' => true, |
||
635 | 'options' => array_combine( $field['options'], $field['options'] ), |
||
636 | ) |
||
637 | ); |
||
638 | |||
639 | if ( ! empty( $field['description'] ) ) { |
||
640 | $description = wp_kses_post( $field['description'] ); |
||
641 | echo "<small class='form-text text-muted'>$description</small>"; |
||
642 | } |
||
643 | |||
644 | echo '</div>'; |
||
645 | |||
646 | } |
||
647 | |||
648 | /** |
||
649 | * Renders the edit select element template. |
||
650 | */ |
||
651 | public function edit_select_template( $field ) { |
||
652 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
653 | $label = __( 'Field Label', 'invoicing' ); |
||
654 | $id = $field . '.id + "_edit"'; |
||
655 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
656 | $id2 = $field . '.id + "_edit2"'; |
||
657 | $label3 = __( 'Help text', 'invoicing' ); |
||
658 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
659 | $id3 = $field . '.id + "_edit3"'; |
||
660 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
661 | $id4 = $field . '.id + "_edit4"'; |
||
662 | $label6 = __( 'Available Options', 'invoicing' ); |
||
663 | echo " |
||
664 | <div $restrict> |
||
665 | <div class='form-group'> |
||
666 | <label :for='$id'>$label</label> |
||
667 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
668 | </div> |
||
669 | <div class='form-group'> |
||
670 | <label :for='$id2'>$label2</label> |
||
671 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
672 | </div> |
||
673 | <div class='form-group'> |
||
674 | <label :for='$id3'>$label3</label> |
||
675 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
676 | </div> |
||
677 | <div class='form-group form-check'> |
||
678 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
679 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
680 | </div> |
||
681 | <hr class='featurette-divider mt-4'> |
||
682 | <h5>$label6</h5> |
||
683 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
684 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
685 | <div class='input-group-append'> |
||
686 | <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
687 | </div> |
||
688 | </div> |
||
689 | <div class='form-group'> |
||
690 | <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
691 | </div> |
||
692 | </div> |
||
693 | "; |
||
694 | |||
695 | } |
||
696 | |||
697 | /** |
||
698 | * Renders the checkbox element template. |
||
699 | */ |
||
700 | public function render_checkbox_template( $field ) { |
||
701 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
702 | $label = "$field.label"; |
||
703 | echo " |
||
704 | <div class='form-check' $restrict> |
||
705 | <input :id='$field.id' class='form-check-input' type='checkbox' /> |
||
706 | <label class='form-check-label' :for='$field.id'>{{" . $label . "}}</label> |
||
707 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
708 | </div> |
||
709 | "; |
||
710 | } |
||
711 | |||
712 | /** |
||
713 | * Renders the checkbox element on the frontend. |
||
714 | */ |
||
715 | public function frontend_render_checkbox_template( $field ) { |
||
716 | |||
717 | echo "<div class='form-group'>"; |
||
718 | |||
719 | echo aui()->input( |
||
720 | array( |
||
721 | 'name' => esc_attr( $field['id'] ), |
||
722 | 'id' => esc_attr( $field['id'] ), |
||
723 | 'required' => (bool) $field['required'], |
||
724 | 'label' => wp_kses_post( $field['label'] ), |
||
725 | 'no_wrap' => true, |
||
726 | 'value' => esc_attr__( 'Yes', 'invoicing' ), |
||
727 | 'type' => 'checkbox', |
||
728 | ) |
||
729 | ); |
||
730 | |||
731 | if ( ! empty( $field['description'] ) ) { |
||
732 | $description = wp_kses_post( $field['description'] ); |
||
733 | echo "<small class='form-text text-muted'>$description</small>"; |
||
734 | } |
||
735 | |||
736 | echo '</div>'; |
||
737 | |||
738 | } |
||
739 | |||
740 | /** |
||
741 | * Renders the edit checkbox element template. |
||
742 | */ |
||
743 | public function edit_checkbox_template( $field ) { |
||
744 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
745 | $label = __( 'Field Label', 'invoicing' ); |
||
746 | $id = $field . '.id + "_edit"'; |
||
747 | $label2 = __( 'Help text', 'invoicing' ); |
||
748 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
749 | $id2 = $field . '.id + "_edit2"'; |
||
750 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
751 | $id3 = $field . '.id + "_edit3"'; |
||
752 | echo " |
||
753 | <div $restrict> |
||
754 | <div class='form-group'> |
||
755 | <label :for='$id'>$label</label> |
||
756 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
757 | </div> |
||
758 | <div class='form-group'> |
||
759 | <label :for='$id2'>$label2</label> |
||
760 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
761 | </div> |
||
762 | <div class='form-group form-check'> |
||
763 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
764 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
765 | </div> |
||
766 | </div> |
||
767 | "; |
||
768 | |||
769 | } |
||
770 | |||
771 | /** |
||
772 | * Renders the radio element template. |
||
773 | */ |
||
774 | public function render_radio_template( $field ) { |
||
775 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
776 | $label = "$field.label"; |
||
777 | $id = $field . '.id'; |
||
778 | echo " |
||
779 | <div $restrict> |
||
780 | <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend> |
||
781 | <div class='form-check' v-for='(option, index) in $field.options'> |
||
782 | <input class='form-check-input' type='radio' :id='$id + index'> |
||
783 | <label class='form-check-label' :for='$id + index'>{{option}}</label> |
||
784 | </div> |
||
785 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
786 | </div> |
||
787 | "; |
||
788 | } |
||
789 | |||
790 | /** |
||
791 | * Renders the radio element on the frontend. |
||
792 | */ |
||
793 | public function frontend_render_radio_template( $field ) { |
||
794 | |||
795 | echo "<div class='form-group'>"; |
||
796 | |||
797 | if ( ! empty( $field['label'] ) ) { |
||
798 | $label = wp_kses_post( $field['label'] ); |
||
799 | echo "<legend class='col-form-label'>$label</legend>"; |
||
800 | } |
||
801 | |||
802 | foreach( $field['options'] as $index => $option ) { |
||
803 | $id = $field['id'] . $index; |
||
804 | $name = $field['id']; |
||
805 | $value = esc_attr( $option ); |
||
806 | $label = wp_kses_post( $option ); |
||
807 | |||
808 | echo " |
||
809 | <div class='form-check'> |
||
810 | <input class='form-check-input' type='radio' name='$name' id='$id' value='$value'> |
||
811 | <label class='form-check-label' for='$id'>$label</label> |
||
812 | </div> |
||
813 | "; |
||
814 | } |
||
815 | |||
816 | if ( ! empty( $field['description'] ) ) { |
||
817 | $description = wp_kses_post( $field['description'] ); |
||
818 | echo "<small class='form-text text-muted'>$description</small>"; |
||
819 | } |
||
820 | |||
821 | echo '</div>'; |
||
822 | |||
823 | } |
||
824 | |||
825 | /** |
||
826 | * Renders the edit radio element template. |
||
827 | */ |
||
828 | public function edit_radio_template( $field ) { |
||
829 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
830 | $label = __( 'Field Label', 'invoicing' ); |
||
831 | $id = $field . '.id + "_edit"'; |
||
832 | $label2 = __( 'Help text', 'invoicing' ); |
||
833 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
834 | $id2 = $field . '.id + "_edit3"'; |
||
835 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
836 | $id3 = $field . '.id + "_edit4"'; |
||
837 | $label5 = __( 'Available Options', 'invoicing' ); |
||
838 | echo " |
||
839 | <div $restrict> |
||
840 | <div class='form-group'> |
||
841 | <label :for='$id'>$label</label> |
||
842 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
843 | </div> |
||
844 | <div class='form-group'> |
||
845 | <label :for='$id2'>$label2</label> |
||
846 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
847 | </div> |
||
848 | <div class='form-group form-check'> |
||
849 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
850 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
851 | </div> |
||
852 | <hr class='featurette-divider mt-4'> |
||
853 | <h5>$label5</h5> |
||
854 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
855 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
856 | <div class='input-group-append'> |
||
857 | <button class='button button-secondary border' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
858 | </div> |
||
859 | </div> |
||
860 | <div class='form-group'> |
||
861 | <button class='button button-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
862 | </div> |
||
863 | </div> |
||
864 | "; |
||
865 | |||
866 | } |
||
867 | |||
868 | /** |
||
869 | * Renders the address element template. |
||
870 | */ |
||
871 | public function render_address_template( $field ) { |
||
872 | $restrict = $this->get_restrict_markup( $field, 'address' ); |
||
873 | |||
874 | echo " |
||
875 | <div class='wpinv-address-wrapper' $restrict> |
||
876 | <draggable v-model='$field.fields' group='address_fields_preview'> |
||
877 | <div class='form-group address-field-preview' v-for='(field, index) in $field.fields' :key='field.name' v-show='field.visible'> |
||
878 | <label :for='field.name'>{{field.label}}<span class='text-danger' v-if='field.required'> *</span></label> |
||
879 | <input class='form-control' type='text' :id='field.name' :placeholder='field.placeholder'> |
||
880 | <small v-if='field.description' class='form-text text-muted' v-html='field.description'></small> |
||
881 | </div> |
||
882 | </draggable> |
||
883 | </div> |
||
884 | "; |
||
885 | } |
||
886 | |||
887 | /** |
||
888 | * Renders the address element on the frontend. |
||
889 | */ |
||
890 | public function frontend_render_address_template( $field ) { |
||
891 | |||
892 | echo "<div class='wpinv-address-fields'>"; |
||
893 | |||
894 | foreach( $field['fields'] as $address_field ) { |
||
895 | |||
896 | if ( empty( $address_field['visible'] ) ) { |
||
897 | continue; |
||
898 | } |
||
899 | |||
900 | $class = esc_attr( $address_field['name'] ); |
||
901 | echo "<div class='form-group $class'>"; |
||
902 | |||
903 | $label = $address_field['label']; |
||
904 | |||
905 | if ( ! empty( $address_field['required'] ) ) { |
||
906 | $label .= "<span class='text-danger'> *</span>"; |
||
907 | } |
||
908 | echo aui()->input( |
||
909 | array( |
||
910 | 'name' => esc_attr( $address_field['name'] ), |
||
911 | 'id' => esc_attr( $address_field['name'] ), |
||
912 | 'required' => (bool) $address_field['required'], |
||
913 | 'label' => wp_kses_post( $label ), |
||
914 | 'no_wrap' => true, |
||
915 | 'placeholder' => esc_attr( $address_field['placeholder'] ), |
||
916 | 'type' => 'text', |
||
917 | ) |
||
918 | ); |
||
919 | |||
920 | if ( ! empty( $address_field['description'] ) ) { |
||
921 | $description = wp_kses_post( $address_field['description'] ); |
||
922 | echo "<small class='form-text text-muted'>$description</small>"; |
||
923 | } |
||
924 | |||
925 | echo '</div>'; |
||
926 | |||
927 | } |
||
928 | |||
929 | echo '</div>'; |
||
930 | |||
931 | } |
||
932 | |||
933 | /** |
||
934 | * Renders the edit address element template. |
||
935 | */ |
||
936 | public function edit_address_template( $field ) { |
||
937 | $restrict = $this->get_restrict_markup( $field, 'address' ); |
||
938 | $label = __( 'Field Label', 'invoicing' ); |
||
939 | $label2 = __( 'Placeholder', 'invoicing' ); |
||
940 | $label3 = __( 'Description', 'invoicing' ); |
||
941 | $label4 = __( 'Is required', 'invoicing' ); |
||
942 | $label5 = __( 'Is visible', 'invoicing' ); |
||
943 | $id = $field . '.id + "_edit_label"'; |
||
944 | $id2 = $field . '.id + "_edit_placeholder"'; |
||
945 | $id3 = $field . '.id + "_edit_description"'; |
||
946 | $id4 = $field . '.id + "_edit_required"'; |
||
947 | $id5 = $field . '.id + "_edit_visible"'; |
||
948 | $id5 = $field . '.id + "_edit_visible"'; |
||
949 | $id_main = $field . '.id'; |
||
950 | |||
951 | echo " |
||
952 | <div $restrict :id='$id_main'> |
||
953 | <draggable v-model='$field.fields' group='address_fields'> |
||
954 | <div class='wpinv-form-address-field-editor' v-for='(field, index) in $field.fields' :class=\"[field.name, { 'visible' : field.visible }]\" :key='field.name'> |
||
955 | |||
956 | <div class='wpinv-form-address-field-editor-header' @click.prevent='toggleAddressPanel($id_main, field.name)'> |
||
957 | <span class='label'>{{field.label}}</span> |
||
958 | <span class='toggle-visibility-icon' @click.prevent='field.visible = !field.visible;'> |
||
959 | <span class='dashicons dashicons-hidden'></span> |
||
960 | <span class='dashicons dashicons-visibility'></span> |
||
961 | </span> |
||
962 | <span class='toggle-icon'> |
||
963 | <span class='dashicons dashicons-arrow-down'></span> |
||
964 | <span class='dashicons dashicons-arrow-up' style='display:none'></span> |
||
965 | </span> |
||
966 | </div> |
||
967 | |||
968 | <div class='wpinv-form-address-field-editor-editor-body'> |
||
969 | <div class='p-2'> |
||
970 | |||
971 | <div class='form-group'> |
||
972 | <label :for='$id + index'>$label</label> |
||
973 | <input :id='$id + index' v-model='field.label' class='form-control' /> |
||
974 | </div> |
||
975 | |||
976 | <div class='form-group'> |
||
977 | <label :for='$id2 + index'>$label2</label> |
||
978 | <input :id='$id2 + index' v-model='field.placeholder' class='form-control' /> |
||
979 | </div> |
||
980 | |||
981 | <div class='form-group'> |
||
982 | <label :for='$id3 + index'>$label3</label> |
||
983 | <textarea :id='$id3 + index' v-model='field.description' class='form-control'></textarea> |
||
984 | </div> |
||
985 | |||
986 | <div class='form-group form-check'> |
||
987 | <input :id='$id4 + index' v-model='field.required' type='checkbox' class='form-check-input' /> |
||
988 | <label class='form-check-label' :for='$id4 + index'>$label4</label> |
||
989 | </div> |
||
990 | |||
991 | <div class='form-group form-check'> |
||
992 | <input :id='$id5 + index' v-model='field.visible' type='checkbox' class='form-check-input' /> |
||
993 | <label class='form-check-label' :for='$id5 + index'>$label5</label> |
||
994 | </div> |
||
995 | |||
996 | </div> |
||
997 | </div> |
||
998 | |||
999 | </div> |
||
1000 | </draggable> |
||
1001 | |||
1002 | </div> |
||
1003 | "; |
||
1004 | |||
1005 | } |
||
1006 | |||
1007 | /** |
||
1008 | * Renders the email element template. |
||
1009 | */ |
||
1010 | public function render_email_template( $field ) { |
||
1011 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
1012 | $label = "$field.label"; |
||
1013 | echo " |
||
1014 | <div $restrict> |
||
1015 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1016 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
1017 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1018 | </div> |
||
1019 | "; |
||
1020 | } |
||
1021 | |||
1022 | /** |
||
1023 | * Renders the billing_email element template. |
||
1024 | */ |
||
1025 | public function render_billing_email_template( $field ) { |
||
1026 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
1027 | $label = "$field.label"; |
||
1028 | echo " |
||
1029 | <div $restrict> |
||
1030 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1031 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
1032 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1033 | </div> |
||
1034 | "; |
||
1035 | } |
||
1036 | |||
1037 | /** |
||
1038 | * Renders the email element on the frontend. |
||
1039 | */ |
||
1040 | public function frontend_render_email_template( $field ) { |
||
1041 | |||
1042 | echo "<div class='form-group'>"; |
||
1043 | |||
1044 | echo aui()->input( |
||
1045 | array( |
||
1046 | 'name' => esc_attr( $field['id'] ), |
||
1047 | 'id' => esc_attr( $field['id'] ), |
||
1048 | 'required' => (bool) $field['required'], |
||
1049 | 'label' => wp_kses_post( $field['label'] ), |
||
1050 | 'no_wrap' => true, |
||
1051 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1052 | 'type' => 'email', |
||
1053 | ) |
||
1054 | ); |
||
1055 | |||
1056 | if ( ! empty( $field['description'] ) ) { |
||
1057 | $description = wp_kses_post( $field['description'] ); |
||
1058 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1059 | } |
||
1060 | |||
1061 | echo '</div>'; |
||
1062 | |||
1063 | } |
||
1064 | |||
1065 | /** |
||
1066 | * Renders the billing email element on the frontend. |
||
1067 | */ |
||
1068 | public function frontend_render_billing_email_template( $field ) { |
||
1069 | |||
1070 | echo "<div class='form-group'>"; |
||
1071 | $value = ''; |
||
1072 | |||
1073 | if ( is_user_logged_in() ) { |
||
1074 | $user = wp_get_current_user(); |
||
1075 | $value = sanitize_email( $user->user_email ); |
||
1076 | } |
||
1077 | echo aui()->input( |
||
1078 | array( |
||
1079 | 'name' => 'billing_email', |
||
1080 | 'value' => $value, |
||
1081 | 'id' => esc_attr( $field['id'] ), |
||
1082 | 'required' => true, |
||
1083 | 'label' => wp_kses_post( $field['label'] ), |
||
1084 | 'no_wrap' => true, |
||
1085 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1086 | 'type' => 'email', |
||
1087 | ) |
||
1088 | ); |
||
1089 | |||
1090 | if ( ! empty( $field['description'] ) ) { |
||
1091 | $description = wp_kses_post( $field['description'] ); |
||
1092 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1093 | } |
||
1094 | |||
1095 | echo '</div>'; |
||
1096 | |||
1097 | } |
||
1098 | |||
1099 | /** |
||
1100 | * Renders the edit email element template. |
||
1101 | */ |
||
1102 | public function edit_email_template( $field ) { |
||
1103 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
1104 | $label = __( 'Field Label', 'invoicing' ); |
||
1105 | $id = $field . '.id + "_edit"'; |
||
1106 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1107 | $id2 = $field . '.id + "_edit2"'; |
||
1108 | $label3 = __( 'Help text', 'invoicing' ); |
||
1109 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1110 | $id3 = $field . '.id + "_edit3"'; |
||
1111 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1112 | $id4 = $field . '.id + "_edit4"'; |
||
1113 | echo " |
||
1114 | <div $restrict> |
||
1115 | <div class='form-group'> |
||
1116 | <label :for='$id'>$label</label> |
||
1117 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1118 | </div> |
||
1119 | <div class='form-group'> |
||
1120 | <label :for='$id2'>$label2</label> |
||
1121 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1122 | </div> |
||
1123 | <div class='form-group'> |
||
1124 | <label :for='$id3'>$label3</label> |
||
1125 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1126 | </div> |
||
1127 | <div class='form-group form-check'> |
||
1128 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1129 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1130 | </div> |
||
1131 | </div> |
||
1132 | "; |
||
1133 | |||
1134 | } |
||
1135 | |||
1136 | /** |
||
1137 | * Renders the edit billing_email element template. |
||
1138 | */ |
||
1139 | public function edit_billing_email_template( $field ) { |
||
1140 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
1141 | $label = __( 'Field Label', 'invoicing' ); |
||
1142 | $id = $field . '.id + "_edit"'; |
||
1143 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1144 | $id2 = $field . '.id + "_edit2"'; |
||
1145 | $label3 = __( 'Help text', 'invoicing' ); |
||
1146 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1147 | $id3 = $field . '.id + "_edit3"'; |
||
1148 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1149 | $id4 = $field . '.id + "_edit4"'; |
||
1150 | echo " |
||
1151 | <div $restrict> |
||
1152 | <div class='form-group'> |
||
1153 | <label :for='$id'>$label</label> |
||
1154 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1155 | </div> |
||
1156 | <div class='form-group'> |
||
1157 | <label :for='$id2'>$label2</label> |
||
1158 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1159 | </div> |
||
1160 | <div class='form-group'> |
||
1161 | <label :for='$id3'>$label3</label> |
||
1162 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1163 | </div> |
||
1164 | </div> |
||
1165 | "; |
||
1166 | |||
1167 | } |
||
1168 | |||
1169 | /** |
||
1170 | * Renders the website element template. |
||
1171 | */ |
||
1172 | public function render_website_template( $field ) { |
||
1173 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
1174 | $label = "$field.label"; |
||
1175 | echo " |
||
1176 | <div $restrict> |
||
1177 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1178 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'> |
||
1179 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1180 | </div> |
||
1181 | "; |
||
1182 | } |
||
1183 | |||
1184 | /** |
||
1185 | * Renders the website element on the frontend. |
||
1186 | */ |
||
1187 | public function frontend_render_website_template( $field ) { |
||
1188 | |||
1189 | echo "<div class='form-group'>"; |
||
1190 | |||
1191 | echo aui()->input( |
||
1192 | array( |
||
1193 | 'name' => esc_attr( $field['id'] ), |
||
1194 | 'id' => esc_attr( $field['id'] ), |
||
1195 | 'required' => (bool) $field['required'], |
||
1196 | 'label' => wp_kses_post( $field['label'] ), |
||
1197 | 'no_wrap' => true, |
||
1198 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1199 | 'type' => 'url', |
||
1200 | ) |
||
1201 | ); |
||
1202 | |||
1203 | if ( ! empty( $field['description'] ) ) { |
||
1204 | $description = wp_kses_post( $field['description'] ); |
||
1205 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1206 | } |
||
1207 | |||
1208 | echo '</div>'; |
||
1209 | |||
1210 | } |
||
1211 | |||
1212 | /** |
||
1213 | * Renders the edit website element template. |
||
1214 | */ |
||
1215 | public function edit_website_template( $field ) { |
||
1216 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
1217 | $label = __( 'Field Label', 'invoicing' ); |
||
1218 | $id = $field . '.id + "_edit"'; |
||
1219 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1220 | $id2 = $field . '.id + "_edit2"'; |
||
1221 | $label3 = __( 'Help text', 'invoicing' ); |
||
1222 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1223 | $id3 = $field . '.id + "_edit3"'; |
||
1224 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1225 | $id4 = $field . '.id + "_edit4"'; |
||
1226 | echo " |
||
1227 | <div $restrict> |
||
1228 | <div class='form-group'> |
||
1229 | <label :for='$id'>$label</label> |
||
1230 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1231 | </div> |
||
1232 | <div class='form-group'> |
||
1233 | <label :for='$id2'>$label2</label> |
||
1234 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1235 | </div> |
||
1236 | <div class='form-group'> |
||
1237 | <label :for='$id3'>$label3</label> |
||
1238 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1239 | </div> |
||
1240 | <div class='form-group form-check'> |
||
1241 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1242 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1243 | </div> |
||
1244 | </div> |
||
1245 | "; |
||
1246 | |||
1247 | } |
||
1248 | |||
1249 | /** |
||
1250 | * Renders the date element template. |
||
1251 | */ |
||
1252 | public function render_date_template( $field ) { |
||
1253 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
1254 | $label = "$field.label"; |
||
1255 | echo " |
||
1256 | <div $restrict> |
||
1257 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1258 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'> |
||
1259 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1260 | </div> |
||
1261 | "; |
||
1262 | } |
||
1263 | |||
1264 | /** |
||
1265 | * Renders the date element on the frontend. |
||
1266 | */ |
||
1267 | public function frontend_render_date_template( $field ) { |
||
1268 | |||
1269 | echo "<div class='form-group'>"; |
||
1270 | |||
1271 | echo aui()->input( |
||
1272 | array( |
||
1273 | 'name' => esc_attr( $field['id'] ), |
||
1274 | 'id' => esc_attr( $field['id'] ), |
||
1275 | 'required' => (bool) $field['required'], |
||
1276 | 'label' => wp_kses_post( $field['label'] ), |
||
1277 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1278 | 'no_wrap' => true, |
||
1279 | 'type' => 'date', |
||
1280 | ) |
||
1281 | ); |
||
1282 | |||
1283 | if ( ! empty( $field['description'] ) ) { |
||
1284 | $description = wp_kses_post( $field['description'] ); |
||
1285 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1286 | } |
||
1287 | |||
1288 | echo '</div>'; |
||
1289 | |||
1290 | } |
||
1291 | |||
1292 | /** |
||
1293 | * Renders the edit date element template. |
||
1294 | */ |
||
1295 | public function edit_date_template( $field ) { |
||
1296 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
1297 | $label = __( 'Field Label', 'invoicing' ); |
||
1298 | $id = $field . '.id + "_edit"'; |
||
1299 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1300 | $id2 = $field . '.id + "_edit2"'; |
||
1301 | $label3 = __( 'Help text', 'invoicing' ); |
||
1302 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1303 | $id3 = $field . '.id + "_edit3"'; |
||
1304 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1305 | $id4 = $field . '.id + "_edit4"'; |
||
1306 | echo " |
||
1307 | <div $restrict> |
||
1308 | <div class='form-group'> |
||
1309 | <label :for='$id'>$label</label> |
||
1310 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1311 | </div> |
||
1312 | <div class='form-group'> |
||
1313 | <label :for='$id2'>$label2</label> |
||
1314 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1315 | </div> |
||
1316 | <div class='form-group'> |
||
1317 | <label :for='$id3'>$label3</label> |
||
1318 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1319 | </div> |
||
1320 | <div class='form-group form-check'> |
||
1321 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1322 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1323 | </div> |
||
1324 | </div> |
||
1325 | "; |
||
1326 | |||
1327 | } |
||
1328 | |||
1329 | /** |
||
1330 | * Renders the time element template. |
||
1331 | */ |
||
1332 | public function render_time_template( $field ) { |
||
1333 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
1334 | $label = "$field.label"; |
||
1335 | echo " |
||
1336 | <div $restrict> |
||
1337 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1338 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'> |
||
1339 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1340 | </div> |
||
1341 | "; |
||
1342 | } |
||
1343 | |||
1344 | /** |
||
1345 | * Renders the time element on the frontend. |
||
1346 | */ |
||
1347 | public function frontend_render_time_template( $field ) { |
||
1348 | |||
1349 | echo "<div class='form-group'>"; |
||
1350 | |||
1351 | echo aui()->input( |
||
1352 | array( |
||
1353 | 'name' => esc_attr( $field['id'] ), |
||
1354 | 'id' => esc_attr( $field['id'] ), |
||
1355 | 'required' => (bool) $field['required'], |
||
1356 | 'label' => wp_kses_post( $field['label'] ), |
||
1357 | 'no_wrap' => true, |
||
1358 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1359 | 'type' => 'time', |
||
1360 | ) |
||
1361 | ); |
||
1362 | |||
1363 | if ( ! empty( $field['description'] ) ) { |
||
1364 | $description = wp_kses_post( $field['description'] ); |
||
1365 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1366 | } |
||
1367 | |||
1368 | echo '</div>'; |
||
1369 | |||
1370 | } |
||
1371 | |||
1372 | /** |
||
1373 | * Renders the edit time element template. |
||
1374 | */ |
||
1375 | public function edit_time_template( $field ) { |
||
1376 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
1377 | $label = __( 'Field Label', 'invoicing' ); |
||
1378 | $id = $field . '.id + "_edit"'; |
||
1379 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1380 | $id2 = $field . '.id + "_edit2"'; |
||
1381 | $label3 = __( 'Help text', 'invoicing' ); |
||
1382 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1383 | $id3 = $field . '.id + "_edit3"'; |
||
1384 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1385 | $id4 = $field . '.id + "_edit4"'; |
||
1386 | echo " |
||
1387 | <div $restrict> |
||
1388 | <div class='form-group'> |
||
1389 | <label :for='$id'>$label</label> |
||
1390 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1391 | </div> |
||
1392 | <div class='form-group'> |
||
1393 | <label :for='$id2'>$label2</label> |
||
1394 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1395 | </div> |
||
1396 | <div class='form-group'> |
||
1397 | <label :for='$id3'>$label3</label> |
||
1398 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1399 | </div> |
||
1400 | <div class='form-group form-check'> |
||
1401 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1402 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1403 | </div> |
||
1404 | </div> |
||
1405 | "; |
||
1406 | |||
1407 | } |
||
1408 | |||
1409 | /** |
||
1410 | * Renders the number element template. |
||
1411 | */ |
||
1412 | public function render_number_template( $field ) { |
||
1413 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
1414 | $label = "$field.label"; |
||
1415 | echo " |
||
1416 | <div $restrict> |
||
1417 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1418 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'> |
||
1419 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1420 | </div> |
||
1421 | "; |
||
1422 | } |
||
1423 | |||
1424 | /** |
||
1425 | * Renders the number element on the frontend. |
||
1426 | */ |
||
1427 | public function frontend_render_number_template( $field ) { |
||
1428 | |||
1429 | echo "<div class='form-group'>"; |
||
1430 | |||
1431 | echo aui()->input( |
||
1432 | array( |
||
1433 | 'name' => esc_attr( $field['id'] ), |
||
1434 | 'id' => esc_attr( $field['id'] ), |
||
1435 | 'required' => (bool) $field['required'], |
||
1436 | 'label' => wp_kses_post( $field['label'] ), |
||
1437 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1438 | 'no_wrap' => true, |
||
1439 | 'type' => 'number', |
||
1440 | ) |
||
1441 | ); |
||
1442 | |||
1443 | if ( ! empty( $field['description'] ) ) { |
||
1444 | $description = wp_kses_post( $field['description'] ); |
||
1445 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1446 | } |
||
1447 | |||
1448 | echo '</div>'; |
||
1449 | |||
1450 | } |
||
1451 | |||
1452 | /** |
||
1453 | * Renders the edit number element template. |
||
1454 | */ |
||
1455 | public function edit_number_template( $field ) { |
||
1456 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
1457 | $label = __( 'Field Label', 'invoicing' ); |
||
1458 | $id = $field . '.id + "_edit"'; |
||
1459 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1460 | $id2 = $field . '.id + "_edit2"'; |
||
1461 | $label3 = __( 'Help text', 'invoicing' ); |
||
1462 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1463 | $id3 = $field . '.id + "_edit3"'; |
||
1464 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1465 | $id4 = $field . '.id + "_edit4"'; |
||
1466 | echo " |
||
1467 | <div $restrict> |
||
1468 | <div class='form-group'> |
||
1469 | <label :for='$id'>$label</label> |
||
1470 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1471 | </div> |
||
1472 | <div class='form-group'> |
||
1473 | <label :for='$id2'>$label2</label> |
||
1474 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1475 | </div> |
||
1476 | <div class='form-group'> |
||
1477 | <label :for='$id3'>$label3</label> |
||
1478 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1479 | </div> |
||
1480 | <div class='form-group form-check'> |
||
1481 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1482 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1483 | </div> |
||
1484 | </div> |
||
1485 | "; |
||
1486 | |||
1487 | } |
||
1488 | |||
1489 | /** |
||
1490 | * Renders the separator element template. |
||
1491 | */ |
||
1492 | public function render_separator_template( $field ) { |
||
1493 | $restrict = $this->get_restrict_markup( $field, 'separator' ); |
||
1494 | echo "<hr class='featurette-divider mt-0 mb-2' $restrict>"; |
||
1495 | } |
||
1496 | |||
1497 | /** |
||
1498 | * Renders the separator element on the frontend. |
||
1499 | */ |
||
1500 | public function frontend_render_separator_template( $field ) { |
||
1501 | echo '<hr class="featurette-divider mt-0 mb-2" />'; |
||
1502 | } |
||
1503 | |||
1504 | /** |
||
1505 | * Renders the pay button element template. |
||
1506 | */ |
||
1507 | public function render_pay_button_template( $field ) { |
||
1508 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
1509 | $label = "$field.label"; |
||
1510 | echo " |
||
1511 | <div $restrict> |
||
1512 | <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button> |
||
1513 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1514 | </div> |
||
1515 | "; |
||
1516 | } |
||
1517 | |||
1518 | /** |
||
1519 | * Renders the pay_button element on the frontend. |
||
1520 | */ |
||
1521 | public function frontend_render_pay_button_template( $field ) { |
||
1522 | |||
1523 | echo "<div class='form-group'>"; |
||
1524 | |||
1525 | $class = 'btn btn-block submit-button ' . sanitize_html_class( $field['class'] ); |
||
1526 | echo aui()->input( |
||
1527 | array( |
||
1528 | 'name' => esc_attr( $field['id'] ), |
||
1529 | 'id' => esc_attr( $field['id'] ), |
||
1530 | 'value' => esc_attr( $field['label'] ), |
||
1531 | 'no_wrap' => true, |
||
1532 | 'type' => 'submit', |
||
1533 | 'class' => $class, |
||
1534 | ) |
||
1535 | ); |
||
1536 | |||
1537 | if ( ! empty( $field['description'] ) ) { |
||
1538 | $description = wp_kses_post( $field['description'] ); |
||
1539 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1540 | } |
||
1541 | |||
1542 | echo '</div>'; |
||
1543 | |||
1544 | } |
||
1545 | |||
1546 | /** |
||
1547 | * Renders the pay button element template. |
||
1548 | */ |
||
1549 | public function edit_pay_button_template( $field ) { |
||
1550 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
1551 | $label = __( 'Button Text', 'invoicing' ); |
||
1552 | $id = $field . '.id + "_edit"'; |
||
1553 | $label2 = __( 'Help text', 'invoicing' ); |
||
1554 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1555 | $id2 = $field . '.id + "_edit2"'; |
||
1556 | $label4 = esc_attr__( 'Button Type', 'invoicing' ); |
||
1557 | $id3 = $field . '.id + "_edit3"'; |
||
1558 | echo " |
||
1559 | <div $restrict> |
||
1560 | <div class='form-group'> |
||
1561 | <label :for='$id'>$label</label> |
||
1562 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1563 | </div> |
||
1564 | <div class='form-group'> |
||
1565 | <label :for='$id2'>$label2</label> |
||
1566 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1567 | </div> |
||
1568 | <div class='form-group'> |
||
1569 | <label :for='$id3'>$label4</label> |
||
1570 | |||
1571 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
1572 | <option value='btn-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
1573 | <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
1574 | <option value='btn-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
1575 | <option value='btn-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
1576 | <option value='btn-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
1577 | <option value='btn-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
1578 | <option value='btn-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
1579 | <option value='btn-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
1580 | <option value='btn-link'>" . __( 'Link', 'invoicing' ) ."</option> |
||
1581 | </select> |
||
1582 | </div> |
||
1583 | </div> |
||
1584 | "; |
||
1585 | |||
1586 | } |
||
1587 | |||
1588 | /** |
||
1589 | * Renders the alert element template. |
||
1590 | */ |
||
1591 | public function render_alert_template( $field ) { |
||
1592 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
1593 | $text = "$field.text"; |
||
1594 | echo " |
||
1595 | <div $restrict class='alert' :class='$field.class' role='alert'> |
||
1596 | <span v-html='$text'></span> |
||
1597 | <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''> |
||
1598 | <span aria-hidden='true'>×</span> |
||
1599 | </button> |
||
1600 | </div> |
||
1601 | "; |
||
1602 | } |
||
1603 | |||
1604 | /** |
||
1605 | * Renders the alert element on the frontend. |
||
1606 | */ |
||
1607 | public function frontend_render_alert_template( $field ) { |
||
1620 | |||
1621 | } |
||
1622 | |||
1623 | /** |
||
1624 | * Renders the alert element template. |
||
1625 | */ |
||
1626 | public function edit_alert_template( $field ) { |
||
1627 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
1628 | $label = __( 'Alert Text', 'invoicing' ); |
||
1629 | $label2 = esc_attr__( 'Enter your alert text here', 'invoicing' ); |
||
1630 | $id = $field . '.id + "_edit"'; |
||
1631 | $label3 = __( 'Is Dismissible?', 'invoicing' ); |
||
1632 | $id2 = $field . '.id + "_edit2"'; |
||
1633 | $label4 = esc_attr__( 'Alert Type', 'invoicing' ); |
||
1634 | $id3 = $field . '.id + "_edit3"'; |
||
1635 | echo " |
||
1636 | <div $restrict> |
||
1637 | <div class='form-group'> |
||
1638 | <label :for='$id'>$label</label> |
||
1639 | <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
1640 | </div> |
||
1641 | <div class='form-group form-check'> |
||
1642 | <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' /> |
||
1643 | <label class='form-check-label' :for='$id2'>$label3</label> |
||
1644 | </div> |
||
1645 | <div class='form-group'> |
||
1646 | <label :for='$id3'>$label4</label> |
||
1647 | |||
1648 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
1649 | <option value='alert-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
1650 | <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
1651 | <option value='alert-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
1652 | <option value='alert-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
1653 | <option value='alert-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
1654 | <option value='alert-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
1655 | <option value='alert-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
1656 | <option value='alert-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
1657 | </select> |
||
1658 | </div> |
||
1659 | </div> |
||
1660 | "; |
||
1661 | |||
1662 | } |
||
1663 | |||
1664 | /** |
||
1665 | * Renders the discount element template. |
||
1666 | */ |
||
1667 | public function render_discount_template( $field ) { |
||
1668 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
1669 | ?> |
||
1670 | |||
1671 | <div <?php echo $restrict; ?> class="discount_field border rounded p-3"> |
||
1672 | <div class="discount_field_inner d-flex flex-column flex-md-row"> |
||
1673 | <input :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text"> |
||
1674 | <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button> |
||
1675 | </div> |
||
1676 | <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small> |
||
1677 | </div> |
||
1678 | |||
1679 | <?php |
||
1680 | } |
||
1681 | |||
1682 | /** |
||
1683 | * Renders the discount element on the frontend. |
||
1684 | */ |
||
1685 | public function frontend_render_discount_template( $field ) { |
||
1686 | |||
1687 | $placeholder = esc_attr( $field['input_label'] ); |
||
1688 | $label = sanitize_text_field( $field['button_label'] ); |
||
1689 | $description = ''; |
||
1690 | |||
1691 | if ( ! empty( $field['description'] ) ) { |
||
1692 | $description = "<small class='form-text text-muted'>{$field['description']}</small>"; |
||
1693 | } |
||
1694 | ?> |
||
1695 | |||
1696 | <div class="form-group"> |
||
1697 | <div class="discount_field border rounded p-3"> |
||
1698 | <div class="discount_field_inner d-flex flex-column flex-md-row"> |
||
1699 | <input placeholder="<?php echo $placeholder; ?>" class="form-control mr-2 mb-2" style="flex: 1;" type="text"> |
||
1700 | <a href="#" class="btn btn-secondary submit-button mb-2 wpinv-payment-form-coupon-button"><?php echo $label; ?></a> |
||
1701 | </div> |
||
1702 | <?php echo $description ?> |
||
1703 | </div> |
||
1704 | </div> |
||
1705 | |||
1706 | <?php |
||
1707 | } |
||
1708 | |||
1709 | /** |
||
1710 | * Renders the discount element template. |
||
1711 | */ |
||
1712 | public function edit_discount_template( $field ) { |
||
1713 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
1714 | $label = __( 'Discount Input Placeholder', 'invoicing' ); |
||
1715 | $label2 = __( 'Help Text', 'invoicing' ); |
||
1716 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1717 | $label4 = __( 'Button Text', 'invoicing' ); |
||
1718 | $id = $field . '.id + "_edit"'; |
||
1719 | $id2 = $field . '.id + "_edit2"'; |
||
1720 | $id3 = $field . '.id + "_edit3"'; |
||
1721 | echo " |
||
1722 | <div $restrict> |
||
1723 | <div class='form-group'> |
||
1724 | <label :for='$id'>$label</label> |
||
1725 | <input :id='$id' v-model='$field.input_label' class='form-control' /> |
||
1726 | </div> |
||
1727 | |||
1728 | <div class='form-group'> |
||
1729 | <label :for='$id2'>$label4</label> |
||
1730 | <input :id='$id2' v-model='$field.button_label' class='form-control' /> |
||
1731 | </div> |
||
1732 | |||
1733 | <div class='form-group'> |
||
1734 | <label :for='$id3'>$label2</label> |
||
1735 | <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1736 | </div> |
||
1737 | |||
1738 | </div> |
||
1739 | "; |
||
1740 | |||
1741 | } |
||
1742 | |||
1743 | /** |
||
1744 | * Renders the items element template. |
||
1745 | */ |
||
1746 | public function render_items_template( $field ) { |
||
1747 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
1748 | $label = __( 'Item totals placeholder. Item totals will appear here. Click to set items.', 'invoicing' ); |
||
1749 | echo "<div $restrict class='item_totals p-4 bg-warning'>$label</div>"; |
||
1750 | } |
||
1751 | |||
1752 | /** |
||
1753 | * Renders the items element on the frontend. |
||
1754 | */ |
||
1755 | public function frontend_render_items_template( $field, $items ) { |
||
2360 | <?php |
||
2361 | } |
||
2362 | |||
2363 | /** |
||
2364 | * Renders the items element template. |
||
2365 | */ |
||
2366 | public function edit_items_template( $field ) { |
||
2367 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
2368 | $label = __( 'Let customers...', 'invoicing' ); |
||
2369 | $label2 = __( 'Available Items', 'invoicing' ); |
||
2370 | $label3 = esc_attr__( 'Add some help text for this element', 'invoicing' ); |
||
2371 | $id = $field . '.id + "_edit"'; |
||
2372 | $id2 = $field . '.id + "_edit2"'; |
||
2373 | $id3 = $field . '.id + "_edit3"'; |
||
2374 | $id4 = $field . '.id + "_edit4"'; |
||
2375 | $label4 = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' ); |
||
2376 | $label5 = esc_attr__( 'Allow users to pay what they want', 'invoicing' ); |
||
2377 | $label6 = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' ); |
||
2378 | $label7 = esc_attr__( 'Allow users to buy several quantities', 'invoicing' ); |
||
2379 | $label8 = esc_attr__( 'This item is required', 'invoicing' ); |
||
2380 | echo "<div $restrict> |
||
2381 | |||
2382 | <label>$label2</label> |
||
2383 | |||
2384 | <draggable v-model='form_items' group='selectable_form_items'> |
||
2385 | <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class='\"item_\" + item.id' :key='item.id'> |
||
2386 | |||
2387 | <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'> |
||
2388 | <span class='label'>{{item.title}}</span> |
||
2389 | <span class='price'>({{formatPrice(item.price)}})</span> |
||
2390 | <span class='toggle-icon'> |
||
2391 | <span class='dashicons dashicons-arrow-down'></span> |
||
2392 | <span class='dashicons dashicons-arrow-up' style='display:none'></span> |
||
2393 | </span> |
||
2394 | </div> |
||
2395 | |||
2396 | <div class='wpinv-available-items-editor-body'> |
||
2397 | <div class='p-2'> |
||
2398 | |||
2399 | <div class='form-group'> |
||
2400 | <label :for='$id + item.id'>Item Name</label> |
||
2401 | <input :id='$id + item.id' v-model='item.title' class='form-control' /> |
||
2402 | </div> |
||
2403 | |||
2404 | <div class='form-group'> |
||
2405 | <label :for='$id + item.id + \"price\"'>Item Price</label> |
||
2406 | <input :id='$id + item.id + \"price\"' v-model='item.price' class='form-control' /> |
||
2407 | <small class='form-text text-muted' v-if='item.custom_price'>$label4</small> |
||
2408 | </div> |
||
2409 | |||
2410 | <div class='form-group form-check'> |
||
2411 | <input :id='$id4 + item.id + \"custom_price\"' v-model='item.custom_price' type='checkbox' class='form-check-input' /> |
||
2412 | <label class='form-check-label' :for='$id4 + item.id + \"custom_price\"'>$label5</label> |
||
2413 | </div> |
||
2414 | |||
2415 | <div class='form-group' v-if='item.custom_price'> |
||
2416 | <label :for='$id + item.id + \"minimum_price\"'>Minimum Price</label> |
||
2417 | <input :id='$id + item.id + \"minimum_price\"' placeholder='0.00' v-model='item.minimum_price' class='form-control' /> |
||
2418 | <small class='form-text text-muted'>$label6</small> |
||
2419 | </div> |
||
2420 | |||
2421 | <div class='form-group form-check'> |
||
2422 | <input :id='$id + item.id + \"quantities\"' v-model='item.allow_quantities' type='checkbox' class='form-check-input' /> |
||
2423 | <label class='form-check-label' :for='$id + item.id + \"quantities\"'>$label7</label> |
||
2424 | </div> |
||
2425 | |||
2426 | <div class='form-group form-check'> |
||
2427 | <input :id='$id + item.id + \"required\"' v-model='item.required' type='checkbox' class='form-check-input' /> |
||
2428 | <label class='form-check-label' :for='$id + item.id + \"required\"'>$label8</label> |
||
2429 | </div> |
||
2430 | |||
2431 | <div class='form-group'> |
||
2432 | <label :for='$id + item.id + \"description\"'>Item Description</label> |
||
2433 | <textarea :id='$id + item.id + \"description\"' v-model='item.description' class='form-control'></textarea> |
||
2434 | </div> |
||
2435 | |||
2436 | <button type='button' class='button button-link button-link-delete' @click.prevent='removeItem(item)'>Delete Item</button> |
||
2437 | |||
2438 | </div> |
||
2439 | </div> |
||
2440 | |||
2441 | </div> |
||
2442 | </draggable> |
||
2443 | |||
2444 | <small v-if='! form_items.length' class='form-text text-danger'> You have not set up any items. Please select an item below or create a new item.</small> |
||
2445 | |||
2446 | <div class='form-group mt-2'> |
||
2447 | |||
2448 | <select class='form-control custom-select' v-model='selected_item'> |
||
2449 | <option value=''>" . __( 'Add an existing item to the form', 'invoicing' ) ."</option> |
||
2450 | <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option> |
||
2451 | </select> |
||
2452 | |||
2453 | </div> |
||
2454 | |||
2455 | <div class='form-group'> |
||
2456 | <input type='button' value='Add item' class='button button-primary' @click.prevent='addSelectedItem' :disabled='selected_item == \"\"'> |
||
2457 | <small>Or <a href='' @click.prevent='addNewItem'>create a new item</a>.</small> |
||
2458 | </div> |
||
2459 | |||
2460 | <div class='form-group mt-5'> |
||
2461 | <label :for='$id2'>$label</label> |
||
2462 | |||
2463 | <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'> |
||
2464 | <option value='total'>" . __( 'Buy all items on the list', 'invoicing' ) ."</option> |
||
2465 | <option value='radio'>" . __( 'Select a single item from the list', 'invoicing' ) ."</option> |
||
2466 | <option value='checkbox'>" . __( 'Select one or more items on the list', 'invoicing' ) ."</option> |
||
2467 | <option value='select'>" . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option> |
||
2468 | <option value='multi_select'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option> |
||
2469 | </select> |
||
2470 | |||
2471 | </div> |
||
2472 | |||
2473 | <div class='form-group'> |
||
2474 | <label :for='$id3'>Help Text</label> |
||
2475 | <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
2476 | </div> |
||
2477 | |||
2478 | </div> |
||
2479 | "; |
||
2480 | |||
2481 | } |
||
2482 | |||
2483 | /** |
||
2484 | * Returns an array of all published items. |
||
2485 | */ |
||
2486 | public function get_published_items() { |
||
2487 | |||
2488 | $item_args = array( |
||
2489 | 'post_type' => 'wpi_item', |
||
2490 | 'orderby' => 'title', |
||
2491 | 'order' => 'ASC', |
||
2492 | 'posts_per_page' => -1, |
||
2493 | 'post_status' => array( 'publish' ), |
||
2494 | ); |
||
2495 | |||
2496 | $items = get_posts( apply_filters( 'wpinv_item_dropdown_query_args', $item_args ) ); |
||
2497 | |||
2498 | if ( empty( $items ) ) { |
||
2499 | return array(); |
||
2500 | } |
||
2501 | |||
2502 | $options = array(); |
||
2503 | foreach ( $items as $item ) { |
||
2504 | $title = esc_html( $item->post_title ); |
||
2505 | $title .= wpinv_get_item_suffix( $item->ID, false ); |
||
2506 | $id = absint( $item->ID ); |
||
2507 | $price = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) ); |
||
2508 | $recurring = (bool) get_post_meta( $id, '_wpinv_is_recurring', true ); |
||
2509 | $description = $item->post_excerpt; |
||
2510 | $custom_price = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true ); |
||
2511 | $minimum_price = (float) get_post_meta( $id, '_minimum_price', true ); |
||
2512 | $allow_quantities = false; |
||
2513 | $options[] = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' ); |
||
2514 | |||
2515 | } |
||
2516 | return $options; |
||
2517 | |||
2518 | } |
||
2519 | |||
2520 | /** |
||
2521 | * Returns an array of items for the currently being edited form. |
||
2522 | */ |
||
2523 | public function get_form_items( $id = false ) { |
||
2536 | |||
2537 | } |
||
2538 | |||
2539 | /** |
||
2540 | * Returns an array of elements for the currently being edited form. |
||
2541 | */ |
||
2542 | public function get_form_elements( $id = false ) { |
||
2543 | |||
2544 | if ( empty( $id ) ) { |
||
2545 | return wpinv_get_data( 'sample-payment-form' ); |
||
2546 | } |
||
2547 | |||
2548 | $form_elements = get_post_meta( $id, 'wpinv_form_elements', true ); |
||
2555 | } |
||
2556 | |||
2557 | } |
||
2558 |