Total Complexity | 98 |
Total Lines | 1870 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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() { |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * Returns the restrict markup. |
||
261 | */ |
||
262 | public function get_restrict_markup( $field, $field_type ) { |
||
263 | $restrict = "$field.type=='$field_type'"; |
||
264 | return "v-if=\"$restrict\""; |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * Renders the title element template. |
||
269 | */ |
||
270 | public function render_heading_template( $field ) { |
||
271 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
272 | echo "<component :is='$field.level' $restrict v-html='$field.text'></component>"; |
||
273 | } |
||
274 | |||
275 | /** |
||
276 | * Renders the title element on the frontend. |
||
277 | */ |
||
278 | public function frontend_render_heading_template( $field ) { |
||
279 | $tag = $field['level']; |
||
280 | echo "<$tag>{$field['text']}</$tag>"; |
||
281 | } |
||
282 | |||
283 | /** |
||
284 | * Renders the edit title element template. |
||
285 | */ |
||
286 | public function edit_heading_template( $field ) { |
||
287 | $restrict = $this->get_restrict_markup( $field, 'heading' ); |
||
288 | $label = __( 'Heading', 'invoicing' ); |
||
289 | $label2 = __( 'Select Heading Level', 'invoicing' ); |
||
290 | $id = $field . '.id + "_edit"'; |
||
291 | $id2 = $field . '.id + "_edit2"'; |
||
292 | |||
293 | echo " |
||
294 | <div $restrict> |
||
295 | <div class='form-group'> |
||
296 | <label :for='$id'>$label</label> |
||
297 | <input class='form-control' :id='$id' v-model='$field.text' type='text' /> |
||
298 | </div> |
||
299 | |||
300 | <div class='form-group'> |
||
301 | <label :for='$id2'>$label2</label> |
||
302 | |||
303 | <select class='form-control custom-select' :id='$id2' v-model='$field.level'> |
||
304 | <option value='h1'>H1</option> |
||
305 | <option value='h2'>H2</option> |
||
306 | <option value='h3'>H3</option> |
||
307 | <option value='h4'>H4</option> |
||
308 | <option value='h5'>H5</option> |
||
309 | <option value='h6'>H6</option> |
||
310 | <option value='h7'>H7</option> |
||
311 | </select> |
||
312 | </div> |
||
313 | </div> |
||
314 | "; |
||
315 | |||
316 | } |
||
317 | |||
318 | /** |
||
319 | * Renders a paragraph element template. |
||
320 | */ |
||
321 | public function render_paragraph_template( $field ) { |
||
322 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
323 | $label = "$field.text"; |
||
324 | echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>"; |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * Renders the paragraph element on the frontend. |
||
329 | */ |
||
330 | public function frontend_render_paragraph_template( $field ) { |
||
331 | echo "<p>{$field['text']}</p>"; |
||
332 | } |
||
333 | |||
334 | /** |
||
335 | * Renders the edit paragraph element template. |
||
336 | */ |
||
337 | public function edit_paragraph_template( $field ) { |
||
338 | $restrict = $this->get_restrict_markup( $field, 'paragraph' ); |
||
339 | $label = __( 'Enter your text', 'invoicing' ); |
||
340 | $id = $field . '.id + "_edit"'; |
||
341 | echo " |
||
342 | <div $restrict> |
||
343 | <div class='form-group'> |
||
344 | <label :for='$id'>$label</label> |
||
345 | <textarea :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
346 | </div> |
||
347 | </div> |
||
348 | "; |
||
349 | |||
350 | } |
||
351 | |||
352 | /** |
||
353 | * Renders the text element template. |
||
354 | */ |
||
355 | public function render_text_template( $field ) { |
||
356 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
357 | $label = "$field.label"; |
||
358 | echo " |
||
359 | <div $restrict> |
||
360 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
361 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='text'> |
||
362 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
363 | </div> |
||
364 | "; |
||
365 | } |
||
366 | |||
367 | /** |
||
368 | * Renders the text element on the frontend. |
||
369 | */ |
||
370 | public function frontend_render_text_template( $field ) { |
||
371 | |||
372 | echo "<div class='form-group'>"; |
||
373 | |||
374 | echo aui()->input( |
||
|
|||
375 | array( |
||
376 | 'name' => esc_attr( $field['id'] ), |
||
377 | 'id' => esc_attr( $field['id'] ), |
||
378 | 'placeholder'=> esc_attr( $field['placeholder'] ), |
||
379 | 'required' => (bool) $field['required'], |
||
380 | 'label' => wp_kses_post( $field['label'] ), |
||
381 | 'no_wrap' => true, |
||
382 | ) |
||
383 | ); |
||
384 | |||
385 | if ( ! empty( $field['description'] ) ) { |
||
386 | $description = wp_kses_post( $field['description'] ); |
||
387 | echo "<small class='form-text text-muted'>$description</small>"; |
||
388 | } |
||
389 | |||
390 | echo '</div>'; |
||
391 | |||
392 | } |
||
393 | |||
394 | /** |
||
395 | * Renders the edit text element template. |
||
396 | */ |
||
397 | public function edit_text_template( $field ) { |
||
398 | $restrict = $this->get_restrict_markup( $field, 'text' ); |
||
399 | $label = __( 'Field Label', 'invoicing' ); |
||
400 | $id = $field . '.id + "_edit"'; |
||
401 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
402 | $id2 = $field . '.id + "_edit2"'; |
||
403 | $label3 = __( 'Help text', 'invoicing' ); |
||
404 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
405 | $id3 = $field . '.id + "_edit3"'; |
||
406 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
407 | $id4 = $field . '.id + "_edit4"'; |
||
408 | echo " |
||
409 | <div $restrict> |
||
410 | <div class='form-group'> |
||
411 | <label :for='$id'>$label</label> |
||
412 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
413 | </div> |
||
414 | <div class='form-group'> |
||
415 | <label :for='$id2'>$label2</label> |
||
416 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
417 | </div> |
||
418 | <div class='form-group'> |
||
419 | <label :for='$id3'>$label3</label> |
||
420 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
421 | </div> |
||
422 | <div class='form-group form-check'> |
||
423 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
424 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
425 | </div> |
||
426 | </div> |
||
427 | "; |
||
428 | |||
429 | } |
||
430 | |||
431 | /** |
||
432 | * Renders the textarea element template. |
||
433 | */ |
||
434 | public function render_textarea_template( $field ) { |
||
435 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
436 | $label = "$field.label"; |
||
437 | echo " |
||
438 | <div $restrict> |
||
439 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
440 | <textarea :placeholder='$field.placeholder' :id='$field.id' class='form-control' rows='3'></textarea> |
||
441 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
442 | </div> |
||
443 | "; |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * Renders the textarea element on the frontend. |
||
448 | */ |
||
449 | public function frontend_render_textarea_template( $field ) { |
||
450 | |||
451 | echo "<div class='form-group'>"; |
||
452 | |||
453 | echo aui()->textarea( |
||
454 | array( |
||
455 | 'name' => esc_attr( $field['id'] ), |
||
456 | 'id' => esc_attr( $field['id'] ), |
||
457 | 'placeholder'=> esc_attr( $field['placeholder'] ), |
||
458 | 'required' => (bool) $field['required'], |
||
459 | 'label' => wp_kses_post( $field['label'] ), |
||
460 | 'no_wrap' => true, |
||
461 | 'rows' => 3, |
||
462 | ) |
||
463 | ); |
||
464 | |||
465 | if ( ! empty( $field['description'] ) ) { |
||
466 | $description = wp_kses_post( $field['description'] ); |
||
467 | echo "<small class='form-text text-muted'>$description</small>"; |
||
468 | } |
||
469 | |||
470 | echo '</div>'; |
||
471 | |||
472 | } |
||
473 | |||
474 | /** |
||
475 | * Renders the edit textarea element template. |
||
476 | */ |
||
477 | public function edit_textarea_template( $field ) { |
||
478 | $restrict = $this->get_restrict_markup( $field, 'textarea' ); |
||
479 | $label = __( 'Field Label', 'invoicing' ); |
||
480 | $id = $field . '.id + "_edit"'; |
||
481 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
482 | $id2 = $field . '.id + "_edit2"'; |
||
483 | $label3 = __( 'Help text', 'invoicing' ); |
||
484 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
485 | $id3 = $field . '.id + "_edit3"'; |
||
486 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
487 | $id4 = $field . '.id + "_edit4"'; |
||
488 | echo " |
||
489 | <div $restrict> |
||
490 | <div class='form-group'> |
||
491 | <label :for='$id'>$label</label> |
||
492 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
493 | </div> |
||
494 | <div class='form-group'> |
||
495 | <label :for='$id2'>$label2</label> |
||
496 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
497 | </div> |
||
498 | <div class='form-group'> |
||
499 | <label :for='$id3'>$label3</label> |
||
500 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
501 | </div> |
||
502 | <div class='form-group form-check'> |
||
503 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
504 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
505 | </div> |
||
506 | </div> |
||
507 | "; |
||
508 | |||
509 | } |
||
510 | |||
511 | /** |
||
512 | * Renders the select element template. |
||
513 | */ |
||
514 | public function render_select_template( $field ) { |
||
515 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
516 | $label = "$field.label"; |
||
517 | $placeholder = "$field.placeholder"; |
||
518 | $id = $field . '.id'; |
||
519 | echo " |
||
520 | <div $restrict> |
||
521 | <label :for='$id'>{{" . $label . "}}</label> |
||
522 | <select id='$id' class='form-control custom-select' v-model='$field.value'> |
||
523 | <option v-if='$placeholder' value='' disabled>{{" . $placeholder . "}}</option> |
||
524 | <option v-for='option in $field.options' value='option'>{{option}}</option> |
||
525 | </select> |
||
526 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
527 | </div> |
||
528 | "; |
||
529 | } |
||
530 | |||
531 | /** |
||
532 | * Renders the select element on the frontend. |
||
533 | */ |
||
534 | public function frontend_render_select_template( $field ) { |
||
535 | |||
536 | echo "<div class='form-group'>"; |
||
537 | |||
538 | echo aui()->select( |
||
539 | array( |
||
540 | 'name' => esc_attr( $field['id'] ), |
||
541 | 'id' => esc_attr( $field['id'] ), |
||
542 | 'placeholder'=> esc_attr( $field['placeholder'] ), |
||
543 | 'required' => (bool) $field['required'], |
||
544 | 'label' => wp_kses_post( $field['label'] ), |
||
545 | 'no_wrap' => true, |
||
546 | 'options' => $field['options'], |
||
547 | ) |
||
548 | ); |
||
549 | |||
550 | if ( ! empty( $field['description'] ) ) { |
||
551 | $description = wp_kses_post( $field['description'] ); |
||
552 | echo "<small class='form-text text-muted'>$description</small>"; |
||
553 | } |
||
554 | |||
555 | echo '</div>'; |
||
556 | |||
557 | } |
||
558 | |||
559 | /** |
||
560 | * Renders the edit select element template. |
||
561 | */ |
||
562 | public function edit_select_template( $field ) { |
||
563 | $restrict = $this->get_restrict_markup( $field, 'select' ); |
||
564 | $label = __( 'Field Label', 'invoicing' ); |
||
565 | $id = $field . '.id + "_edit"'; |
||
566 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
567 | $id2 = $field . '.id + "_edit2"'; |
||
568 | $label3 = __( 'Help text', 'invoicing' ); |
||
569 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
570 | $id3 = $field . '.id + "_edit3"'; |
||
571 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
572 | $id4 = $field . '.id + "_edit4"'; |
||
573 | $label6 = __( 'Available Options', 'invoicing' ); |
||
574 | echo " |
||
575 | <div $restrict> |
||
576 | <div class='form-group'> |
||
577 | <label :for='$id'>$label</label> |
||
578 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
579 | </div> |
||
580 | <div class='form-group'> |
||
581 | <label :for='$id2'>$label2</label> |
||
582 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
583 | </div> |
||
584 | <div class='form-group'> |
||
585 | <label :for='$id3'>$label3</label> |
||
586 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
587 | </div> |
||
588 | <div class='form-group form-check'> |
||
589 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
590 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
591 | </div> |
||
592 | <hr class='featurette-divider mt-4'> |
||
593 | <h5>$label6</h5> |
||
594 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
595 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
596 | <div class='input-group-append'> |
||
597 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
598 | </div> |
||
599 | </div> |
||
600 | <div class='form-group'> |
||
601 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
602 | </div> |
||
603 | </div> |
||
604 | "; |
||
605 | |||
606 | } |
||
607 | |||
608 | /** |
||
609 | * Renders the checkbox element template. |
||
610 | */ |
||
611 | public function render_checkbox_template( $field ) { |
||
612 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
613 | $label = "$field.label"; |
||
614 | echo " |
||
615 | <div class='form-check' $restrict> |
||
616 | <input :id='$field.id' class='form-check-input' type='checkbox' /> |
||
617 | <label class='form-check-label' :for='$field.id'>{{" . $label . "}}</label> |
||
618 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
619 | </div> |
||
620 | "; |
||
621 | } |
||
622 | |||
623 | /** |
||
624 | * Renders the checkbox element on the frontend. |
||
625 | */ |
||
626 | public function frontend_render_checkbox_template( $field ) { |
||
627 | |||
628 | echo "<div class='form-group'>"; |
||
629 | |||
630 | echo aui()->input( |
||
631 | array( |
||
632 | 'name' => esc_attr( $field['id'] ), |
||
633 | 'id' => esc_attr( $field['id'] ), |
||
634 | 'required' => (bool) $field['required'], |
||
635 | 'label' => wp_kses_post( $field['label'] ), |
||
636 | 'no_wrap' => true, |
||
637 | 'type' => 'checkbox', |
||
638 | ) |
||
639 | ); |
||
640 | |||
641 | if ( ! empty( $field['description'] ) ) { |
||
642 | $description = wp_kses_post( $field['description'] ); |
||
643 | echo "<small class='form-text text-muted'>$description</small>"; |
||
644 | } |
||
645 | |||
646 | echo '</div>'; |
||
647 | |||
648 | } |
||
649 | |||
650 | /** |
||
651 | * Renders the edit checkbox element template. |
||
652 | */ |
||
653 | public function edit_checkbox_template( $field ) { |
||
654 | $restrict = $this->get_restrict_markup( $field, 'checkbox' ); |
||
655 | $label = __( 'Field Label', 'invoicing' ); |
||
656 | $id = $field . '.id + "_edit"'; |
||
657 | $label2 = __( 'Help text', 'invoicing' ); |
||
658 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
659 | $id2 = $field . '.id + "_edit2"'; |
||
660 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
661 | $id3 = $field . '.id + "_edit3"'; |
||
662 | echo " |
||
663 | <div $restrict> |
||
664 | <div class='form-group'> |
||
665 | <label :for='$id'>$label</label> |
||
666 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
667 | </div> |
||
668 | <div class='form-group'> |
||
669 | <label :for='$id2'>$label2</label> |
||
670 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
671 | </div> |
||
672 | <div class='form-group form-check'> |
||
673 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
674 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
675 | </div> |
||
676 | </div> |
||
677 | "; |
||
678 | |||
679 | } |
||
680 | |||
681 | /** |
||
682 | * Renders the radio element template. |
||
683 | */ |
||
684 | public function render_radio_template( $field ) { |
||
685 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
686 | $label = "$field.label"; |
||
687 | $id = $field . '.id'; |
||
688 | echo " |
||
689 | <div $restrict> |
||
690 | <legend class='col-form-label' v-if='$label'>{{" . $label . "}}</legend> |
||
691 | <div class='form-check' v-for='(option, index) in $field.options'> |
||
692 | <input class='form-check-input' type='radio' :id='$id + index'> |
||
693 | <label class='form-check-label' :for='$id + index'>{{option}}</label> |
||
694 | </div> |
||
695 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
696 | </div> |
||
697 | "; |
||
698 | } |
||
699 | |||
700 | /** |
||
701 | * Renders the radio element on the frontend. |
||
702 | */ |
||
703 | public function frontend_render_radio_template( $field ) { |
||
704 | |||
705 | echo "<div class='form-group'>"; |
||
706 | |||
707 | if ( ! empty( $field['label'] ) ) { |
||
708 | $label = wp_kses_post( $field['label'] ); |
||
709 | echo "<legend class='col-form-label'>$label</legend>"; |
||
710 | } |
||
711 | |||
712 | foreach( $field['options'] as $index => $option ) { |
||
713 | $id = $field['id'] . $index; |
||
714 | $value = esc_attr( $option ); |
||
715 | $label = wp_kses_post( $option ); |
||
716 | |||
717 | echo " |
||
718 | <div class='form-check'> |
||
719 | <input class='form-check-input' type='radio' id='$id' value='$value'> |
||
720 | <label class='form-check-label' for='$id'>$label</label> |
||
721 | </div> |
||
722 | "; |
||
723 | } |
||
724 | |||
725 | if ( ! empty( $field['description'] ) ) { |
||
726 | $description = wp_kses_post( $field['description'] ); |
||
727 | echo "<small class='form-text text-muted'>$description</small>"; |
||
728 | } |
||
729 | |||
730 | echo '</div>'; |
||
731 | |||
732 | } |
||
733 | |||
734 | /** |
||
735 | * Renders the edit radio element template. |
||
736 | */ |
||
737 | public function edit_radio_template( $field ) { |
||
738 | $restrict = $this->get_restrict_markup( $field, 'radio' ); |
||
739 | $label = __( 'Field Label', 'invoicing' ); |
||
740 | $id = $field . '.id + "_edit"'; |
||
741 | $label2 = __( 'Help text', 'invoicing' ); |
||
742 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
743 | $id2 = $field . '.id + "_edit3"'; |
||
744 | $label4 = __( 'Is this field required?', 'invoicing' ); |
||
745 | $id3 = $field . '.id + "_edit4"'; |
||
746 | $label5 = __( 'Available Options', 'invoicing' ); |
||
747 | echo " |
||
748 | <div $restrict> |
||
749 | <div class='form-group'> |
||
750 | <label :for='$id'>$label</label> |
||
751 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
752 | </div> |
||
753 | <div class='form-group'> |
||
754 | <label :for='$id2'>$label2</label> |
||
755 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
756 | </div> |
||
757 | <div class='form-group form-check'> |
||
758 | <input :id='$id3' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
759 | <label class='form-check-label' :for='$id3'>$label4</label> |
||
760 | </div> |
||
761 | <hr class='featurette-divider mt-4'> |
||
762 | <h5>$label5</h5> |
||
763 | <div class='form-group input-group' v-for='(option, index) in $field.options'> |
||
764 | <input type='text' class='form-control' v-model='$field.options[index]'> |
||
765 | <div class='input-group-append'> |
||
766 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.splice(index, 1)'><span class='dashicons dashicons-trash'></span></button> |
||
767 | </div> |
||
768 | </div> |
||
769 | <div class='form-group'> |
||
770 | <button class='btn btn-outline-secondary' type='button' @click.prevent='$field.options.push(\"\")'>Add Option</button> |
||
771 | </div> |
||
772 | </div> |
||
773 | "; |
||
774 | |||
775 | } |
||
776 | |||
777 | /** |
||
778 | * Renders the email element template. |
||
779 | */ |
||
780 | public function render_email_template( $field ) { |
||
781 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
782 | $label = "$field.label"; |
||
783 | echo " |
||
784 | <div $restrict> |
||
785 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
786 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
787 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
788 | </div> |
||
789 | "; |
||
790 | } |
||
791 | |||
792 | /** |
||
793 | * Renders the billing_email element template. |
||
794 | */ |
||
795 | public function render_billing_email_template( $field ) { |
||
796 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
797 | $label = "$field.label"; |
||
798 | echo " |
||
799 | <div $restrict> |
||
800 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
801 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='email'> |
||
802 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
803 | </div> |
||
804 | "; |
||
805 | } |
||
806 | |||
807 | /** |
||
808 | * Renders the email element on the frontend. |
||
809 | */ |
||
810 | public function frontend_render_email_template( $field ) { |
||
811 | |||
812 | echo "<div class='form-group'>"; |
||
813 | |||
814 | echo aui()->input( |
||
815 | array( |
||
816 | 'name' => esc_attr( $field['id'] ), |
||
817 | 'id' => esc_attr( $field['id'] ), |
||
818 | 'required' => (bool) $field['required'], |
||
819 | 'label' => wp_kses_post( $field['label'] ), |
||
820 | 'no_wrap' => true, |
||
821 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
822 | 'type' => 'email', |
||
823 | ) |
||
824 | ); |
||
825 | |||
826 | if ( ! empty( $field['description'] ) ) { |
||
827 | $description = wp_kses_post( $field['description'] ); |
||
828 | echo "<small class='form-text text-muted'>$description</small>"; |
||
829 | } |
||
830 | |||
831 | echo '</div>'; |
||
832 | |||
833 | } |
||
834 | |||
835 | /** |
||
836 | * Renders the billing email element on the frontend. |
||
837 | */ |
||
838 | public function frontend_render_billing_email_template( $field ) { |
||
839 | |||
840 | echo "<div class='form-group'>"; |
||
841 | |||
842 | echo aui()->input( |
||
843 | array( |
||
844 | 'name' => 'billing_email', |
||
845 | 'id' => esc_attr( $field['id'] ), |
||
846 | 'required' => true, |
||
847 | 'label' => wp_kses_post( $field['label'] ), |
||
848 | 'no_wrap' => true, |
||
849 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
850 | 'type' => 'email', |
||
851 | ) |
||
852 | ); |
||
853 | |||
854 | if ( ! empty( $field['description'] ) ) { |
||
855 | $description = wp_kses_post( $field['description'] ); |
||
856 | echo "<small class='form-text text-muted'>$description</small>"; |
||
857 | } |
||
858 | |||
859 | echo '</div>'; |
||
860 | |||
861 | } |
||
862 | |||
863 | /** |
||
864 | * Renders the edit email element template. |
||
865 | */ |
||
866 | public function edit_email_template( $field ) { |
||
867 | $restrict = $this->get_restrict_markup( $field, 'email' ); |
||
868 | $label = __( 'Field Label', 'invoicing' ); |
||
869 | $id = $field . '.id + "_edit"'; |
||
870 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
871 | $id2 = $field . '.id + "_edit2"'; |
||
872 | $label3 = __( 'Help text', 'invoicing' ); |
||
873 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
874 | $id3 = $field . '.id + "_edit3"'; |
||
875 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
876 | $id4 = $field . '.id + "_edit4"'; |
||
877 | echo " |
||
878 | <div $restrict> |
||
879 | <div class='form-group'> |
||
880 | <label :for='$id'>$label</label> |
||
881 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
882 | </div> |
||
883 | <div class='form-group'> |
||
884 | <label :for='$id2'>$label2</label> |
||
885 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
886 | </div> |
||
887 | <div class='form-group'> |
||
888 | <label :for='$id3'>$label3</label> |
||
889 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
890 | </div> |
||
891 | <div class='form-group form-check'> |
||
892 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
893 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
894 | </div> |
||
895 | </div> |
||
896 | "; |
||
897 | |||
898 | } |
||
899 | |||
900 | /** |
||
901 | * Renders the edit billing_email element template. |
||
902 | */ |
||
903 | public function edit_billing_email_template( $field ) { |
||
904 | $restrict = $this->get_restrict_markup( $field, 'billing_email' ); |
||
905 | $label = __( 'Field Label', 'invoicing' ); |
||
906 | $id = $field . '.id + "_edit"'; |
||
907 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
908 | $id2 = $field . '.id + "_edit2"'; |
||
909 | $label3 = __( 'Help text', 'invoicing' ); |
||
910 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
911 | $id3 = $field . '.id + "_edit3"'; |
||
912 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
913 | $id4 = $field . '.id + "_edit4"'; |
||
914 | echo " |
||
915 | <div $restrict> |
||
916 | <div class='form-group'> |
||
917 | <label :for='$id'>$label</label> |
||
918 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
919 | </div> |
||
920 | <div class='form-group'> |
||
921 | <label :for='$id2'>$label2</label> |
||
922 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
923 | </div> |
||
924 | <div class='form-group'> |
||
925 | <label :for='$id3'>$label3</label> |
||
926 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
927 | </div> |
||
928 | </div> |
||
929 | "; |
||
930 | |||
931 | } |
||
932 | |||
933 | /** |
||
934 | * Renders the website element template. |
||
935 | */ |
||
936 | public function render_website_template( $field ) { |
||
937 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
938 | $label = "$field.label"; |
||
939 | echo " |
||
940 | <div $restrict> |
||
941 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
942 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='url'> |
||
943 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
944 | </div> |
||
945 | "; |
||
946 | } |
||
947 | |||
948 | /** |
||
949 | * Renders the website element on the frontend. |
||
950 | */ |
||
951 | public function frontend_render_website_template( $field ) { |
||
952 | |||
953 | echo "<div class='form-group'>"; |
||
954 | |||
955 | echo aui()->input( |
||
956 | array( |
||
957 | 'name' => esc_attr( $field['id'] ), |
||
958 | 'id' => esc_attr( $field['id'] ), |
||
959 | 'required' => (bool) $field['required'], |
||
960 | 'label' => wp_kses_post( $field['label'] ), |
||
961 | 'no_wrap' => true, |
||
962 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
963 | 'type' => 'url', |
||
964 | ) |
||
965 | ); |
||
966 | |||
967 | if ( ! empty( $field['description'] ) ) { |
||
968 | $description = wp_kses_post( $field['description'] ); |
||
969 | echo "<small class='form-text text-muted'>$description</small>"; |
||
970 | } |
||
971 | |||
972 | echo '</div>'; |
||
973 | |||
974 | } |
||
975 | |||
976 | /** |
||
977 | * Renders the edit website element template. |
||
978 | */ |
||
979 | public function edit_website_template( $field ) { |
||
980 | $restrict = $this->get_restrict_markup( $field, 'website' ); |
||
981 | $label = __( 'Field Label', 'invoicing' ); |
||
982 | $id = $field . '.id + "_edit"'; |
||
983 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
984 | $id2 = $field . '.id + "_edit2"'; |
||
985 | $label3 = __( 'Help text', 'invoicing' ); |
||
986 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
987 | $id3 = $field . '.id + "_edit3"'; |
||
988 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
989 | $id4 = $field . '.id + "_edit4"'; |
||
990 | echo " |
||
991 | <div $restrict> |
||
992 | <div class='form-group'> |
||
993 | <label :for='$id'>$label</label> |
||
994 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
995 | </div> |
||
996 | <div class='form-group'> |
||
997 | <label :for='$id2'>$label2</label> |
||
998 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
999 | </div> |
||
1000 | <div class='form-group'> |
||
1001 | <label :for='$id3'>$label3</label> |
||
1002 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1003 | </div> |
||
1004 | <div class='form-group form-check'> |
||
1005 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1006 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1007 | </div> |
||
1008 | </div> |
||
1009 | "; |
||
1010 | |||
1011 | } |
||
1012 | |||
1013 | /** |
||
1014 | * Renders the date element template. |
||
1015 | */ |
||
1016 | public function render_date_template( $field ) { |
||
1017 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
1018 | $label = "$field.label"; |
||
1019 | echo " |
||
1020 | <div $restrict> |
||
1021 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1022 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='date'> |
||
1023 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1024 | </div> |
||
1025 | "; |
||
1026 | } |
||
1027 | |||
1028 | /** |
||
1029 | * Renders the date element on the frontend. |
||
1030 | */ |
||
1031 | public function frontend_render_date_template( $field ) { |
||
1032 | |||
1033 | echo "<div class='form-group'>"; |
||
1034 | |||
1035 | echo aui()->input( |
||
1036 | array( |
||
1037 | 'name' => esc_attr( $field['id'] ), |
||
1038 | 'id' => esc_attr( $field['id'] ), |
||
1039 | 'required' => (bool) $field['required'], |
||
1040 | 'label' => wp_kses_post( $field['label'] ), |
||
1041 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1042 | 'no_wrap' => true, |
||
1043 | 'type' => 'date', |
||
1044 | ) |
||
1045 | ); |
||
1046 | |||
1047 | if ( ! empty( $field['description'] ) ) { |
||
1048 | $description = wp_kses_post( $field['description'] ); |
||
1049 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1050 | } |
||
1051 | |||
1052 | echo '</div>'; |
||
1053 | |||
1054 | } |
||
1055 | |||
1056 | /** |
||
1057 | * Renders the edit date element template. |
||
1058 | */ |
||
1059 | public function edit_date_template( $field ) { |
||
1060 | $restrict = $this->get_restrict_markup( $field, 'date' ); |
||
1061 | $label = __( 'Field Label', 'invoicing' ); |
||
1062 | $id = $field . '.id + "_edit"'; |
||
1063 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1064 | $id2 = $field . '.id + "_edit2"'; |
||
1065 | $label3 = __( 'Help text', 'invoicing' ); |
||
1066 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1067 | $id3 = $field . '.id + "_edit3"'; |
||
1068 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1069 | $id4 = $field . '.id + "_edit4"'; |
||
1070 | echo " |
||
1071 | <div $restrict> |
||
1072 | <div class='form-group'> |
||
1073 | <label :for='$id'>$label</label> |
||
1074 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1075 | </div> |
||
1076 | <div class='form-group'> |
||
1077 | <label :for='$id2'>$label2</label> |
||
1078 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1079 | </div> |
||
1080 | <div class='form-group'> |
||
1081 | <label :for='$id3'>$label3</label> |
||
1082 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1083 | </div> |
||
1084 | <div class='form-group form-check'> |
||
1085 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1086 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1087 | </div> |
||
1088 | </div> |
||
1089 | "; |
||
1090 | |||
1091 | } |
||
1092 | |||
1093 | /** |
||
1094 | * Renders the time element template. |
||
1095 | */ |
||
1096 | public function render_time_template( $field ) { |
||
1097 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
1098 | $label = "$field.label"; |
||
1099 | echo " |
||
1100 | <div $restrict> |
||
1101 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1102 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='time'> |
||
1103 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1104 | </div> |
||
1105 | "; |
||
1106 | } |
||
1107 | |||
1108 | /** |
||
1109 | * Renders the time element on the frontend. |
||
1110 | */ |
||
1111 | public function frontend_render_time_template( $field ) { |
||
1112 | |||
1113 | echo "<div class='form-group'>"; |
||
1114 | |||
1115 | echo aui()->input( |
||
1116 | array( |
||
1117 | 'name' => esc_attr( $field['id'] ), |
||
1118 | 'id' => esc_attr( $field['id'] ), |
||
1119 | 'required' => (bool) $field['required'], |
||
1120 | 'label' => wp_kses_post( $field['label'] ), |
||
1121 | 'no_wrap' => true, |
||
1122 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1123 | 'type' => 'time', |
||
1124 | ) |
||
1125 | ); |
||
1126 | |||
1127 | if ( ! empty( $field['description'] ) ) { |
||
1128 | $description = wp_kses_post( $field['description'] ); |
||
1129 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1130 | } |
||
1131 | |||
1132 | echo '</div>'; |
||
1133 | |||
1134 | } |
||
1135 | |||
1136 | /** |
||
1137 | * Renders the edit time element template. |
||
1138 | */ |
||
1139 | public function edit_time_template( $field ) { |
||
1140 | $restrict = $this->get_restrict_markup( $field, 'time' ); |
||
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 class='form-group form-check'> |
||
1165 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1166 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1167 | </div> |
||
1168 | </div> |
||
1169 | "; |
||
1170 | |||
1171 | } |
||
1172 | |||
1173 | /** |
||
1174 | * Renders the number element template. |
||
1175 | */ |
||
1176 | public function render_number_template( $field ) { |
||
1177 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
1178 | $label = "$field.label"; |
||
1179 | echo " |
||
1180 | <div $restrict> |
||
1181 | <label :for='$field.id'>{{" . $label . "}}</label> |
||
1182 | <input :placeholder='$field.placeholder' :id='$field.id' class='form-control' type='number'> |
||
1183 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1184 | </div> |
||
1185 | "; |
||
1186 | } |
||
1187 | |||
1188 | /** |
||
1189 | * Renders the number element on the frontend. |
||
1190 | */ |
||
1191 | public function frontend_render_number_template( $field ) { |
||
1192 | |||
1193 | echo "<div class='form-group'>"; |
||
1194 | |||
1195 | echo aui()->input( |
||
1196 | array( |
||
1197 | 'name' => esc_attr( $field['id'] ), |
||
1198 | 'id' => esc_attr( $field['id'] ), |
||
1199 | 'required' => (bool) $field['required'], |
||
1200 | 'label' => wp_kses_post( $field['label'] ), |
||
1201 | 'placeholder' => esc_attr( $field['placeholder'] ), |
||
1202 | 'no_wrap' => true, |
||
1203 | 'type' => 'number', |
||
1204 | ) |
||
1205 | ); |
||
1206 | |||
1207 | if ( ! empty( $field['description'] ) ) { |
||
1208 | $description = wp_kses_post( $field['description'] ); |
||
1209 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1210 | } |
||
1211 | |||
1212 | echo '</div>'; |
||
1213 | |||
1214 | } |
||
1215 | |||
1216 | /** |
||
1217 | * Renders the edit number element template. |
||
1218 | */ |
||
1219 | public function edit_number_template( $field ) { |
||
1220 | $restrict = $this->get_restrict_markup( $field, 'number' ); |
||
1221 | $label = __( 'Field Label', 'invoicing' ); |
||
1222 | $id = $field . '.id + "_edit"'; |
||
1223 | $label2 = __( 'Placeholder text', 'invoicing' ); |
||
1224 | $id2 = $field . '.id + "_edit2"'; |
||
1225 | $label3 = __( 'Help text', 'invoicing' ); |
||
1226 | $label4 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1227 | $id3 = $field . '.id + "_edit3"'; |
||
1228 | $label5 = __( 'Is this field required?', 'invoicing' ); |
||
1229 | $id4 = $field . '.id + "_edit4"'; |
||
1230 | echo " |
||
1231 | <div $restrict> |
||
1232 | <div class='form-group'> |
||
1233 | <label :for='$id'>$label</label> |
||
1234 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1235 | </div> |
||
1236 | <div class='form-group'> |
||
1237 | <label :for='$id2'>$label2</label> |
||
1238 | <input :id='$id2' v-model='$field.placeholder' class='form-control' /> |
||
1239 | </div> |
||
1240 | <div class='form-group'> |
||
1241 | <label :for='$id3'>$label3</label> |
||
1242 | <textarea placeholder='$label4' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1243 | </div> |
||
1244 | <div class='form-group form-check'> |
||
1245 | <input :id='$id4' v-model='$field.required' type='checkbox' class='form-check-input' /> |
||
1246 | <label class='form-check-label' :for='$id4'>$label5</label> |
||
1247 | </div> |
||
1248 | </div> |
||
1249 | "; |
||
1250 | |||
1251 | } |
||
1252 | |||
1253 | /** |
||
1254 | * Renders the separator element template. |
||
1255 | */ |
||
1256 | public function render_separator_template( $field ) { |
||
1257 | $restrict = $this->get_restrict_markup( $field, 'separator' ); |
||
1258 | echo "<hr class='featurette-divider mt-0 mb-2' $restrict>"; |
||
1259 | } |
||
1260 | |||
1261 | /** |
||
1262 | * Renders the separator element on the frontend. |
||
1263 | */ |
||
1264 | public function frontend_render_separator_template( $field ) { |
||
1265 | echo '<hr class="featurette-divider mt-0 mb-2" />'; |
||
1266 | } |
||
1267 | |||
1268 | /** |
||
1269 | * Renders the pay button element template. |
||
1270 | */ |
||
1271 | public function render_pay_button_template( $field ) { |
||
1272 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
1273 | $label = "$field.label"; |
||
1274 | echo " |
||
1275 | <div $restrict> |
||
1276 | <button class='form-control btn submit-button' :class='$field.class' type='submit' @click.prevent=''>{{" . $label . "}}</button> |
||
1277 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1278 | </div> |
||
1279 | "; |
||
1280 | } |
||
1281 | |||
1282 | /** |
||
1283 | * Renders the pay_button element on the frontend. |
||
1284 | */ |
||
1285 | public function frontend_render_pay_button_template( $field ) { |
||
1286 | |||
1287 | echo "<div class='form-group'>"; |
||
1288 | |||
1289 | $class = 'btn btn-block submit-button ' . sanitize_html_class( $field['class'] ); |
||
1290 | echo aui()->button( |
||
1291 | array( |
||
1292 | 'name' => esc_attr( $field['id'] ), |
||
1293 | 'id' => esc_attr( $field['id'] ), |
||
1294 | 'content' => wp_kses_post( $field['label'] ), |
||
1295 | 'no_wrap' => true, |
||
1296 | 'type' => 'button', |
||
1297 | 'class' => $class, |
||
1298 | ) |
||
1299 | ); |
||
1300 | |||
1301 | if ( ! empty( $field['description'] ) ) { |
||
1302 | $description = wp_kses_post( $field['description'] ); |
||
1303 | echo "<small class='form-text text-muted'>$description</small>"; |
||
1304 | } |
||
1305 | |||
1306 | echo '</div>'; |
||
1307 | |||
1308 | } |
||
1309 | |||
1310 | /** |
||
1311 | * Renders the pay button element template. |
||
1312 | */ |
||
1313 | public function edit_pay_button_template( $field ) { |
||
1314 | $restrict = $this->get_restrict_markup( $field, 'pay_button' ); |
||
1315 | $label = __( 'Button Text', 'invoicing' ); |
||
1316 | $id = $field . '.id + "_edit"'; |
||
1317 | $label2 = __( 'Help text', 'invoicing' ); |
||
1318 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1319 | $id2 = $field . '.id + "_edit2"'; |
||
1320 | $label4 = esc_attr__( 'Button Type', 'invoicing' ); |
||
1321 | $id3 = $field . '.id + "_edit3"'; |
||
1322 | echo " |
||
1323 | <div $restrict> |
||
1324 | <div class='form-group'> |
||
1325 | <label :for='$id'>$label</label> |
||
1326 | <input :id='$id' v-model='$field.label' class='form-control' /> |
||
1327 | </div> |
||
1328 | <div class='form-group'> |
||
1329 | <label :for='$id2'>$label2</label> |
||
1330 | <textarea placeholder='$label3' :id='$id2' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1331 | </div> |
||
1332 | <div class='form-group'> |
||
1333 | <label :for='$id3'>$label4</label> |
||
1334 | |||
1335 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
1336 | <option value='btn-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
1337 | <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
1338 | <option value='btn-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
1339 | <option value='btn-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
1340 | <option value='btn-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
1341 | <option value='btn-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
1342 | <option value='btn-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
1343 | <option value='btn-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
1344 | <option value='btn-link'>" . __( 'Link', 'invoicing' ) ."</option> |
||
1345 | </select> |
||
1346 | </div> |
||
1347 | </div> |
||
1348 | "; |
||
1349 | |||
1350 | } |
||
1351 | |||
1352 | /** |
||
1353 | * Renders the alert element template. |
||
1354 | */ |
||
1355 | public function render_alert_template( $field ) { |
||
1356 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
1357 | $text = "$field.text"; |
||
1358 | echo " |
||
1359 | <div $restrict class='alert' :class='$field.class' role='alert'> |
||
1360 | <span v-html='$text'></span> |
||
1361 | <button v-if='$field.dismissible' type='button' class='close' @click.prevent=''> |
||
1362 | <span aria-hidden='true'>×</span> |
||
1363 | </button> |
||
1364 | </div> |
||
1365 | "; |
||
1366 | } |
||
1367 | |||
1368 | /** |
||
1369 | * Renders the alert element on the frontend. |
||
1370 | */ |
||
1371 | public function frontend_render_alert_template( $field ) { |
||
1384 | |||
1385 | } |
||
1386 | |||
1387 | /** |
||
1388 | * Renders the alert element template. |
||
1389 | */ |
||
1390 | public function edit_alert_template( $field ) { |
||
1391 | $restrict = $this->get_restrict_markup( $field, 'alert' ); |
||
1392 | $label = __( 'Alert Text', 'invoicing' ); |
||
1393 | $label2 = esc_attr__( 'Enter your alert text here', 'invoicing' ); |
||
1394 | $id = $field . '.id + "_edit"'; |
||
1395 | $label3 = __( 'Is Dismissible?', 'invoicing' ); |
||
1396 | $id2 = $field . '.id + "_edit2"'; |
||
1397 | $label4 = esc_attr__( 'Alert Type', 'invoicing' ); |
||
1398 | $id3 = $field . '.id + "_edit3"'; |
||
1399 | echo " |
||
1400 | <div $restrict> |
||
1401 | <div class='form-group'> |
||
1402 | <label :for='$id'>$label</label> |
||
1403 | <textarea placeholder='$label2' :id='$id' v-model='$field.text' class='form-control' rows='3'></textarea> |
||
1404 | </div> |
||
1405 | <div class='form-group form-check'> |
||
1406 | <input :id='$id2' v-model='$field.dismissible' type='checkbox' class='form-check-input' /> |
||
1407 | <label class='form-check-label' :for='$id2'>$label3</label> |
||
1408 | </div> |
||
1409 | <div class='form-group'> |
||
1410 | <label :for='$id3'>$label4</label> |
||
1411 | |||
1412 | <select class='form-control custom-select' :id='$id3' v-model='$field.class'> |
||
1413 | <option value='alert-primary'>" . __( 'Primary', 'invoicing' ) ."</option> |
||
1414 | <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option> |
||
1415 | <option value='alert-success'>" . __( 'Success', 'invoicing' ) ."</option> |
||
1416 | <option value='alert-danger'>" . __( 'Danger', 'invoicing' ) ."</option> |
||
1417 | <option value='alert-warning'>" . __( 'Warning', 'invoicing' ) ."</option> |
||
1418 | <option value='alert-info'>" . __( 'Info', 'invoicing' ) ."</option> |
||
1419 | <option value='alert-light'>" . __( 'Light', 'invoicing' ) ."</option> |
||
1420 | <option value='alert-dark'>" . __( 'Dark', 'invoicing' ) ."</option> |
||
1421 | </select> |
||
1422 | </div> |
||
1423 | </div> |
||
1424 | "; |
||
1425 | |||
1426 | } |
||
1427 | |||
1428 | /** |
||
1429 | * Renders the discount element template. |
||
1430 | */ |
||
1431 | public function render_discount_template( $field ) { |
||
1432 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
1433 | ?> |
||
1434 | |||
1435 | <div <?php echo $restrict; ?> class="discount_field border rounded p-3"> |
||
1436 | <div class="discount_field_inner d-flex flex-column flex-md-row"> |
||
1437 | <input :placeholder="<?php echo $field ?>.input_label" class="form-control mr-2 mb-2" style="flex: 1;" type="text"> |
||
1438 | <button class="btn btn-secondary submit-button mb-2" type="submit" @click.prevent="">{{<?php echo $field; ?>.button_label}}</button> |
||
1439 | </div> |
||
1440 | <small v-if='<?php echo $field ?>.description' class='form-text text-muted' v-html='<?php echo $field ?>.description'></small> |
||
1441 | </div> |
||
1442 | |||
1443 | <?php |
||
1444 | } |
||
1445 | |||
1446 | /** |
||
1447 | * Renders the discount element on the frontend. |
||
1448 | */ |
||
1449 | public function frontend_render_discount_template( $field ) { |
||
1450 | |||
1451 | $placeholder = esc_attr( $field['input_label'] ); |
||
1452 | $label = sanitize_text_field( $field['button_label'] ); |
||
1453 | $description = ''; |
||
1454 | |||
1455 | if ( ! empty( $field['description'] ) ) { |
||
1456 | $description = "<small class='form-text text-muted'>{$field['description']}</small>"; |
||
1457 | } |
||
1458 | ?> |
||
1459 | |||
1460 | <div class="form-group"> |
||
1461 | <div class="discount_field border rounded p-3"> |
||
1462 | <div class="discount_field_inner d-flex flex-column flex-md-row"> |
||
1463 | <input placeholder="<?php echo $placeholder; ?>" class="form-control mr-2 mb-2" style="flex: 1;" type="text"> |
||
1464 | <button class="btn btn-secondary submit-button mb-2 wpinv-payment-form-coupon-button" type="submit"><?php echo $label; ?></button> |
||
1465 | </div> |
||
1466 | <?php echo $description ?> |
||
1467 | </div> |
||
1468 | </div> |
||
1469 | |||
1470 | <?php |
||
1471 | } |
||
1472 | |||
1473 | /** |
||
1474 | * Renders the discount element template. |
||
1475 | */ |
||
1476 | public function edit_discount_template( $field ) { |
||
1477 | $restrict = $this->get_restrict_markup( $field, 'discount' ); |
||
1478 | $label = __( 'Discount Input Placeholder', 'invoicing' ); |
||
1479 | $label2 = __( 'Help Text', 'invoicing' ); |
||
1480 | $label3 = esc_attr__( 'Add some help text for this field', 'invoicing' ); |
||
1481 | $label4 = __( 'Button Text', 'invoicing' ); |
||
1482 | $id = $field . '.id + "_edit"'; |
||
1483 | $id2 = $field . '.id + "_edit2"'; |
||
1484 | $id3 = $field . '.id + "_edit3"'; |
||
1485 | echo " |
||
1486 | <div $restrict> |
||
1487 | <div class='form-group'> |
||
1488 | <label :for='$id'>$label</label> |
||
1489 | <input :id='$id' v-model='$field.input_label' class='form-control' /> |
||
1490 | </div> |
||
1491 | |||
1492 | <div class='form-group'> |
||
1493 | <label :for='$id2'>$label4</label> |
||
1494 | <input :id='$id2' v-model='$field.button_label' class='form-control' /> |
||
1495 | </div> |
||
1496 | |||
1497 | <div class='form-group'> |
||
1498 | <label :for='$id3'>$label2</label> |
||
1499 | <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1500 | </div> |
||
1501 | |||
1502 | </div> |
||
1503 | "; |
||
1504 | |||
1505 | } |
||
1506 | |||
1507 | /** |
||
1508 | * Renders the items element template. |
||
1509 | */ |
||
1510 | public function render_items_template( $field ) { |
||
1511 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
1512 | echo " |
||
1513 | <div $restrict class='item_totals'> |
||
1514 | |||
1515 | <div v-if='$field.items_type == \"total\"' class='border'> |
||
1516 | |||
1517 | <div v-for='(item, index) in form_items'> |
||
1518 | <div class='row pl-2 pr-2 pt-2'> |
||
1519 | <div class='col-8'>{{item.title}}</div> |
||
1520 | <div class='col-4'>{{formatPrice(item.price)}}</div> |
||
1521 | </div> |
||
1522 | <small v-if='item.description' class='form-text text-muted pl-2 pr-2 m-0' v-html='item.description'></small> |
||
1523 | </div> |
||
1524 | |||
1525 | <div class='mt-4 border-top'> |
||
1526 | <div class='row p-2'> |
||
1527 | <div class='col-8'><strong class='mr-5'>Total</strong></div> |
||
1528 | <div class='col-4'><strong>{{totalPrice}}</strong></div> |
||
1529 | </div> |
||
1530 | </div> |
||
1531 | </div> |
||
1532 | |||
1533 | <div v-if='$field.items_type == \"checkbox\"'> |
||
1534 | |||
1535 | <div class='form-check' v-for='(item, index) in form_items'> |
||
1536 | <input class='form-check-input' type='checkbox' :id='$field.id + index'> |
||
1537 | <label class='form-check-label' :for='$field.id + index'>{{item.title}} <strong>{{formatPrice(item.price)}}</strong></label> |
||
1538 | <small v-if='item.description' class='form-text text-muted' v-html='item.description'></small> |
||
1539 | </div> |
||
1540 | |||
1541 | </div> |
||
1542 | |||
1543 | <div v-if='$field.items_type == \"radio\"'> |
||
1544 | |||
1545 | <div class='form-check' v-for='(item, index) in form_items'> |
||
1546 | <input class='form-check-input' type='radio' :name='$field.id' :id='$field.id + index'> |
||
1547 | <label class='form-check-label' :for='$field.id + index'>{{item.title}} <strong>{{formatPrice(item.price)}}</strong></label> |
||
1548 | <small v-if='item.description' class='form-text text-muted' v-html='item.description'></small> |
||
1549 | </div> |
||
1550 | |||
1551 | </div> |
||
1552 | |||
1553 | <div v-if='$field.items_type == \"select\"'> |
||
1554 | |||
1555 | <select class='form-control custom-select'> |
||
1556 | <option value='' disabled selected='selected'>" . __( 'Select an option', 'invoicing' ) ."</option> |
||
1557 | <option v-for='(item, index) in form_items' :value='index'>{{item.title}} {{formatPrice(item.price)}}</option> |
||
1558 | </select> |
||
1559 | </div> |
||
1560 | |||
1561 | <div v-if='$field.items_type == \"multi_select\"'> |
||
1562 | |||
1563 | <select class='form-control custom-select' multiple> |
||
1564 | <option v-for='(item, index) in form_items' :value='index'>{{item.title}} {{formatPrice(item.price)}}</option> |
||
1565 | </select> |
||
1566 | |||
1567 | </div> |
||
1568 | |||
1569 | <small v-if='$field.description' class='form-text text-muted' v-html='$field.description'></small> |
||
1570 | </div> |
||
1571 | "; |
||
1572 | } |
||
1573 | |||
1574 | /** |
||
1575 | * Renders the items element on the frontend. |
||
1576 | */ |
||
1577 | public function frontend_render_items_template( $field, $items ) { |
||
1713 | </div> |
||
1714 | <?php |
||
1715 | } |
||
1716 | |||
1717 | /** |
||
1718 | * Renders the items element template. |
||
1719 | */ |
||
1720 | public function edit_items_template( $field ) { |
||
1721 | $restrict = $this->get_restrict_markup( $field, 'items' ); |
||
1722 | $label = __( 'Let customers...', 'invoicing' ); |
||
1723 | $label2 = __( 'Available Items', 'invoicing' ); |
||
1724 | $label3 = esc_attr__( 'Add some help text for this element', 'invoicing' ); |
||
1725 | $id = $field . '.id + "_edit"'; |
||
1726 | $id2 = $field . '.id + "_edit2"'; |
||
1727 | $id3 = $field . '.id + "_edit3"'; |
||
1728 | $id4 = $field . '.id + "_edit4"'; |
||
1729 | echo "<div $restrict> |
||
1730 | |||
1731 | <label>$label2</label> |
||
1732 | |||
1733 | <draggable v-model='form_items' group='selectable_form_items'> |
||
1734 | <div class='wpinv-available-items-editor' v-for='(item, index) in form_items' :class='\"item_\" + item.id' :key='item.id'> |
||
1735 | |||
1736 | <div class='wpinv-available-items-editor-header' @click.prevent='togglePanel(item.id)'> |
||
1737 | <span class='label'>{{item.title}}</span> |
||
1738 | <span class='price'>({{formatPrice(item.price)}})</span> |
||
1739 | <span class='toggle-icon'> |
||
1740 | <span class='dashicons dashicons-arrow-down'></span> |
||
1741 | <span class='dashicons dashicons-arrow-up' style='display:none'></span> |
||
1742 | </span> |
||
1743 | </div> |
||
1744 | |||
1745 | <div class='wpinv-available-items-editor-body'> |
||
1746 | <div class='p-2'> |
||
1747 | |||
1748 | <div class='form-group'> |
||
1749 | <label :for='$id + item.id'>Item Name</label> |
||
1750 | <input :id='$id + item.id' v-model='item.title' class='form-control' /> |
||
1751 | </div> |
||
1752 | |||
1753 | <div class='form-group'> |
||
1754 | <label :for='$id + item.id + \"price\"'>Item Price</label> |
||
1755 | <input :id='$id + item.id + \"price\"' v-model='item.price' class='form-control' /> |
||
1756 | </div> |
||
1757 | |||
1758 | <div class='form-group'> |
||
1759 | <label :for='$id + item.id + \"description\"'>Item Description</label> |
||
1760 | <textarea :id='$id + item.id + \"description\"' v-model='item.description' class='form-control'></textarea> |
||
1761 | </div> |
||
1762 | |||
1763 | </div> |
||
1764 | </div> |
||
1765 | |||
1766 | </div> |
||
1767 | </draggable> |
||
1768 | |||
1769 | <small v-if='! form_items.length' class='form-text text-muted'> You have not set up any items. Please select an item below or create a new item.</small> |
||
1770 | |||
1771 | <div class='form-group mt-2'> |
||
1772 | |||
1773 | <select class='form-control custom-select' v-model='selected_item'> |
||
1774 | <option value=''>" . __( 'Add an item to the form', 'invoicing' ) ."</option> |
||
1775 | <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option> |
||
1776 | </select> |
||
1777 | |||
1778 | </div> |
||
1779 | |||
1780 | <div class='form-group'> |
||
1781 | <input type='button' value='Add item' class='button button-primary' @click.prevent='addSelectedItem' :disabled='selected_item == \"\"'> |
||
1782 | <small>Or <a href='' @click.prevent='addNewItem'>create a new item</a>.</small> |
||
1783 | </div> |
||
1784 | |||
1785 | <div class='form-group mt-5'> |
||
1786 | <label :for='$id2'>$label</label> |
||
1787 | |||
1788 | <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'> |
||
1789 | <option value='total'>" . __( 'Buy all items on the list', 'invoicing' ) ."</option> |
||
1790 | <option value='radio'>" . __( 'Select a single item from the list', 'invoicing' ) ."</option> |
||
1791 | <option value='checkbox'>" . __( 'Select one or more items on the list', 'invoicing' ) ."</option> |
||
1792 | <option value='select'>" . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option> |
||
1793 | <option value='multi_select'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option> |
||
1794 | </select> |
||
1795 | |||
1796 | </div> |
||
1797 | |||
1798 | <div class='form-group'> |
||
1799 | <label :for='$id3'>Help Text</label> |
||
1800 | <textarea placeholder='$label3' :id='$id3' v-model='$field.description' class='form-control' rows='3'></textarea> |
||
1801 | </div> |
||
1802 | |||
1803 | </div> |
||
1804 | "; |
||
1805 | |||
1806 | } |
||
1807 | |||
1808 | /** |
||
1809 | * Returns an array of all published items. |
||
1810 | */ |
||
1811 | public function get_published_items() { |
||
1812 | |||
1813 | $item_args = array( |
||
1814 | 'post_type' => 'wpi_item', |
||
1815 | 'orderby' => 'title', |
||
1816 | 'order' => 'ASC', |
||
1817 | 'posts_per_page' => -1, |
||
1818 | 'post_status' => array( 'publish' ), |
||
1819 | ); |
||
1820 | |||
1821 | $items = get_posts( apply_filters( 'wpinv_item_dropdown_query_args', $item_args ) ); |
||
1822 | |||
1823 | if ( empty( $items ) ) { |
||
1824 | return array(); |
||
1825 | } |
||
1826 | |||
1827 | $options = array(); |
||
1828 | foreach ( $items as $item ) { |
||
1829 | $title = esc_html( $item->post_title ); |
||
1830 | $title .= wpinv_get_item_suffix( $item->ID, false ); |
||
1831 | $id = absint( $item->ID ); |
||
1832 | $price = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) ); |
||
1833 | $recurring = (bool) get_post_meta( $id, '_wpinv_is_recurring', true ); |
||
1834 | $description = $item->post_excerpt; |
||
1835 | $options[] = compact( 'title', 'id', 'price', 'recurring', 'description' ); |
||
1836 | |||
1837 | } |
||
1838 | return $options; |
||
1839 | |||
1840 | } |
||
1841 | |||
1842 | /** |
||
1843 | * Returns an array of items for the currently being edited form. |
||
1844 | */ |
||
1845 | public function get_form_items( $id = false ) { |
||
1858 | |||
1859 | } |
||
1860 | |||
1861 | /** |
||
1862 | * Returns an array of elements for the currently being edited form. |
||
1863 | */ |
||
1864 | public function get_form_elements( $id = false ) { |
||
1865 | |||
1866 | if ( empty( $id ) ) { |
||
1867 | return wpinv_get_data( 'sample-payment-form' ); |
||
1868 | } |
||
1869 | |||
1877 | } |
||
1878 | |||
1879 | } |
||
1880 |