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