@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,87 +11,87 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Alert { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get($args = array()){ |
|
22 | - global $aui_bs5; |
|
23 | - $defaults = array( |
|
24 | - 'type' => 'info', |
|
25 | - 'class' => '', |
|
26 | - 'icon' => '', |
|
27 | - 'heading' => '', |
|
28 | - 'content' => '', |
|
29 | - 'footer' => '', |
|
30 | - 'dismissible'=> false, |
|
31 | - 'data' => '', |
|
32 | - ); |
|
33 | - |
|
34 | - /** |
|
35 | - * Parse incoming $args into an array and merge it with $defaults |
|
36 | - */ |
|
37 | - $args = wp_parse_args( $args, $defaults ); |
|
38 | - $output = ''; |
|
39 | - if ( ! empty( $args['content'] ) ) { |
|
40 | - $type = sanitize_html_class( $args['type'] ); |
|
41 | - if($type=='error'){$type='danger';} |
|
42 | - $icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : ''; |
|
43 | - |
|
44 | - // set default icon |
|
45 | - if(!$icon && $args['icon']!==false && $type){ |
|
46 | - if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} |
|
47 | - elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} |
|
48 | - elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} |
|
49 | - elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';} |
|
50 | - } |
|
51 | - |
|
52 | - $data = ''; |
|
53 | - $class = !empty($args['class']) ? esc_attr($args['class']) : ''; |
|
54 | - if($args['dismissible']){$class .= " alert-dismissible fade show";} |
|
55 | - |
|
56 | - // open |
|
57 | - $output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>'; |
|
58 | - |
|
59 | - // heading |
|
60 | - if ( ! empty( $args['heading'] ) ) { |
|
61 | - $output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>'; |
|
62 | - } |
|
63 | - |
|
64 | - // icon |
|
65 | - if ( ! empty( $icon) ) { |
|
66 | - $output .= $icon." "; |
|
67 | - } |
|
68 | - |
|
69 | - // content |
|
70 | - $output .= $args['content']; |
|
71 | - |
|
72 | - // dismissible |
|
73 | - if($args['dismissible']){ |
|
74 | - |
|
75 | - if ( $aui_bs5 ) { |
|
76 | - $output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'; |
|
77 | - }else{ |
|
78 | - $output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; |
|
79 | - $output .= '<span aria-hidden="true">×</span>'; |
|
80 | - $output .= '</button>'; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - // footer |
|
85 | - if ( ! empty( $args['footer'] ) ) { |
|
86 | - $output .= '<hr>'; |
|
87 | - $output .= '<p class="mb-0">' . $args['footer'] . '</p>'; |
|
88 | - } |
|
89 | - |
|
90 | - // close |
|
91 | - $output .= '</div>'; |
|
92 | - } |
|
93 | - |
|
94 | - return $output; |
|
95 | - } |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get($args = array()){ |
|
22 | + global $aui_bs5; |
|
23 | + $defaults = array( |
|
24 | + 'type' => 'info', |
|
25 | + 'class' => '', |
|
26 | + 'icon' => '', |
|
27 | + 'heading' => '', |
|
28 | + 'content' => '', |
|
29 | + 'footer' => '', |
|
30 | + 'dismissible'=> false, |
|
31 | + 'data' => '', |
|
32 | + ); |
|
33 | + |
|
34 | + /** |
|
35 | + * Parse incoming $args into an array and merge it with $defaults |
|
36 | + */ |
|
37 | + $args = wp_parse_args( $args, $defaults ); |
|
38 | + $output = ''; |
|
39 | + if ( ! empty( $args['content'] ) ) { |
|
40 | + $type = sanitize_html_class( $args['type'] ); |
|
41 | + if($type=='error'){$type='danger';} |
|
42 | + $icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : ''; |
|
43 | + |
|
44 | + // set default icon |
|
45 | + if(!$icon && $args['icon']!==false && $type){ |
|
46 | + if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} |
|
47 | + elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} |
|
48 | + elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} |
|
49 | + elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';} |
|
50 | + } |
|
51 | + |
|
52 | + $data = ''; |
|
53 | + $class = !empty($args['class']) ? esc_attr($args['class']) : ''; |
|
54 | + if($args['dismissible']){$class .= " alert-dismissible fade show";} |
|
55 | + |
|
56 | + // open |
|
57 | + $output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>'; |
|
58 | + |
|
59 | + // heading |
|
60 | + if ( ! empty( $args['heading'] ) ) { |
|
61 | + $output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>'; |
|
62 | + } |
|
63 | + |
|
64 | + // icon |
|
65 | + if ( ! empty( $icon) ) { |
|
66 | + $output .= $icon." "; |
|
67 | + } |
|
68 | + |
|
69 | + // content |
|
70 | + $output .= $args['content']; |
|
71 | + |
|
72 | + // dismissible |
|
73 | + if($args['dismissible']){ |
|
74 | + |
|
75 | + if ( $aui_bs5 ) { |
|
76 | + $output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'; |
|
77 | + }else{ |
|
78 | + $output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; |
|
79 | + $output .= '<span aria-hidden="true">×</span>'; |
|
80 | + $output .= '</button>'; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + // footer |
|
85 | + if ( ! empty( $args['footer'] ) ) { |
|
86 | + $output .= '<hr>'; |
|
87 | + $output .= '<p class="mb-0">' . $args['footer'] . '</p>'; |
|
88 | + } |
|
89 | + |
|
90 | + // close |
|
91 | + $output .= '</div>'; |
|
92 | + } |
|
93 | + |
|
94 | + return $output; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,112 +11,112 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Pagination { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function get( $args = array() ) { |
|
22 | - global $wp_query, $aui_bs5; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'class' => '', |
|
26 | - 'mid_size' => 2, |
|
27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | - 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | - 'before_paging' => '', |
|
31 | - 'after_paging' => '', |
|
32 | - 'type' => 'array', |
|
33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | - 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
35 | - 'rounded_style' => false, |
|
36 | - 'custom_next_text' => '', // Custom next page text |
|
37 | - 'custom_prev_text' => '', // Custom prev page text |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * Parse incoming $args into an array and merge it with $defaults |
|
42 | - */ |
|
43 | - $args = wp_parse_args( $args, $defaults ); |
|
44 | - |
|
45 | - $output = ''; |
|
46 | - |
|
47 | - // Don't print empty markup if there's only one page. |
|
48 | - if ( $args['total'] > 1 ) { |
|
49 | - // Set up paginated links. |
|
50 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
51 | - |
|
52 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
53 | - |
|
54 | - $custom_prev_link = ''; |
|
55 | - $custom_next_link = ''; |
|
56 | - |
|
57 | - // make the output bootstrap ready |
|
58 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
59 | - if ( ! empty( $links ) ) { |
|
60 | - foreach ( $links as $link ) { |
|
61 | - $_link = $link; |
|
62 | - |
|
63 | - if ( $aui_bs5 ) { |
|
64 | - $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
65 | - $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
66 | - $links_html .= "<li class='page-item mx-0'>"; |
|
67 | - $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
68 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
69 | - $links_html .= $link; |
|
70 | - $links_html .= "</li>"; |
|
71 | - } else { |
|
72 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
73 | - $links_html .= "<li class='page-item $active'>"; |
|
74 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
75 | - $links_html .= "</li>"; |
|
76 | - } |
|
77 | - |
|
78 | - if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
79 | - $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
80 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
81 | - |
|
82 | - if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
83 | - $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
84 | - } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
85 | - $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - $links_html .= "</ul>"; |
|
91 | - |
|
92 | - if ( $links ) { |
|
93 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
94 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
95 | - $output .= '</section>'; |
|
96 | - } |
|
97 | - |
|
98 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
99 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
100 | - } |
|
101 | - |
|
102 | - if ( $output ) { |
|
103 | - if ( $custom_next_link || $custom_prev_link ) { |
|
104 | - $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
105 | - $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
106 | - |
|
107 | - $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
108 | - } |
|
109 | - |
|
110 | - if ( ! empty( $args['before_paging'] ) ) { |
|
111 | - $output = $args['before_paging'] . $output; |
|
112 | - } |
|
113 | - |
|
114 | - if ( ! empty( $args['after_paging'] ) ) { |
|
115 | - $output = $output . $args['after_paging']; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return $output; |
|
120 | - } |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function get( $args = array() ) { |
|
22 | + global $wp_query, $aui_bs5; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'class' => '', |
|
26 | + 'mid_size' => 2, |
|
27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | + 'screen_reader_text' => __( 'Posts navigation','aui' ), |
|
30 | + 'before_paging' => '', |
|
31 | + 'after_paging' => '', |
|
32 | + 'type' => 'array', |
|
33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | + 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
35 | + 'rounded_style' => false, |
|
36 | + 'custom_next_text' => '', // Custom next page text |
|
37 | + 'custom_prev_text' => '', // Custom prev page text |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * Parse incoming $args into an array and merge it with $defaults |
|
42 | + */ |
|
43 | + $args = wp_parse_args( $args, $defaults ); |
|
44 | + |
|
45 | + $output = ''; |
|
46 | + |
|
47 | + // Don't print empty markup if there's only one page. |
|
48 | + if ( $args['total'] > 1 ) { |
|
49 | + // Set up paginated links. |
|
50 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
51 | + |
|
52 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
53 | + |
|
54 | + $custom_prev_link = ''; |
|
55 | + $custom_next_link = ''; |
|
56 | + |
|
57 | + // make the output bootstrap ready |
|
58 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
59 | + if ( ! empty( $links ) ) { |
|
60 | + foreach ( $links as $link ) { |
|
61 | + $_link = $link; |
|
62 | + |
|
63 | + if ( $aui_bs5 ) { |
|
64 | + $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
65 | + $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
66 | + $links_html .= "<li class='page-item mx-0'>"; |
|
67 | + $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
68 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
69 | + $links_html .= $link; |
|
70 | + $links_html .= "</li>"; |
|
71 | + } else { |
|
72 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
73 | + $links_html .= "<li class='page-item $active'>"; |
|
74 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
75 | + $links_html .= "</li>"; |
|
76 | + } |
|
77 | + |
|
78 | + if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
79 | + $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
80 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
81 | + |
|
82 | + if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
83 | + $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
84 | + } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
85 | + $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + $links_html .= "</ul>"; |
|
91 | + |
|
92 | + if ( $links ) { |
|
93 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
94 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
95 | + $output .= '</section>'; |
|
96 | + } |
|
97 | + |
|
98 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
99 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
100 | + } |
|
101 | + |
|
102 | + if ( $output ) { |
|
103 | + if ( $custom_next_link || $custom_prev_link ) { |
|
104 | + $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
105 | + $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
106 | + |
|
107 | + $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
108 | + } |
|
109 | + |
|
110 | + if ( ! empty( $args['before_paging'] ) ) { |
|
111 | + $output = $args['before_paging'] . $output; |
|
112 | + } |
|
113 | + |
|
114 | + if ( ! empty( $args['after_paging'] ) ) { |
|
115 | + $output = $output . $args['after_paging']; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return $output; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,470 +11,470 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Helper { |
13 | 13 | |
14 | - /** |
|
15 | - * A component helper for generating a input name. |
|
16 | - * |
|
17 | - * @param $text |
|
18 | - * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public static function name( $text, $multiple = false ) { |
|
23 | - $output = ''; |
|
24 | - |
|
25 | - if ( $text ) { |
|
26 | - $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | - $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | - } |
|
29 | - |
|
30 | - return $output; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * A component helper for generating a item id. |
|
35 | - * |
|
36 | - * @param $text string The text to be used as the value. |
|
37 | - * |
|
38 | - * @return string The sanitized item. |
|
39 | - */ |
|
40 | - public static function id( $text ) { |
|
41 | - $output = ''; |
|
42 | - |
|
43 | - if ( $text ) { |
|
44 | - $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | - } |
|
46 | - |
|
47 | - return $output; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * A component helper for generating a item title. |
|
52 | - * |
|
53 | - * @param $text string The text to be used as the value. |
|
54 | - * |
|
55 | - * @return string The sanitized item. |
|
56 | - */ |
|
57 | - public static function title( $text ) { |
|
58 | - $output = ''; |
|
59 | - |
|
60 | - if ( $text ) { |
|
61 | - $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | - } |
|
63 | - |
|
64 | - return $output; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * A component helper for generating a item value. |
|
69 | - * |
|
70 | - * @param $text string The text to be used as the value. |
|
71 | - * |
|
72 | - * @return string The sanitized item. |
|
73 | - */ |
|
74 | - public static function value( $text ) { |
|
75 | - $output = ''; |
|
76 | - |
|
77 | - if ( $text !== null && $text !== false ) { |
|
78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | - } |
|
80 | - |
|
81 | - return $output; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * A component helper for generating a item class attribute. |
|
86 | - * |
|
87 | - * @param $text string The text to be used as the value. |
|
88 | - * |
|
89 | - * @return string The sanitized item. |
|
90 | - */ |
|
91 | - public static function class_attr( $text ) { |
|
92 | - $output = ''; |
|
93 | - |
|
94 | - if ( $text ) { |
|
95 | - $classes = self::esc_classes( $text ); |
|
96 | - if ( ! empty( $classes ) ) { |
|
97 | - $output = ' class="' . $classes . '" '; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return $output; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Escape a string of classes. |
|
106 | - * |
|
107 | - * @param $text |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public static function esc_classes( $text ) { |
|
112 | - $output = ''; |
|
113 | - |
|
114 | - if ( $text ) { |
|
115 | - $classes = explode( " ", $text ); |
|
116 | - $classes = array_map( "trim", $classes ); |
|
117 | - $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | - if ( ! empty( $classes ) ) { |
|
119 | - $output = implode( " ", $classes ); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - return $output; |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $args |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function data_attributes( $args ) { |
|
133 | - $output = ''; |
|
134 | - |
|
135 | - if ( ! empty( $args ) ) { |
|
136 | - |
|
137 | - foreach ( $args as $key => $val ) { |
|
138 | - if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - return $output; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param $args |
|
149 | - * |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public static function aria_attributes( $args ) { |
|
153 | - $output = ''; |
|
154 | - |
|
155 | - if ( ! empty( $args ) ) { |
|
156 | - |
|
157 | - foreach ( $args as $key => $val ) { |
|
158 | - if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $output; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Build a font awesome icon from a class. |
|
169 | - * |
|
170 | - * @param $class |
|
171 | - * @param bool $space_after |
|
172 | - * @param array $extra_attributes An array of extra attributes. |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
177 | - $output = ''; |
|
178 | - |
|
179 | - if ( $class ) { |
|
180 | - $classes = self::esc_classes( $class ); |
|
181 | - if ( ! empty( $classes ) ) { |
|
182 | - $output = '<i class="' . $classes . '" '; |
|
183 | - // extra attributes |
|
184 | - if ( ! empty( $extra_attributes ) ) { |
|
185 | - $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
186 | - } |
|
187 | - $output .= '></i>'; |
|
188 | - if ( $space_after ) { |
|
189 | - $output .= " "; |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return $output; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $args |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function extra_attributes( $args ) { |
|
203 | - $output = ''; |
|
204 | - |
|
205 | - if ( ! empty( $args ) ) { |
|
206 | - |
|
207 | - if ( is_array( $args ) ) { |
|
208 | - foreach ( $args as $key => $val ) { |
|
209 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
210 | - } |
|
211 | - } else { |
|
212 | - $output .= ' ' . $args . ' '; |
|
213 | - } |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - return $output; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param $args |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function help_text( $text ) { |
|
226 | - $output = ''; |
|
227 | - |
|
228 | - if ( $text ) { |
|
229 | - $output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>'; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - return $output; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Replace element require context with JS. |
|
238 | - * |
|
239 | - * @param $input |
|
240 | - * |
|
241 | - * @return string|void |
|
242 | - */ |
|
243 | - public static function element_require( $input ) { |
|
244 | - |
|
245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | - |
|
247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | - "jQuery(form).find('[data-argument=\"", |
|
249 | - "\"]').find('input,select,textarea').val()", |
|
250 | - "\"]').find('input:checked').val()", |
|
251 | - ), $input ) ); |
|
252 | - |
|
253 | - if ( $output ) { |
|
254 | - $output = ' data-element-require="' . $output . '" '; |
|
255 | - } |
|
256 | - |
|
257 | - return $output; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
262 | - * |
|
263 | - * @since 0.1.41 |
|
264 | - * |
|
265 | - * @param mixed $value The value to be stripped. |
|
266 | - * @param array $input Input Field. |
|
267 | - * |
|
268 | - * @return mixed Stripped value. |
|
269 | - */ |
|
270 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
271 | - $original = $value; |
|
272 | - |
|
273 | - if ( is_array( $value ) ) { |
|
274 | - foreach ( $value as $index => $item ) { |
|
275 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
276 | - } |
|
277 | - } elseif ( is_object( $value ) ) { |
|
278 | - $object_vars = get_object_vars( $value ); |
|
279 | - |
|
280 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
282 | - } |
|
283 | - } else { |
|
284 | - $value = self::_sanitize_html_field( $value, $input ); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Filters content and keeps only allowable HTML elements. |
|
289 | - * |
|
290 | - * @since 0.1.41 |
|
291 | - * |
|
292 | - * @param string|array $value Content to filter through kses. |
|
293 | - * @param string|array $value Original content without filter. |
|
294 | - * @param array $input Input Field. |
|
295 | - */ |
|
296 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Filters content and keeps only allowable HTML elements. |
|
301 | - * |
|
302 | - * This function makes sure that only the allowed HTML element names, attribute |
|
303 | - * names and attribute values plus only sane HTML entities will occur in |
|
304 | - * $string. You have to remove any slashes from PHP's magic quotes before you |
|
305 | - * call this function. |
|
306 | - * |
|
307 | - * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
308 | - * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
309 | - * covers all common link protocols, except for 'javascript' which should not |
|
310 | - * be allowed for untrusted users. |
|
311 | - * |
|
312 | - * @since 0.1.41 |
|
313 | - * |
|
314 | - * @param string|array $value Content to filter through kses. |
|
315 | - * @param array $input Input Field. |
|
316 | - * |
|
317 | - * @return string Filtered content with only allowed HTML elements. |
|
318 | - */ |
|
319 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | - if ( $value === '' ) { |
|
321 | - return $value; |
|
322 | - } |
|
323 | - |
|
324 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
325 | - |
|
326 | - if ( ! is_array( $allowed_html ) ) { |
|
327 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
328 | - } |
|
329 | - |
|
330 | - $filtered = trim( wp_unslash( $value ) ); |
|
331 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
333 | - |
|
334 | - return $filtered; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Returns an array of allowed HTML tags and attributes for a given context. |
|
339 | - * |
|
340 | - * @since 0.1.41 |
|
341 | - * |
|
342 | - * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
343 | - * 'strip', 'data', 'entities', or the name of a field filter such as |
|
344 | - * 'pre_user_description'. |
|
345 | - * @param array $input Input. |
|
346 | - * |
|
347 | - * @return array Array of allowed HTML tags and their allowed attributes. |
|
348 | - */ |
|
349 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
351 | - |
|
352 | - if ( is_array( $allowed_html ) ) { |
|
353 | - // <iframe> |
|
354 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
355 | - $allowed_html['iframe'] = array( |
|
356 | - 'class' => true, |
|
357 | - 'id' => true, |
|
358 | - 'src' => true, |
|
359 | - 'width' => true, |
|
360 | - 'height' => true, |
|
361 | - 'frameborder' => true, |
|
362 | - 'marginwidth' => true, |
|
363 | - 'marginheight' => true, |
|
364 | - 'scrolling' => true, |
|
365 | - 'style' => true, |
|
366 | - 'title' => true, |
|
367 | - 'allow' => true, |
|
368 | - 'allowfullscreen' => true, |
|
369 | - 'data-*' => true, |
|
370 | - ); |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Filters the allowed html tags. |
|
376 | - * |
|
377 | - * @since 0.1.41 |
|
378 | - * |
|
379 | - * @param array[]|string $allowed_html Allowed html tags. |
|
380 | - * @param @param string|array $context The context for which to retrieve tags. |
|
381 | - * @param array $input Input field. |
|
382 | - */ |
|
383 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
384 | - } |
|
385 | - |
|
386 | - public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
387 | - |
|
388 | - $class = ''; |
|
389 | - |
|
390 | - // set default if empty |
|
391 | - if( $label_number === '' ){ |
|
392 | - $label_number = 2; |
|
393 | - } |
|
394 | - |
|
395 | - if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | - if ( $type == 'label' ) { |
|
397 | - $class = 'col-sm-' . absint( $label_number ); |
|
398 | - } elseif ( $type == 'input' ) { |
|
399 | - $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - return $class; |
|
404 | - } |
|
405 | - |
|
406 | - /** |
|
407 | - * Sanitizes a multiline string from user input or from the database. |
|
408 | - * |
|
409 | - * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way. |
|
410 | - * |
|
411 | - * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original |
|
412 | - * |
|
413 | - * @since 0.1.66 |
|
414 | - * |
|
415 | - * @param string $str String to sanitize. |
|
416 | - * @return string Sanitized string. |
|
417 | - */ |
|
418 | - public static function sanitize_textarea_field( $str ) { |
|
419 | - $filtered = self::_sanitize_text_fields( $str, true ); |
|
420 | - |
|
421 | - /** |
|
422 | - * Filters a sanitized textarea field string. |
|
423 | - * |
|
424 | - * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php |
|
425 | - * |
|
426 | - * @param string $filtered The sanitized string. |
|
427 | - * @param string $str The string prior to being sanitized. |
|
428 | - */ |
|
429 | - return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Internal helper function to sanitize a string from user input or from the db. |
|
434 | - * |
|
435 | - * @since 0.1.66 |
|
436 | - * @access private |
|
437 | - * |
|
438 | - * @param string $str String to sanitize. |
|
439 | - * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
|
440 | - * @return string Sanitized string. |
|
441 | - */ |
|
442 | - public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
443 | - if ( is_object( $str ) || is_array( $str ) ) { |
|
444 | - return ''; |
|
445 | - } |
|
446 | - |
|
447 | - $str = (string) $str; |
|
448 | - |
|
449 | - $filtered = wp_check_invalid_utf8( $str ); |
|
450 | - |
|
451 | - if ( strpos( $filtered, '<' ) !== false ) { |
|
452 | - $filtered = wp_pre_kses_less_than( $filtered ); |
|
453 | - // This will strip extra whitespace for us. |
|
454 | - $filtered = wp_strip_all_tags( $filtered, false ); |
|
455 | - |
|
456 | - // Use HTML entities in a special case to make sure no later |
|
457 | - // newline stripping stage could lead to a functional tag. |
|
458 | - $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
459 | - } |
|
460 | - |
|
461 | - if ( ! $keep_newlines ) { |
|
462 | - $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
463 | - } |
|
464 | - $filtered = trim( $filtered ); |
|
465 | - |
|
466 | - $found = false; |
|
467 | - while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
468 | - $filtered = str_replace( $match[1], '', $filtered ); |
|
469 | - $found = true; |
|
470 | - } |
|
471 | - unset( $match ); |
|
472 | - |
|
473 | - if ( $found ) { |
|
474 | - // Strip out the whitespace that may now exist after removing the octets. |
|
475 | - $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
476 | - } |
|
477 | - |
|
478 | - return $filtered; |
|
479 | - } |
|
14 | + /** |
|
15 | + * A component helper for generating a input name. |
|
16 | + * |
|
17 | + * @param $text |
|
18 | + * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public static function name( $text, $multiple = false ) { |
|
23 | + $output = ''; |
|
24 | + |
|
25 | + if ( $text ) { |
|
26 | + $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | + $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | + } |
|
29 | + |
|
30 | + return $output; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * A component helper for generating a item id. |
|
35 | + * |
|
36 | + * @param $text string The text to be used as the value. |
|
37 | + * |
|
38 | + * @return string The sanitized item. |
|
39 | + */ |
|
40 | + public static function id( $text ) { |
|
41 | + $output = ''; |
|
42 | + |
|
43 | + if ( $text ) { |
|
44 | + $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | + } |
|
46 | + |
|
47 | + return $output; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * A component helper for generating a item title. |
|
52 | + * |
|
53 | + * @param $text string The text to be used as the value. |
|
54 | + * |
|
55 | + * @return string The sanitized item. |
|
56 | + */ |
|
57 | + public static function title( $text ) { |
|
58 | + $output = ''; |
|
59 | + |
|
60 | + if ( $text ) { |
|
61 | + $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | + } |
|
63 | + |
|
64 | + return $output; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * A component helper for generating a item value. |
|
69 | + * |
|
70 | + * @param $text string The text to be used as the value. |
|
71 | + * |
|
72 | + * @return string The sanitized item. |
|
73 | + */ |
|
74 | + public static function value( $text ) { |
|
75 | + $output = ''; |
|
76 | + |
|
77 | + if ( $text !== null && $text !== false ) { |
|
78 | + $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | + } |
|
80 | + |
|
81 | + return $output; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * A component helper for generating a item class attribute. |
|
86 | + * |
|
87 | + * @param $text string The text to be used as the value. |
|
88 | + * |
|
89 | + * @return string The sanitized item. |
|
90 | + */ |
|
91 | + public static function class_attr( $text ) { |
|
92 | + $output = ''; |
|
93 | + |
|
94 | + if ( $text ) { |
|
95 | + $classes = self::esc_classes( $text ); |
|
96 | + if ( ! empty( $classes ) ) { |
|
97 | + $output = ' class="' . $classes . '" '; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return $output; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Escape a string of classes. |
|
106 | + * |
|
107 | + * @param $text |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public static function esc_classes( $text ) { |
|
112 | + $output = ''; |
|
113 | + |
|
114 | + if ( $text ) { |
|
115 | + $classes = explode( " ", $text ); |
|
116 | + $classes = array_map( "trim", $classes ); |
|
117 | + $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | + if ( ! empty( $classes ) ) { |
|
119 | + $output = implode( " ", $classes ); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + return $output; |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $args |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function data_attributes( $args ) { |
|
133 | + $output = ''; |
|
134 | + |
|
135 | + if ( ! empty( $args ) ) { |
|
136 | + |
|
137 | + foreach ( $args as $key => $val ) { |
|
138 | + if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + return $output; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param $args |
|
149 | + * |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public static function aria_attributes( $args ) { |
|
153 | + $output = ''; |
|
154 | + |
|
155 | + if ( ! empty( $args ) ) { |
|
156 | + |
|
157 | + foreach ( $args as $key => $val ) { |
|
158 | + if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $output; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Build a font awesome icon from a class. |
|
169 | + * |
|
170 | + * @param $class |
|
171 | + * @param bool $space_after |
|
172 | + * @param array $extra_attributes An array of extra attributes. |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
177 | + $output = ''; |
|
178 | + |
|
179 | + if ( $class ) { |
|
180 | + $classes = self::esc_classes( $class ); |
|
181 | + if ( ! empty( $classes ) ) { |
|
182 | + $output = '<i class="' . $classes . '" '; |
|
183 | + // extra attributes |
|
184 | + if ( ! empty( $extra_attributes ) ) { |
|
185 | + $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
186 | + } |
|
187 | + $output .= '></i>'; |
|
188 | + if ( $space_after ) { |
|
189 | + $output .= " "; |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return $output; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $args |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function extra_attributes( $args ) { |
|
203 | + $output = ''; |
|
204 | + |
|
205 | + if ( ! empty( $args ) ) { |
|
206 | + |
|
207 | + if ( is_array( $args ) ) { |
|
208 | + foreach ( $args as $key => $val ) { |
|
209 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
210 | + } |
|
211 | + } else { |
|
212 | + $output .= ' ' . $args . ' '; |
|
213 | + } |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + return $output; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param $args |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function help_text( $text ) { |
|
226 | + $output = ''; |
|
227 | + |
|
228 | + if ( $text ) { |
|
229 | + $output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>'; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + return $output; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Replace element require context with JS. |
|
238 | + * |
|
239 | + * @param $input |
|
240 | + * |
|
241 | + * @return string|void |
|
242 | + */ |
|
243 | + public static function element_require( $input ) { |
|
244 | + |
|
245 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | + |
|
247 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | + "jQuery(form).find('[data-argument=\"", |
|
249 | + "\"]').find('input,select,textarea').val()", |
|
250 | + "\"]').find('input:checked').val()", |
|
251 | + ), $input ) ); |
|
252 | + |
|
253 | + if ( $output ) { |
|
254 | + $output = ' data-element-require="' . $output . '" '; |
|
255 | + } |
|
256 | + |
|
257 | + return $output; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
262 | + * |
|
263 | + * @since 0.1.41 |
|
264 | + * |
|
265 | + * @param mixed $value The value to be stripped. |
|
266 | + * @param array $input Input Field. |
|
267 | + * |
|
268 | + * @return mixed Stripped value. |
|
269 | + */ |
|
270 | + public static function sanitize_html_field( $value, $input = array() ) { |
|
271 | + $original = $value; |
|
272 | + |
|
273 | + if ( is_array( $value ) ) { |
|
274 | + foreach ( $value as $index => $item ) { |
|
275 | + $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
276 | + } |
|
277 | + } elseif ( is_object( $value ) ) { |
|
278 | + $object_vars = get_object_vars( $value ); |
|
279 | + |
|
280 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | + $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
282 | + } |
|
283 | + } else { |
|
284 | + $value = self::_sanitize_html_field( $value, $input ); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Filters content and keeps only allowable HTML elements. |
|
289 | + * |
|
290 | + * @since 0.1.41 |
|
291 | + * |
|
292 | + * @param string|array $value Content to filter through kses. |
|
293 | + * @param string|array $value Original content without filter. |
|
294 | + * @param array $input Input Field. |
|
295 | + */ |
|
296 | + return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Filters content and keeps only allowable HTML elements. |
|
301 | + * |
|
302 | + * This function makes sure that only the allowed HTML element names, attribute |
|
303 | + * names and attribute values plus only sane HTML entities will occur in |
|
304 | + * $string. You have to remove any slashes from PHP's magic quotes before you |
|
305 | + * call this function. |
|
306 | + * |
|
307 | + * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
308 | + * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
309 | + * covers all common link protocols, except for 'javascript' which should not |
|
310 | + * be allowed for untrusted users. |
|
311 | + * |
|
312 | + * @since 0.1.41 |
|
313 | + * |
|
314 | + * @param string|array $value Content to filter through kses. |
|
315 | + * @param array $input Input Field. |
|
316 | + * |
|
317 | + * @return string Filtered content with only allowed HTML elements. |
|
318 | + */ |
|
319 | + public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | + if ( $value === '' ) { |
|
321 | + return $value; |
|
322 | + } |
|
323 | + |
|
324 | + $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
325 | + |
|
326 | + if ( ! is_array( $allowed_html ) ) { |
|
327 | + $allowed_html = wp_kses_allowed_html( 'post' ); |
|
328 | + } |
|
329 | + |
|
330 | + $filtered = trim( wp_unslash( $value ) ); |
|
331 | + $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | + $filtered = balanceTags( $filtered ); // Balances tags |
|
333 | + |
|
334 | + return $filtered; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Returns an array of allowed HTML tags and attributes for a given context. |
|
339 | + * |
|
340 | + * @since 0.1.41 |
|
341 | + * |
|
342 | + * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
343 | + * 'strip', 'data', 'entities', or the name of a field filter such as |
|
344 | + * 'pre_user_description'. |
|
345 | + * @param array $input Input. |
|
346 | + * |
|
347 | + * @return array Array of allowed HTML tags and their allowed attributes. |
|
348 | + */ |
|
349 | + public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | + $allowed_html = wp_kses_allowed_html( $context ); |
|
351 | + |
|
352 | + if ( is_array( $allowed_html ) ) { |
|
353 | + // <iframe> |
|
354 | + if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
355 | + $allowed_html['iframe'] = array( |
|
356 | + 'class' => true, |
|
357 | + 'id' => true, |
|
358 | + 'src' => true, |
|
359 | + 'width' => true, |
|
360 | + 'height' => true, |
|
361 | + 'frameborder' => true, |
|
362 | + 'marginwidth' => true, |
|
363 | + 'marginheight' => true, |
|
364 | + 'scrolling' => true, |
|
365 | + 'style' => true, |
|
366 | + 'title' => true, |
|
367 | + 'allow' => true, |
|
368 | + 'allowfullscreen' => true, |
|
369 | + 'data-*' => true, |
|
370 | + ); |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Filters the allowed html tags. |
|
376 | + * |
|
377 | + * @since 0.1.41 |
|
378 | + * |
|
379 | + * @param array[]|string $allowed_html Allowed html tags. |
|
380 | + * @param @param string|array $context The context for which to retrieve tags. |
|
381 | + * @param array $input Input field. |
|
382 | + */ |
|
383 | + return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
384 | + } |
|
385 | + |
|
386 | + public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
387 | + |
|
388 | + $class = ''; |
|
389 | + |
|
390 | + // set default if empty |
|
391 | + if( $label_number === '' ){ |
|
392 | + $label_number = 2; |
|
393 | + } |
|
394 | + |
|
395 | + if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | + if ( $type == 'label' ) { |
|
397 | + $class = 'col-sm-' . absint( $label_number ); |
|
398 | + } elseif ( $type == 'input' ) { |
|
399 | + $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + return $class; |
|
404 | + } |
|
405 | + |
|
406 | + /** |
|
407 | + * Sanitizes a multiline string from user input or from the database. |
|
408 | + * |
|
409 | + * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way. |
|
410 | + * |
|
411 | + * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php for the original |
|
412 | + * |
|
413 | + * @since 0.1.66 |
|
414 | + * |
|
415 | + * @param string $str String to sanitize. |
|
416 | + * @return string Sanitized string. |
|
417 | + */ |
|
418 | + public static function sanitize_textarea_field( $str ) { |
|
419 | + $filtered = self::_sanitize_text_fields( $str, true ); |
|
420 | + |
|
421 | + /** |
|
422 | + * Filters a sanitized textarea field string. |
|
423 | + * |
|
424 | + * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php |
|
425 | + * |
|
426 | + * @param string $filtered The sanitized string. |
|
427 | + * @param string $str The string prior to being sanitized. |
|
428 | + */ |
|
429 | + return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Internal helper function to sanitize a string from user input or from the db. |
|
434 | + * |
|
435 | + * @since 0.1.66 |
|
436 | + * @access private |
|
437 | + * |
|
438 | + * @param string $str String to sanitize. |
|
439 | + * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
|
440 | + * @return string Sanitized string. |
|
441 | + */ |
|
442 | + public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
443 | + if ( is_object( $str ) || is_array( $str ) ) { |
|
444 | + return ''; |
|
445 | + } |
|
446 | + |
|
447 | + $str = (string) $str; |
|
448 | + |
|
449 | + $filtered = wp_check_invalid_utf8( $str ); |
|
450 | + |
|
451 | + if ( strpos( $filtered, '<' ) !== false ) { |
|
452 | + $filtered = wp_pre_kses_less_than( $filtered ); |
|
453 | + // This will strip extra whitespace for us. |
|
454 | + $filtered = wp_strip_all_tags( $filtered, false ); |
|
455 | + |
|
456 | + // Use HTML entities in a special case to make sure no later |
|
457 | + // newline stripping stage could lead to a functional tag. |
|
458 | + $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
459 | + } |
|
460 | + |
|
461 | + if ( ! $keep_newlines ) { |
|
462 | + $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
463 | + } |
|
464 | + $filtered = trim( $filtered ); |
|
465 | + |
|
466 | + $found = false; |
|
467 | + while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
468 | + $filtered = str_replace( $match[1], '', $filtered ); |
|
469 | + $found = true; |
|
470 | + } |
|
471 | + unset( $match ); |
|
472 | + |
|
473 | + if ( $found ) { |
|
474 | + // Strip out the whitespace that may now exist after removing the octets. |
|
475 | + $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
476 | + } |
|
477 | + |
|
478 | + return $filtered; |
|
479 | + } |
|
480 | 480 | } |
481 | 481 | \ No newline at end of file |
@@ -16,222 +16,222 @@ |
||
16 | 16 | |
17 | 17 | // If this file is called directly, abort. |
18 | 18 | if ( ! defined( 'WPINC' ) ) { |
19 | - die; |
|
19 | + die; |
|
20 | 20 | } |
21 | 21 | |
22 | 22 | class AyeCode_UI_Plugin { |
23 | 23 | |
24 | - /** |
|
25 | - * AUI Plugin constructor. |
|
26 | - * |
|
27 | - * @since 1.0.0 |
|
28 | - */ |
|
29 | - public function __construct() { |
|
30 | - |
|
31 | - // load AUI |
|
32 | - require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | - |
|
34 | - // Maybe show example page |
|
35 | - add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | - } |
|
37 | - |
|
38 | - public function maybe_show_examples(){ |
|
39 | - if ( current_user_can( 'manage_options' ) && isset( $_REQUEST['preview-aui'] ) ) { |
|
40 | - echo "<head>"; |
|
41 | - wp_head(); |
|
42 | - echo "</head>"; |
|
43 | - echo "<body class='bsui'>"; |
|
44 | - echo $this->get_examples(); |
|
45 | - wp_footer(); |
|
46 | - echo "</body>"; |
|
47 | - exit; |
|
48 | - } |
|
49 | - } |
|
50 | - |
|
51 | - public function get_examples(){ |
|
52 | - $output = ''; |
|
53 | - |
|
54 | - // open form |
|
55 | - $output .= "<form class='p-5 m-5 border rounded bg-white'>"; |
|
56 | - |
|
57 | - $output .= aui()->input( |
|
58 | - array( |
|
59 | - 'type' => 'datepicker', |
|
60 | - 'id' => 'date_example_sm', |
|
61 | - 'size' => 'sm', |
|
62 | - 'name' => 'date_example_sm', |
|
63 | - 'label' => 'Date Input Label (small)', |
|
64 | - 'help_text' => 'help text', |
|
65 | - 'label_type' => 'top', |
|
66 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
67 | - 'value' => '', |
|
68 | - 'extra_attributes' => array( |
|
69 | - 'data-enable-time' => 'true', |
|
70 | - 'data-time_24hr' => 'true', |
|
71 | - 'data-allow-input' => 'true', |
|
72 | - ), |
|
73 | - ) |
|
74 | - ); |
|
75 | - |
|
76 | - $output .= aui()->input( |
|
77 | - array( |
|
78 | - 'type' => 'datepicker', |
|
79 | - 'id' => 'date_example', |
|
80 | - //'size' => 'smx', |
|
81 | - 'name' => 'date_example', |
|
82 | - 'label' => 'Date Input Label', |
|
83 | - 'help_text' => 'help text', |
|
84 | - 'label_type' => 'top', |
|
85 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
86 | - 'value' => '', |
|
87 | - 'extra_attributes' => array( |
|
88 | - 'data-enable-time' => 'true', |
|
89 | - 'data-time_24hr' => 'true', |
|
90 | - 'data-allow-input' => 'true', |
|
91 | - ), |
|
92 | - ) |
|
93 | - ); |
|
94 | - |
|
95 | - $output .= aui()->input( |
|
96 | - array( |
|
97 | - 'type' => 'datepicker', |
|
98 | - 'id' => 'date_example_lg', |
|
99 | - 'size' => 'lg', |
|
100 | - 'name' => 'date_example_lg', |
|
101 | - 'label' => 'Date Input Label (large)', |
|
102 | - 'help_text' => 'help text', |
|
103 | - 'label_type' => 'top', |
|
104 | - 'placeholder' => 'YYYY-MM-DD 00:00', |
|
105 | - 'value' => '', |
|
106 | - 'extra_attributes' => array( |
|
107 | - 'data-enable-time' => 'true', |
|
108 | - 'data-time_24hr' => 'true', |
|
109 | - //'data-allow-input' => 'true', |
|
110 | - ), |
|
111 | - ) |
|
112 | - ); |
|
113 | - |
|
114 | - // input example |
|
115 | - $output .= aui()->input( |
|
116 | - array( |
|
117 | - 'type' => 'text', |
|
118 | - 'id' => 'text-example', |
|
119 | - 'size' => 'sm', |
|
120 | - //'clear_icon' => true, |
|
121 | - 'name' => 'text-example', |
|
122 | - 'placeholder' => 'text placeholder', |
|
123 | - 'title' => 'Text input example', |
|
124 | - 'value' => '', |
|
125 | - 'required' => false, |
|
126 | - 'help_text' => 'help text', |
|
127 | - 'label' => 'Text input example label', |
|
128 | - 'label_type' => 'top' |
|
129 | - ) |
|
130 | - ); |
|
131 | - |
|
132 | - $output .= aui()->input( |
|
133 | - array( |
|
134 | - 'type' => 'search', |
|
135 | - 'id' => 'text-example', |
|
136 | - 'size' => 'sm', |
|
137 | - //'clear_icon' => true, |
|
138 | - 'name' => 'text-example', |
|
139 | - 'placeholder' => 'text placeholder', |
|
140 | - 'title' => 'Text input example', |
|
141 | - 'value' => '', |
|
142 | - 'required' => false, |
|
143 | - 'help_text' => 'help text', |
|
144 | - 'label' => 'Text input example label', |
|
145 | - 'label_type' => 'top' |
|
146 | - ) |
|
147 | - ); |
|
148 | - |
|
149 | - // input example |
|
150 | - $output .= aui()->input( |
|
151 | - array( |
|
152 | - 'type' => 'url', |
|
153 | - 'id' => 'text-example2', |
|
154 | - 'name' => 'text-example', |
|
155 | - 'placeholder' => 'url placeholder', |
|
156 | - 'title' => 'Text input example', |
|
157 | - 'value' => '', |
|
158 | - 'required' => false, |
|
159 | - 'help_text' => 'help text', |
|
160 | - 'label' => 'Text input example label' |
|
161 | - ) |
|
162 | - ); |
|
163 | - |
|
164 | - // checkbox example |
|
165 | - $output .= aui()->input( |
|
166 | - array( |
|
167 | - 'type' => 'checkbox', |
|
168 | - 'id' => 'checkbox-example', |
|
169 | - 'name' => 'checkbox-example', |
|
170 | - 'placeholder' => 'checkbox-example', |
|
171 | - 'title' => 'Checkbox example', |
|
172 | - 'value' => '1', |
|
173 | - 'checked' => true, |
|
174 | - 'required' => false, |
|
175 | - 'help_text' => 'help text', |
|
176 | - 'label' => 'Checkbox checked' |
|
177 | - ) |
|
178 | - ); |
|
179 | - |
|
180 | - // checkbox example |
|
181 | - $output .= aui()->input( |
|
182 | - array( |
|
183 | - 'type' => 'checkbox', |
|
184 | - 'id' => 'checkbox-example2', |
|
185 | - 'name' => 'checkbox-example2', |
|
186 | - 'placeholder' => 'checkbox-example', |
|
187 | - 'title' => 'Checkbox example', |
|
188 | - 'value' => '1', |
|
189 | - 'checked' => false, |
|
190 | - 'required' => false, |
|
191 | - 'help_text' => 'help text', |
|
192 | - 'label' => 'Checkbox un-checked' |
|
193 | - ) |
|
194 | - ); |
|
195 | - |
|
196 | - // switch example |
|
197 | - $output .= aui()->input( |
|
198 | - array( |
|
199 | - 'type' => 'checkbox', |
|
200 | - 'id' => 'switch-example', |
|
201 | - 'name' => 'switch-example', |
|
202 | - 'placeholder' => 'checkbox-example', |
|
203 | - 'title' => 'Switch example', |
|
204 | - 'value' => '1', |
|
205 | - 'checked' => true, |
|
206 | - 'switch' => true, |
|
207 | - 'required' => false, |
|
208 | - 'help_text' => 'help text', |
|
209 | - 'label' => 'Switch on' |
|
210 | - ) |
|
211 | - ); |
|
212 | - |
|
213 | - // switch example |
|
214 | - $output .= aui()->input( |
|
215 | - array( |
|
216 | - 'type' => 'checkbox', |
|
217 | - 'id' => 'switch-example2', |
|
218 | - 'name' => 'switch-example2', |
|
219 | - 'placeholder' => 'checkbox-example', |
|
220 | - 'title' => 'Switch example', |
|
221 | - 'value' => '1', |
|
222 | - 'checked' => false, |
|
223 | - 'switch' => true, |
|
224 | - 'required' => false, |
|
225 | - 'help_text' => 'help text', |
|
226 | - 'label' => 'Switch off' |
|
227 | - ) |
|
228 | - ); |
|
229 | - |
|
230 | - // close form |
|
231 | - $output .= "</form>"; |
|
232 | - |
|
233 | - return $output; |
|
234 | - } |
|
24 | + /** |
|
25 | + * AUI Plugin constructor. |
|
26 | + * |
|
27 | + * @since 1.0.0 |
|
28 | + */ |
|
29 | + public function __construct() { |
|
30 | + |
|
31 | + // load AUI |
|
32 | + require_once( dirname( __FILE__ ) . '/ayecode-ui-loader.php' ); |
|
33 | + |
|
34 | + // Maybe show example page |
|
35 | + add_action( 'template_redirect', array( $this,'maybe_show_examples' ) ); |
|
36 | + } |
|
37 | + |
|
38 | + public function maybe_show_examples(){ |
|
39 | + if ( current_user_can( 'manage_options' ) && isset( $_REQUEST['preview-aui'] ) ) { |
|
40 | + echo "<head>"; |
|
41 | + wp_head(); |
|
42 | + echo "</head>"; |
|
43 | + echo "<body class='bsui'>"; |
|
44 | + echo $this->get_examples(); |
|
45 | + wp_footer(); |
|
46 | + echo "</body>"; |
|
47 | + exit; |
|
48 | + } |
|
49 | + } |
|
50 | + |
|
51 | + public function get_examples(){ |
|
52 | + $output = ''; |
|
53 | + |
|
54 | + // open form |
|
55 | + $output .= "<form class='p-5 m-5 border rounded bg-white'>"; |
|
56 | + |
|
57 | + $output .= aui()->input( |
|
58 | + array( |
|
59 | + 'type' => 'datepicker', |
|
60 | + 'id' => 'date_example_sm', |
|
61 | + 'size' => 'sm', |
|
62 | + 'name' => 'date_example_sm', |
|
63 | + 'label' => 'Date Input Label (small)', |
|
64 | + 'help_text' => 'help text', |
|
65 | + 'label_type' => 'top', |
|
66 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
67 | + 'value' => '', |
|
68 | + 'extra_attributes' => array( |
|
69 | + 'data-enable-time' => 'true', |
|
70 | + 'data-time_24hr' => 'true', |
|
71 | + 'data-allow-input' => 'true', |
|
72 | + ), |
|
73 | + ) |
|
74 | + ); |
|
75 | + |
|
76 | + $output .= aui()->input( |
|
77 | + array( |
|
78 | + 'type' => 'datepicker', |
|
79 | + 'id' => 'date_example', |
|
80 | + //'size' => 'smx', |
|
81 | + 'name' => 'date_example', |
|
82 | + 'label' => 'Date Input Label', |
|
83 | + 'help_text' => 'help text', |
|
84 | + 'label_type' => 'top', |
|
85 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
86 | + 'value' => '', |
|
87 | + 'extra_attributes' => array( |
|
88 | + 'data-enable-time' => 'true', |
|
89 | + 'data-time_24hr' => 'true', |
|
90 | + 'data-allow-input' => 'true', |
|
91 | + ), |
|
92 | + ) |
|
93 | + ); |
|
94 | + |
|
95 | + $output .= aui()->input( |
|
96 | + array( |
|
97 | + 'type' => 'datepicker', |
|
98 | + 'id' => 'date_example_lg', |
|
99 | + 'size' => 'lg', |
|
100 | + 'name' => 'date_example_lg', |
|
101 | + 'label' => 'Date Input Label (large)', |
|
102 | + 'help_text' => 'help text', |
|
103 | + 'label_type' => 'top', |
|
104 | + 'placeholder' => 'YYYY-MM-DD 00:00', |
|
105 | + 'value' => '', |
|
106 | + 'extra_attributes' => array( |
|
107 | + 'data-enable-time' => 'true', |
|
108 | + 'data-time_24hr' => 'true', |
|
109 | + //'data-allow-input' => 'true', |
|
110 | + ), |
|
111 | + ) |
|
112 | + ); |
|
113 | + |
|
114 | + // input example |
|
115 | + $output .= aui()->input( |
|
116 | + array( |
|
117 | + 'type' => 'text', |
|
118 | + 'id' => 'text-example', |
|
119 | + 'size' => 'sm', |
|
120 | + //'clear_icon' => true, |
|
121 | + 'name' => 'text-example', |
|
122 | + 'placeholder' => 'text placeholder', |
|
123 | + 'title' => 'Text input example', |
|
124 | + 'value' => '', |
|
125 | + 'required' => false, |
|
126 | + 'help_text' => 'help text', |
|
127 | + 'label' => 'Text input example label', |
|
128 | + 'label_type' => 'top' |
|
129 | + ) |
|
130 | + ); |
|
131 | + |
|
132 | + $output .= aui()->input( |
|
133 | + array( |
|
134 | + 'type' => 'search', |
|
135 | + 'id' => 'text-example', |
|
136 | + 'size' => 'sm', |
|
137 | + //'clear_icon' => true, |
|
138 | + 'name' => 'text-example', |
|
139 | + 'placeholder' => 'text placeholder', |
|
140 | + 'title' => 'Text input example', |
|
141 | + 'value' => '', |
|
142 | + 'required' => false, |
|
143 | + 'help_text' => 'help text', |
|
144 | + 'label' => 'Text input example label', |
|
145 | + 'label_type' => 'top' |
|
146 | + ) |
|
147 | + ); |
|
148 | + |
|
149 | + // input example |
|
150 | + $output .= aui()->input( |
|
151 | + array( |
|
152 | + 'type' => 'url', |
|
153 | + 'id' => 'text-example2', |
|
154 | + 'name' => 'text-example', |
|
155 | + 'placeholder' => 'url placeholder', |
|
156 | + 'title' => 'Text input example', |
|
157 | + 'value' => '', |
|
158 | + 'required' => false, |
|
159 | + 'help_text' => 'help text', |
|
160 | + 'label' => 'Text input example label' |
|
161 | + ) |
|
162 | + ); |
|
163 | + |
|
164 | + // checkbox example |
|
165 | + $output .= aui()->input( |
|
166 | + array( |
|
167 | + 'type' => 'checkbox', |
|
168 | + 'id' => 'checkbox-example', |
|
169 | + 'name' => 'checkbox-example', |
|
170 | + 'placeholder' => 'checkbox-example', |
|
171 | + 'title' => 'Checkbox example', |
|
172 | + 'value' => '1', |
|
173 | + 'checked' => true, |
|
174 | + 'required' => false, |
|
175 | + 'help_text' => 'help text', |
|
176 | + 'label' => 'Checkbox checked' |
|
177 | + ) |
|
178 | + ); |
|
179 | + |
|
180 | + // checkbox example |
|
181 | + $output .= aui()->input( |
|
182 | + array( |
|
183 | + 'type' => 'checkbox', |
|
184 | + 'id' => 'checkbox-example2', |
|
185 | + 'name' => 'checkbox-example2', |
|
186 | + 'placeholder' => 'checkbox-example', |
|
187 | + 'title' => 'Checkbox example', |
|
188 | + 'value' => '1', |
|
189 | + 'checked' => false, |
|
190 | + 'required' => false, |
|
191 | + 'help_text' => 'help text', |
|
192 | + 'label' => 'Checkbox un-checked' |
|
193 | + ) |
|
194 | + ); |
|
195 | + |
|
196 | + // switch example |
|
197 | + $output .= aui()->input( |
|
198 | + array( |
|
199 | + 'type' => 'checkbox', |
|
200 | + 'id' => 'switch-example', |
|
201 | + 'name' => 'switch-example', |
|
202 | + 'placeholder' => 'checkbox-example', |
|
203 | + 'title' => 'Switch example', |
|
204 | + 'value' => '1', |
|
205 | + 'checked' => true, |
|
206 | + 'switch' => true, |
|
207 | + 'required' => false, |
|
208 | + 'help_text' => 'help text', |
|
209 | + 'label' => 'Switch on' |
|
210 | + ) |
|
211 | + ); |
|
212 | + |
|
213 | + // switch example |
|
214 | + $output .= aui()->input( |
|
215 | + array( |
|
216 | + 'type' => 'checkbox', |
|
217 | + 'id' => 'switch-example2', |
|
218 | + 'name' => 'switch-example2', |
|
219 | + 'placeholder' => 'checkbox-example', |
|
220 | + 'title' => 'Switch example', |
|
221 | + 'value' => '1', |
|
222 | + 'checked' => false, |
|
223 | + 'switch' => true, |
|
224 | + 'required' => false, |
|
225 | + 'help_text' => 'help text', |
|
226 | + 'label' => 'Switch off' |
|
227 | + ) |
|
228 | + ); |
|
229 | + |
|
230 | + // close form |
|
231 | + $output .= "</form>"; |
|
232 | + |
|
233 | + return $output; |
|
234 | + } |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | new AyeCode_UI_Plugin(); |
238 | 238 | \ No newline at end of file |
@@ -993,8 +993,8 @@ |
||
993 | 993 | aui_flip_color_scheme_on_scroll(); |
994 | 994 | |
995 | 995 | <?php |
996 | - // FSE tweaks. |
|
997 | - if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?> |
|
996 | + // FSE tweaks. |
|
997 | + if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?> |
|
998 | 998 | function aui_fse_set_data_scroll() { |
999 | 999 | console.log('init scroll'); |
1000 | 1000 | let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas"); |
@@ -26,71 +26,71 @@ discard block |
||
26 | 26 | |
27 | 27 | <?php |
28 | 28 | |
29 | - // Fires before printing a line item column. |
|
30 | - do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
29 | + // Fires before printing a line item column. |
|
30 | + do_action( "getpaid_form_cart_item_before_$key", $item, $form ); |
|
31 | 31 | |
32 | - // Item name. |
|
33 | - if ( 'name' === $key ) { |
|
32 | + // Item name. |
|
33 | + if ( 'name' === $key ) { |
|
34 | 34 | |
35 | 35 | |
36 | - ob_start(); |
|
36 | + ob_start(); |
|
37 | 37 | |
38 | - // Add an optional description. |
|
39 | - $description = $item->get_description(); |
|
38 | + // Add an optional description. |
|
39 | + $description = $item->get_description(); |
|
40 | 40 | |
41 | - if ( ! empty( $description ) ) { |
|
42 | - echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | - } |
|
41 | + if ( ! empty( $description ) ) { |
|
42 | + echo "<small class='form-text text-muted pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
43 | + } |
|
44 | 44 | |
45 | - // Price help text. |
|
46 | - $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | - if ( $description ) { |
|
48 | - echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | - } |
|
45 | + // Price help text. |
|
46 | + $description = getpaid_item_recurring_price_help_text( $item, $currency ); |
|
47 | + if ( $description ) { |
|
48 | + echo "<small class='getpaid-form-item-price-desc form-text text-muted font-italic pr-2 m-0'>" . wp_kses_post( $description ) . '</small>'; |
|
49 | + } |
|
50 | 50 | |
51 | - do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
51 | + do_action( 'getpaid_payment_form_cart_item_description', $item, $form ); |
|
52 | 52 | |
53 | - if ( wpinv_current_user_can_manage_invoicing() ) { |
|
53 | + if ( wpinv_current_user_can_manage_invoicing() ) { |
|
54 | 54 | |
55 | - edit_post_link( |
|
56 | - __( 'Edit this item.', 'invoicing' ), |
|
57 | - '<small class="form-text text-muted">', |
|
58 | - '</small>', |
|
59 | - $item->get_id(), |
|
60 | - 'text-danger' |
|
61 | - ); |
|
55 | + edit_post_link( |
|
56 | + __( 'Edit this item.', 'invoicing' ), |
|
57 | + '<small class="form-text text-muted">', |
|
58 | + '</small>', |
|
59 | + $item->get_id(), |
|
60 | + 'text-danger' |
|
61 | + ); |
|
62 | 62 | |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | - $description = ob_get_clean(); |
|
65 | + $description = ob_get_clean(); |
|
66 | 66 | |
67 | - // Display the name. |
|
68 | - $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
67 | + // Display the name. |
|
68 | + $tootip = empty( $description ) ? '' : ' <i class="fas fa-xs fa-info gp-tooltip d-sm-none text-muted"></i>'; |
|
69 | 69 | |
70 | - $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
70 | + $has_featured_image = has_post_thumbnail( $item->get_id() ); |
|
71 | 71 | |
72 | - if ( $has_featured_image ) { |
|
73 | - echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | - echo '<div class="getpaid-form-item-image-container mr-2">'; |
|
75 | - echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | - echo '</div>'; |
|
77 | - echo '<div class="getpaid-form-item-name-container">'; |
|
78 | - } |
|
72 | + if ( $has_featured_image ) { |
|
73 | + echo '<div class="d-flex align-items-center getpaid-form-item-has-featured-image">'; |
|
74 | + echo '<div class="getpaid-form-item-image-container mr-2">'; |
|
75 | + echo get_the_post_thumbnail( $item->get_id(), 'thumbnail', array( 'class' => 'getpaid-form-item-image mb-0' ) ); |
|
76 | + echo '</div>'; |
|
77 | + echo '<div class="getpaid-form-item-name-container">'; |
|
78 | + } |
|
79 | 79 | |
80 | - echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
80 | + echo '<div class="mb-1 font-weight-bold">' . esc_html( $item->get_name() ) . wp_kses_post( $tootip ) . '</div>'; |
|
81 | 81 | |
82 | - if ( ! empty( $description ) ) { |
|
83 | - printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | - } |
|
82 | + if ( ! empty( $description ) ) { |
|
83 | + printf( '<span class="d-none d-sm-block getpaid-item-desc">%s</span>', wp_kses_post( $description ) ); |
|
84 | + } |
|
85 | 85 | |
86 | - if ( $item->allows_quantities() ) { |
|
87 | - printf( |
|
88 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | - sprintf( |
|
90 | - // translators: %s is the item quantity. |
|
91 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | - sprintf( |
|
93 | - '<input |
|
86 | + if ( $item->allows_quantities() ) { |
|
87 | + printf( |
|
88 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
89 | + sprintf( |
|
90 | + // translators: %s is the item quantity. |
|
91 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
92 | + sprintf( |
|
93 | + '<input |
|
94 | 94 | type="number" |
95 | 95 | step="0.01" |
96 | 96 | style="width: 48px;" |
@@ -99,62 +99,62 @@ discard block |
||
99 | 99 | min="1" |
100 | 100 | max="%s" |
101 | 101 | >', |
102 | - (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | - floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | - ) |
|
105 | - ) |
|
106 | - ); |
|
107 | - } else { |
|
108 | - printf( |
|
109 | - '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | - sprintf( |
|
111 | - // translators: %s is the item quantity. |
|
112 | - esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | - (float) $item->get_quantity() |
|
114 | - ) |
|
115 | - ); |
|
116 | - } |
|
117 | - |
|
118 | - if ( $has_featured_image ) { |
|
119 | - echo '</div>'; |
|
120 | - echo '</div>'; |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - // Item price. |
|
125 | - if ( 'price' === $key ) { |
|
126 | - |
|
127 | - // Set the currency position. |
|
128 | - $position = wpinv_currency_position(); |
|
129 | - |
|
130 | - if ( 'left_space' === $position ) { |
|
131 | - $position = 'left'; |
|
132 | - } |
|
133 | - |
|
134 | - if ( 'right_space' === $position ) { |
|
135 | - $position = 'right'; |
|
136 | - } |
|
137 | - |
|
138 | - if ( $item->user_can_set_their_price() ) { |
|
139 | - $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | - $minimum = (float) $item->get_minimum_price(); |
|
141 | - $validate_minimum = ''; |
|
142 | - $class = ''; |
|
143 | - $data_minimum = ''; |
|
144 | - |
|
145 | - if ( $minimum > 0 ) { |
|
146 | - $validate_minimum = sprintf( |
|
147 | - // translators: %s is the minimum price. |
|
148 | - esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | - wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | - ); |
|
151 | - |
|
152 | - $class = 'getpaid-validate-minimum-amount'; |
|
153 | - |
|
154 | - $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | - } |
|
156 | - |
|
157 | - ?> |
|
102 | + (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(), |
|
103 | + floatval( null !== $max_qty ? $max_qty : 1000000000000 ) |
|
104 | + ) |
|
105 | + ) |
|
106 | + ); |
|
107 | + } else { |
|
108 | + printf( |
|
109 | + '<small class="d-sm-none text-muted form-text">%s</small>', |
|
110 | + sprintf( |
|
111 | + // translators: %s is the item quantity. |
|
112 | + esc_html__( 'Qty %s', 'invoicing' ), |
|
113 | + (float) $item->get_quantity() |
|
114 | + ) |
|
115 | + ); |
|
116 | + } |
|
117 | + |
|
118 | + if ( $has_featured_image ) { |
|
119 | + echo '</div>'; |
|
120 | + echo '</div>'; |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + // Item price. |
|
125 | + if ( 'price' === $key ) { |
|
126 | + |
|
127 | + // Set the currency position. |
|
128 | + $position = wpinv_currency_position(); |
|
129 | + |
|
130 | + if ( 'left_space' === $position ) { |
|
131 | + $position = 'left'; |
|
132 | + } |
|
133 | + |
|
134 | + if ( 'right_space' === $position ) { |
|
135 | + $position = 'right'; |
|
136 | + } |
|
137 | + |
|
138 | + if ( $item->user_can_set_their_price() ) { |
|
139 | + $price = max( (float) $item->get_price(), (float) $item->get_minimum_price() ); |
|
140 | + $minimum = (float) $item->get_minimum_price(); |
|
141 | + $validate_minimum = ''; |
|
142 | + $class = ''; |
|
143 | + $data_minimum = ''; |
|
144 | + |
|
145 | + if ( $minimum > 0 ) { |
|
146 | + $validate_minimum = sprintf( |
|
147 | + // translators: %s is the minimum price. |
|
148 | + esc_attr__( 'The minimum allowed amount is %s', 'invoicing' ), |
|
149 | + wp_strip_all_tags( wpinv_price( $minimum, $currency ) ) |
|
150 | + ); |
|
151 | + |
|
152 | + $class = 'getpaid-validate-minimum-amount'; |
|
153 | + |
|
154 | + $data_minimum = "data-minimum-amount='" . esc_attr( getpaid_unstandardize_amount( $minimum ) ) . "'"; |
|
155 | + } |
|
156 | + |
|
157 | + ?> |
|
158 | 158 | <div class="input-group input-group-sm"> |
159 | 159 | <?php if ( 'left' === $position ) : ?> |
160 | 160 | <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?> |
@@ -195,46 +195,46 @@ discard block |
||
195 | 195 | |
196 | 196 | <?php |
197 | 197 | |
198 | - } else { |
|
199 | - ?> |
|
198 | + } else { |
|
199 | + ?> |
|
200 | 200 | <span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-price"> |
201 | 201 | <?php echo wp_kses_post( wpinv_price( $item->get_price(), $currency ) ); ?> |
202 | 202 | </span> |
203 | 203 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][price]' type='hidden' class='getpaid-item-price-input' value='<?php echo esc_attr( $item->get_price() ); ?>'> |
204 | 204 | <?php |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - printf( |
|
207 | + printf( |
|
208 | 208 | '<small class="d-sm-none text-muted form-text getpaid-mobile-item-subtotal">%s</small>', |
209 | - // translators: %s is the item subtotal. |
|
209 | + // translators: %s is the item subtotal. |
|
210 | 210 | sprintf( esc_html__( 'Subtotal: %s', 'invoicing' ), wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ) ) |
211 | 211 | ); |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - // Item quantity. |
|
215 | - if ( 'quantity' === $key ) { |
|
214 | + // Item quantity. |
|
215 | + if ( 'quantity' === $key ) { |
|
216 | 216 | |
217 | - if ( $item->allows_quantities() ) { |
|
218 | - ?> |
|
217 | + if ( $item->allows_quantities() ) { |
|
218 | + ?> |
|
219 | 219 | <input name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' type="number" step="any" style='width: 64px; line-height: 1; min-height: 35px;' class='getpaid-item-quantity-input p-1 align-middle font-weight-normal shadow-none m-0 rounded-0 text-center border' value='<?php echo (float) $item->get_quantity() == 0 ? 1 : (float) $item->get_quantity(); ?>' min='1' <?php echo null !== $max_qty ? 'max="' . (float) $max_qty . '"' : ''; ?> required> |
220 | 220 | <?php |
221 | - } else { |
|
222 | - ?> |
|
221 | + } else { |
|
222 | + ?> |
|
223 | 223 | <span class="getpaid-items-<?php echo (int) $item->get_id(); ?>-view-quantity"> |
224 | 224 | <?php echo (float) $item->get_quantity(); ?> |
225 | 225 | </span> |
226 | 226 | <input type='hidden' name='getpaid-items[<?php echo (int) $item->get_id(); ?>][quantity]' class='getpaid-item-quantity-input' value='<?php echo (float) $item->get_quantity(); ?>'> |
227 | 227 | <?php |
228 | - } |
|
228 | + } |
|
229 | 229 | } |
230 | 230 | |
231 | - // Item sub total. |
|
232 | - if ( 'subtotal' === $key ) { |
|
233 | - echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
234 | - } |
|
231 | + // Item sub total. |
|
232 | + if ( 'subtotal' === $key ) { |
|
233 | + echo wp_kses_post( wpinv_price( $item->get_sub_total(), $currency ) ); |
|
234 | + } |
|
235 | 235 | |
236 | - do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
237 | - ?> |
|
236 | + do_action( "getpaid_payment_form_cart_item_$key", $item, $form ); |
|
237 | + ?> |
|
238 | 238 | |
239 | 239 | </div> |
240 | 240 |
@@ -12,51 +12,51 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Payment_Form_Submission_Items { |
14 | 14 | |
15 | - /** |
|
16 | - * Submission items. |
|
17 | - * @var GetPaid_Form_Item[] |
|
18 | - */ |
|
19 | - public $items = array(); |
|
15 | + /** |
|
16 | + * Submission items. |
|
17 | + * @var GetPaid_Form_Item[] |
|
18 | + */ |
|
19 | + public $items = array(); |
|
20 | 20 | |
21 | 21 | /** |
22 | - * Class constructor |
|
23 | - * |
|
24 | - * @param GetPaid_Payment_Form_Submission $submission |
|
25 | - */ |
|
26 | - public function __construct( $submission ) { |
|
27 | - |
|
28 | - $data = $submission->get_data(); |
|
29 | - $payment_form = $submission->get_payment_form(); |
|
30 | - $invoice = $submission->get_invoice(); |
|
31 | - $force_prices = array(); |
|
32 | - |
|
33 | - // Prepare the selected items. |
|
34 | - $selected_items = array(); |
|
35 | - if ( ! empty( $data['getpaid-items'] ) ) { |
|
36 | - $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
37 | - |
|
38 | - if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) { |
|
39 | - foreach ( $invoice->get_items() as $invoice_item ) { |
|
40 | - if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) { |
|
41 | - $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity(); |
|
42 | - $selected_items[ $invoice_item->get_id() ]['price'] = $invoice_item->get_price(); |
|
43 | - |
|
44 | - $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price(); |
|
45 | - } |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
49 | - |
|
50 | - // (Maybe) set form items. |
|
51 | - if ( isset( $data['getpaid-form-items'] ) ) { |
|
52 | - |
|
53 | - // Confirm items key. |
|
54 | - $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
55 | - if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) { |
|
56 | - throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
57 | - } |
|
58 | - |
|
59 | - $items = array(); |
|
22 | + * Class constructor |
|
23 | + * |
|
24 | + * @param GetPaid_Payment_Form_Submission $submission |
|
25 | + */ |
|
26 | + public function __construct( $submission ) { |
|
27 | + |
|
28 | + $data = $submission->get_data(); |
|
29 | + $payment_form = $submission->get_payment_form(); |
|
30 | + $invoice = $submission->get_invoice(); |
|
31 | + $force_prices = array(); |
|
32 | + |
|
33 | + // Prepare the selected items. |
|
34 | + $selected_items = array(); |
|
35 | + if ( ! empty( $data['getpaid-items'] ) ) { |
|
36 | + $selected_items = wpinv_clean( $data['getpaid-items'] ); |
|
37 | + |
|
38 | + if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) { |
|
39 | + foreach ( $invoice->get_items() as $invoice_item ) { |
|
40 | + if ( isset( $selected_items[ $invoice_item->get_id() ] ) ) { |
|
41 | + $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity(); |
|
42 | + $selected_items[ $invoice_item->get_id() ]['price'] = $invoice_item->get_price(); |
|
43 | + |
|
44 | + $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price(); |
|
45 | + } |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | + |
|
50 | + // (Maybe) set form items. |
|
51 | + if ( isset( $data['getpaid-form-items'] ) ) { |
|
52 | + |
|
53 | + // Confirm items key. |
|
54 | + $form_items = wpinv_clean( $data['getpaid-form-items'] ); |
|
55 | + if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) { |
|
56 | + throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) ); |
|
57 | + } |
|
58 | + |
|
59 | + $items = array(); |
|
60 | 60 | $item_ids = array(); |
61 | 61 | |
62 | 62 | foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) { |
@@ -69,10 +69,10 @@ discard block |
||
69 | 69 | $item->set_is_required( false ); |
70 | 70 | } |
71 | 71 | |
72 | - if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) { |
|
73 | - $item->set_is_dynamic_pricing( true ); |
|
74 | - $item->set_minimum_price( 0 ); |
|
75 | - } |
|
72 | + if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) { |
|
73 | + $item->set_is_dynamic_pricing( true ); |
|
74 | + $item->set_minimum_price( 0 ); |
|
75 | + } |
|
76 | 76 | |
77 | 77 | $item_ids[] = $item->get_id(); |
78 | 78 | $items[] = $item; |
@@ -87,61 +87,61 @@ discard block |
||
87 | 87 | $items[] = $item; |
88 | 88 | } |
89 | 89 | } |
90 | - } |
|
90 | + } |
|
91 | 91 | |
92 | 92 | $payment_form->set_items( $items ); |
93 | 93 | |
94 | - } |
|
95 | - |
|
96 | - // Process each individual item. |
|
97 | - foreach ( $payment_form->get_items() as $item ) { |
|
98 | - $this->process_item( $item, $selected_items, $submission ); |
|
99 | - } |
|
100 | - |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Process a single item. |
|
105 | - * |
|
106 | - * @param GetPaid_Form_Item $item |
|
107 | - * @param array $selected_items |
|
108 | - * @param GetPaid_Payment_Form_Submission $submission |
|
109 | - */ |
|
110 | - public function process_item( $item, $selected_items, $submission ) { |
|
94 | + } |
|
111 | 95 | |
112 | - // Abort if this is an optional item and it has not been selected. |
|
113 | - if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
114 | - return; |
|
115 | - } |
|
96 | + // Process each individual item. |
|
97 | + foreach ( $payment_form->get_items() as $item ) { |
|
98 | + $this->process_item( $item, $selected_items, $submission ); |
|
99 | + } |
|
116 | 100 | |
117 | - // (maybe) let customers change the quantities and prices. |
|
118 | - if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
101 | + } |
|
119 | 102 | |
120 | - // Maybe change the quantities. |
|
121 | - if ( $item->allows_quantities() ) { |
|
122 | - $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
123 | - } |
|
103 | + /** |
|
104 | + * Process a single item. |
|
105 | + * |
|
106 | + * @param GetPaid_Form_Item $item |
|
107 | + * @param array $selected_items |
|
108 | + * @param GetPaid_Payment_Form_Submission $submission |
|
109 | + */ |
|
110 | + public function process_item( $item, $selected_items, $submission ) { |
|
111 | + |
|
112 | + // Abort if this is an optional item and it has not been selected. |
|
113 | + if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) { |
|
114 | + return; |
|
115 | + } |
|
116 | + |
|
117 | + // (maybe) let customers change the quantities and prices. |
|
118 | + if ( isset( $selected_items[ $item->get_id() ] ) ) { |
|
119 | + |
|
120 | + // Maybe change the quantities. |
|
121 | + if ( $item->allows_quantities() ) { |
|
122 | + $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] ); |
|
123 | + } |
|
124 | 124 | |
125 | - // Maybe change the price. |
|
126 | - if ( $item->user_can_set_their_price() ) { |
|
127 | - $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
125 | + // Maybe change the price. |
|
126 | + if ( $item->user_can_set_their_price() ) { |
|
127 | + $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] ); |
|
128 | 128 | |
129 | - if ( $item->get_minimum_price() > $price ) { |
|
130 | - throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
131 | - } |
|
129 | + if ( $item->get_minimum_price() > $price ) { |
|
130 | + throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) ); |
|
131 | + } |
|
132 | 132 | |
133 | - $item->set_price( $price ); |
|
133 | + $item->set_price( $price ); |
|
134 | 134 | |
135 | - } |
|
136 | - } |
|
135 | + } |
|
136 | + } |
|
137 | 137 | |
138 | - if ( 0 == $item->get_quantity() ) { |
|
139 | - return; |
|
140 | - } |
|
138 | + if ( 0 == $item->get_quantity() ) { |
|
139 | + return; |
|
140 | + } |
|
141 | 141 | |
142 | - // Save the item. |
|
143 | - $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
142 | + // Save the item. |
|
143 | + $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission ); |
|
144 | 144 | |
145 | - } |
|
145 | + } |
|
146 | 146 | |
147 | 147 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,67 +10,67 @@ discard block |
||
10 | 10 | class GetPaid_Form_Item extends WPInv_Item { |
11 | 11 | |
12 | 12 | /** |
13 | - * Stores a custom description for the item. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $custom_description = null; |
|
18 | - |
|
19 | - /** |
|
20 | - * Stores the item quantity. |
|
21 | - * |
|
22 | - * @var float |
|
23 | - */ |
|
24 | - protected $quantity = 1; |
|
25 | - |
|
26 | - /** |
|
27 | - * Stores the item meta. |
|
28 | - * |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $meta = array(); |
|
32 | - |
|
33 | - /** |
|
34 | - * Is this item required? |
|
35 | - * |
|
36 | - * @var int |
|
37 | - */ |
|
38 | - protected $is_required = true; |
|
39 | - |
|
40 | - /** |
|
41 | - * Are quantities allowed? |
|
42 | - * |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $allow_quantities = false; |
|
46 | - |
|
47 | - /** |
|
48 | - * Associated invoice. |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - public $invoice_id = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * Item discount. |
|
56 | - * |
|
57 | - * @var float |
|
58 | - */ |
|
59 | - public $item_discount = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * Recurring item discount. |
|
63 | - * |
|
64 | - * @var float |
|
65 | - */ |
|
66 | - public $recurring_item_discount = 0; |
|
67 | - |
|
68 | - /** |
|
69 | - * Item tax. |
|
70 | - * |
|
71 | - * @var float |
|
72 | - */ |
|
73 | - public $item_tax = 0; |
|
13 | + * Stores a custom description for the item. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $custom_description = null; |
|
18 | + |
|
19 | + /** |
|
20 | + * Stores the item quantity. |
|
21 | + * |
|
22 | + * @var float |
|
23 | + */ |
|
24 | + protected $quantity = 1; |
|
25 | + |
|
26 | + /** |
|
27 | + * Stores the item meta. |
|
28 | + * |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $meta = array(); |
|
32 | + |
|
33 | + /** |
|
34 | + * Is this item required? |
|
35 | + * |
|
36 | + * @var int |
|
37 | + */ |
|
38 | + protected $is_required = true; |
|
39 | + |
|
40 | + /** |
|
41 | + * Are quantities allowed? |
|
42 | + * |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $allow_quantities = false; |
|
46 | + |
|
47 | + /** |
|
48 | + * Associated invoice. |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + public $invoice_id = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * Item discount. |
|
56 | + * |
|
57 | + * @var float |
|
58 | + */ |
|
59 | + public $item_discount = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * Recurring item discount. |
|
63 | + * |
|
64 | + * @var float |
|
65 | + */ |
|
66 | + public $recurring_item_discount = 0; |
|
67 | + |
|
68 | + /** |
|
69 | + * Item tax. |
|
70 | + * |
|
71 | + * @var float |
|
72 | + */ |
|
73 | + public $item_tax = 0; |
|
74 | 74 | |
75 | 75 | /* |
76 | 76 | |-------------------------------------------------------------------------- |
@@ -88,230 +88,230 @@ discard block |
||
88 | 88 | */ |
89 | 89 | |
90 | 90 | /** |
91 | - * Get the item name. |
|
92 | - * |
|
93 | - * @since 1.0.19 |
|
94 | - * @param string $context View or edit context. |
|
95 | - * @return string |
|
96 | - */ |
|
97 | - public function get_name( $context = 'view' ) { |
|
98 | - $name = parent::get_name( $context ); |
|
99 | - return $name . wpinv_get_item_suffix( $this ); |
|
100 | - } |
|
101 | - |
|
102 | - /** |
|
103 | - * Get the item name without a suffix. |
|
104 | - * |
|
105 | - * @since 1.0.19 |
|
106 | - * @param string $context View or edit context. |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - public function get_raw_name( $context = 'view' ) { |
|
110 | - return parent::get_name( $context ); |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the item description. |
|
115 | - * |
|
116 | - * @since 1.0.19 |
|
117 | - * @param string $context View or edit context. |
|
118 | - * @return string |
|
119 | - */ |
|
120 | - public function get_description( $context = 'view' ) { |
|
121 | - |
|
122 | - if ( isset( $this->custom_description ) ) { |
|
123 | - return $this->custom_description; |
|
124 | - } |
|
125 | - |
|
126 | - return parent::get_description( $context ); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Returns the sub total. |
|
131 | - * |
|
132 | - * @since 1.0.19 |
|
133 | - * @param string $context View or edit context. |
|
134 | - * @return float |
|
135 | - */ |
|
136 | - public function get_sub_total( $context = 'view' ) { |
|
137 | - return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns the recurring sub total. |
|
142 | - * |
|
143 | - * @since 1.0.19 |
|
144 | - * @param string $context View or edit context. |
|
145 | - * @return float |
|
146 | - */ |
|
147 | - public function get_recurring_sub_total( $context = 'view' ) { |
|
148 | - |
|
149 | - if ( $this->is_recurring() ) { |
|
150 | - return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
151 | - } |
|
152 | - |
|
153 | - return 0; |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @deprecated |
|
158 | - */ |
|
159 | - public function get_qantity( $context = 'view' ) { |
|
160 | - return $this->get_quantity( $context ); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Get the item quantity. |
|
165 | - * |
|
166 | - * @since 1.0.19 |
|
167 | - * @param string $context View or edit context. |
|
168 | - * @return float |
|
169 | - */ |
|
170 | - public function get_quantity( $context = 'view' ) { |
|
171 | - $quantity = (float) $this->quantity; |
|
172 | - |
|
173 | - if ( 'view' === $context ) { |
|
174 | - return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
175 | - } |
|
176 | - |
|
177 | - return $quantity; |
|
178 | - |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Get the item meta data. |
|
183 | - * |
|
184 | - * @since 1.0.19 |
|
185 | - * @param string $context View or edit context. |
|
186 | - * @return meta |
|
187 | - */ |
|
188 | - public function get_item_meta( $context = 'view' ) { |
|
189 | - $meta = $this->meta; |
|
190 | - |
|
191 | - if ( 'view' === $context ) { |
|
192 | - return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
193 | - } |
|
194 | - |
|
195 | - return $meta; |
|
196 | - |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * Returns whether or not customers can update the item quantity. |
|
201 | - * |
|
202 | - * @since 1.0.19 |
|
203 | - * @param string $context View or edit context. |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function get_allow_quantities( $context = 'view' ) { |
|
207 | - $allow_quantities = (bool) $this->allow_quantities; |
|
208 | - |
|
209 | - if ( 'view' === $context ) { |
|
210 | - return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
211 | - } |
|
212 | - |
|
213 | - return $allow_quantities; |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Returns whether or not the item is required. |
|
219 | - * |
|
220 | - * @since 1.0.19 |
|
221 | - * @param string $context View or edit context. |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - public function get_is_required( $context = 'view' ) { |
|
225 | - $is_required = (bool) $this->is_required; |
|
226 | - |
|
227 | - if ( 'view' === $context ) { |
|
228 | - return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
229 | - } |
|
230 | - |
|
231 | - return $is_required; |
|
232 | - |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Prepares form data for use. |
|
237 | - * |
|
238 | - * @since 1.0.19 |
|
239 | - * @return array |
|
240 | - */ |
|
241 | - public function prepare_data_for_use( $required = null ) { |
|
242 | - |
|
243 | - $required = is_null( $required ) ? $this->is_required() : $required; |
|
244 | - return array( |
|
245 | - 'title' => wp_strip_all_tags( $this->get_name() ), |
|
246 | - 'id' => $this->get_id(), |
|
247 | - 'price' => $this->get_price(), |
|
248 | - 'recurring' => $this->is_recurring(), |
|
249 | - 'description' => $this->get_description(), |
|
250 | - 'allow_quantities' => $this->allows_quantities(), |
|
251 | - 'required' => $required, |
|
252 | - ); |
|
253 | - |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Prepares form data for ajax use. |
|
258 | - * |
|
259 | - * @since 1.0.19 |
|
260 | - * @return array |
|
261 | - */ |
|
262 | - public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
263 | - |
|
264 | - $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
265 | - |
|
266 | - if ( $description ) { |
|
267 | - $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
268 | - } |
|
269 | - |
|
270 | - $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
271 | - $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
272 | - return array( |
|
273 | - 'id' => $this->get_id(), |
|
274 | - 'texts' => array( |
|
275 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
276 | - 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
277 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
278 | - 'item-price' => wpinv_price( $price, $currency ), |
|
279 | - 'item-total' => wpinv_price( $subtotal, $currency ), |
|
280 | - ), |
|
281 | - 'inputs' => array( |
|
282 | - 'item-id' => $this->get_id(), |
|
283 | - 'item-name' => sanitize_text_field( $this->get_name() ), |
|
284 | - 'item-description' => wp_kses_post( $this->get_description() ), |
|
285 | - 'item-quantity' => floatval( $this->get_quantity() ), |
|
286 | - 'item-price' => $price, |
|
287 | - ), |
|
288 | - ); |
|
289 | - |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Prepares form data for saving (cart_details). |
|
294 | - * |
|
295 | - * @since 1.0.19 |
|
296 | - * @return array |
|
297 | - */ |
|
298 | - public function prepare_data_for_saving() { |
|
299 | - |
|
300 | - return array( |
|
301 | - 'post_id' => $this->invoice_id, |
|
302 | - 'item_id' => $this->get_id(), |
|
303 | - 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
304 | - 'item_description' => $this->get_description( 'edit' ), |
|
305 | - 'tax' => $this->item_tax, |
|
306 | - 'item_price' => $this->get_price( 'edit' ), |
|
307 | - 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
308 | - 'discount' => $this->item_discount, |
|
309 | - 'subtotal' => $this->get_sub_total( 'edit' ), |
|
310 | - 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
311 | - 'meta' => $this->get_item_meta( 'edit' ), |
|
312 | - ); |
|
313 | - |
|
314 | - } |
|
91 | + * Get the item name. |
|
92 | + * |
|
93 | + * @since 1.0.19 |
|
94 | + * @param string $context View or edit context. |
|
95 | + * @return string |
|
96 | + */ |
|
97 | + public function get_name( $context = 'view' ) { |
|
98 | + $name = parent::get_name( $context ); |
|
99 | + return $name . wpinv_get_item_suffix( $this ); |
|
100 | + } |
|
101 | + |
|
102 | + /** |
|
103 | + * Get the item name without a suffix. |
|
104 | + * |
|
105 | + * @since 1.0.19 |
|
106 | + * @param string $context View or edit context. |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + public function get_raw_name( $context = 'view' ) { |
|
110 | + return parent::get_name( $context ); |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the item description. |
|
115 | + * |
|
116 | + * @since 1.0.19 |
|
117 | + * @param string $context View or edit context. |
|
118 | + * @return string |
|
119 | + */ |
|
120 | + public function get_description( $context = 'view' ) { |
|
121 | + |
|
122 | + if ( isset( $this->custom_description ) ) { |
|
123 | + return $this->custom_description; |
|
124 | + } |
|
125 | + |
|
126 | + return parent::get_description( $context ); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Returns the sub total. |
|
131 | + * |
|
132 | + * @since 1.0.19 |
|
133 | + * @param string $context View or edit context. |
|
134 | + * @return float |
|
135 | + */ |
|
136 | + public function get_sub_total( $context = 'view' ) { |
|
137 | + return $this->get_quantity( $context ) * $this->get_initial_price( $context ); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns the recurring sub total. |
|
142 | + * |
|
143 | + * @since 1.0.19 |
|
144 | + * @param string $context View or edit context. |
|
145 | + * @return float |
|
146 | + */ |
|
147 | + public function get_recurring_sub_total( $context = 'view' ) { |
|
148 | + |
|
149 | + if ( $this->is_recurring() ) { |
|
150 | + return $this->get_quantity( $context ) * $this->get_price( $context ); |
|
151 | + } |
|
152 | + |
|
153 | + return 0; |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @deprecated |
|
158 | + */ |
|
159 | + public function get_qantity( $context = 'view' ) { |
|
160 | + return $this->get_quantity( $context ); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Get the item quantity. |
|
165 | + * |
|
166 | + * @since 1.0.19 |
|
167 | + * @param string $context View or edit context. |
|
168 | + * @return float |
|
169 | + */ |
|
170 | + public function get_quantity( $context = 'view' ) { |
|
171 | + $quantity = (float) $this->quantity; |
|
172 | + |
|
173 | + if ( 'view' === $context ) { |
|
174 | + return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this ); |
|
175 | + } |
|
176 | + |
|
177 | + return $quantity; |
|
178 | + |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Get the item meta data. |
|
183 | + * |
|
184 | + * @since 1.0.19 |
|
185 | + * @param string $context View or edit context. |
|
186 | + * @return meta |
|
187 | + */ |
|
188 | + public function get_item_meta( $context = 'view' ) { |
|
189 | + $meta = $this->meta; |
|
190 | + |
|
191 | + if ( 'view' === $context ) { |
|
192 | + return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this ); |
|
193 | + } |
|
194 | + |
|
195 | + return $meta; |
|
196 | + |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * Returns whether or not customers can update the item quantity. |
|
201 | + * |
|
202 | + * @since 1.0.19 |
|
203 | + * @param string $context View or edit context. |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function get_allow_quantities( $context = 'view' ) { |
|
207 | + $allow_quantities = (bool) $this->allow_quantities; |
|
208 | + |
|
209 | + if ( 'view' === $context ) { |
|
210 | + return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this ); |
|
211 | + } |
|
212 | + |
|
213 | + return $allow_quantities; |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Returns whether or not the item is required. |
|
219 | + * |
|
220 | + * @since 1.0.19 |
|
221 | + * @param string $context View or edit context. |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + public function get_is_required( $context = 'view' ) { |
|
225 | + $is_required = (bool) $this->is_required; |
|
226 | + |
|
227 | + if ( 'view' === $context ) { |
|
228 | + return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this ); |
|
229 | + } |
|
230 | + |
|
231 | + return $is_required; |
|
232 | + |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Prepares form data for use. |
|
237 | + * |
|
238 | + * @since 1.0.19 |
|
239 | + * @return array |
|
240 | + */ |
|
241 | + public function prepare_data_for_use( $required = null ) { |
|
242 | + |
|
243 | + $required = is_null( $required ) ? $this->is_required() : $required; |
|
244 | + return array( |
|
245 | + 'title' => wp_strip_all_tags( $this->get_name() ), |
|
246 | + 'id' => $this->get_id(), |
|
247 | + 'price' => $this->get_price(), |
|
248 | + 'recurring' => $this->is_recurring(), |
|
249 | + 'description' => $this->get_description(), |
|
250 | + 'allow_quantities' => $this->allows_quantities(), |
|
251 | + 'required' => $required, |
|
252 | + ); |
|
253 | + |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Prepares form data for ajax use. |
|
258 | + * |
|
259 | + * @since 1.0.19 |
|
260 | + * @return array |
|
261 | + */ |
|
262 | + public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) { |
|
263 | + |
|
264 | + $description = getpaid_item_recurring_price_help_text( $this, $currency ); |
|
265 | + |
|
266 | + if ( $description ) { |
|
267 | + $description = "<div class='getpaid-subscription-help-text'>$description</div>"; |
|
268 | + } |
|
269 | + |
|
270 | + $price = ! $is_renewal ? $this->get_price() : $this->get_recurring_price(); |
|
271 | + $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total(); |
|
272 | + return array( |
|
273 | + 'id' => $this->get_id(), |
|
274 | + 'texts' => array( |
|
275 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
276 | + 'item-description' => wp_kses_post( $this->get_description() ) . $description, |
|
277 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
278 | + 'item-price' => wpinv_price( $price, $currency ), |
|
279 | + 'item-total' => wpinv_price( $subtotal, $currency ), |
|
280 | + ), |
|
281 | + 'inputs' => array( |
|
282 | + 'item-id' => $this->get_id(), |
|
283 | + 'item-name' => sanitize_text_field( $this->get_name() ), |
|
284 | + 'item-description' => wp_kses_post( $this->get_description() ), |
|
285 | + 'item-quantity' => floatval( $this->get_quantity() ), |
|
286 | + 'item-price' => $price, |
|
287 | + ), |
|
288 | + ); |
|
289 | + |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Prepares form data for saving (cart_details). |
|
294 | + * |
|
295 | + * @since 1.0.19 |
|
296 | + * @return array |
|
297 | + */ |
|
298 | + public function prepare_data_for_saving() { |
|
299 | + |
|
300 | + return array( |
|
301 | + 'post_id' => $this->invoice_id, |
|
302 | + 'item_id' => $this->get_id(), |
|
303 | + 'item_name' => sanitize_text_field( $this->get_raw_name( 'edit' ) ), |
|
304 | + 'item_description' => $this->get_description( 'edit' ), |
|
305 | + 'tax' => $this->item_tax, |
|
306 | + 'item_price' => $this->get_price( 'edit' ), |
|
307 | + 'quantity' => (float) $this->get_quantity( 'edit' ), |
|
308 | + 'discount' => $this->item_discount, |
|
309 | + 'subtotal' => $this->get_sub_total( 'edit' ), |
|
310 | + 'price' => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount, |
|
311 | + 'meta' => $this->get_item_meta( 'edit' ), |
|
312 | + ); |
|
313 | + |
|
314 | + } |
|
315 | 315 | |
316 | 316 | /* |
317 | 317 | |-------------------------------------------------------------------------- |
@@ -323,70 +323,70 @@ discard block |
||
323 | 323 | | object. |
324 | 324 | */ |
325 | 325 | |
326 | - /** |
|
327 | - * Set the item qantity. |
|
328 | - * |
|
329 | - * @since 1.0.19 |
|
330 | - * @param float $quantity The item quantity. |
|
331 | - */ |
|
332 | - public function set_quantity( $quantity ) { |
|
333 | - |
|
334 | - if ( ! is_numeric( $quantity ) ) { |
|
335 | - $quantity = 1; |
|
336 | - } |
|
337 | - |
|
338 | - $this->quantity = (float) $quantity; |
|
339 | - |
|
340 | - } |
|
341 | - |
|
342 | - /** |
|
343 | - * Set the item meta data. |
|
344 | - * |
|
345 | - * @since 1.0.19 |
|
346 | - * @param array $meta The item meta data. |
|
347 | - */ |
|
348 | - public function set_item_meta( $meta ) { |
|
349 | - $this->meta = maybe_unserialize( $meta ); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Set whether or not the quantities are allowed. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @param bool $allow_quantities |
|
357 | - */ |
|
358 | - public function set_allow_quantities( $allow_quantities ) { |
|
359 | - $this->allow_quantities = (bool) $allow_quantities; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Set whether or not the item is required. |
|
364 | - * |
|
365 | - * @since 1.0.19 |
|
366 | - * @param bool $is_required |
|
367 | - */ |
|
368 | - public function set_is_required( $is_required ) { |
|
369 | - $this->is_required = (bool) $is_required; |
|
370 | - } |
|
371 | - |
|
372 | - /** |
|
373 | - * Sets the custom item description. |
|
374 | - * |
|
375 | - * @since 1.0.19 |
|
376 | - * @param string $description |
|
377 | - */ |
|
378 | - public function set_custom_description( $description ) { |
|
379 | - $this->custom_description = $description; |
|
380 | - } |
|
326 | + /** |
|
327 | + * Set the item qantity. |
|
328 | + * |
|
329 | + * @since 1.0.19 |
|
330 | + * @param float $quantity The item quantity. |
|
331 | + */ |
|
332 | + public function set_quantity( $quantity ) { |
|
333 | + |
|
334 | + if ( ! is_numeric( $quantity ) ) { |
|
335 | + $quantity = 1; |
|
336 | + } |
|
337 | + |
|
338 | + $this->quantity = (float) $quantity; |
|
339 | + |
|
340 | + } |
|
341 | + |
|
342 | + /** |
|
343 | + * Set the item meta data. |
|
344 | + * |
|
345 | + * @since 1.0.19 |
|
346 | + * @param array $meta The item meta data. |
|
347 | + */ |
|
348 | + public function set_item_meta( $meta ) { |
|
349 | + $this->meta = maybe_unserialize( $meta ); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Set whether or not the quantities are allowed. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @param bool $allow_quantities |
|
357 | + */ |
|
358 | + public function set_allow_quantities( $allow_quantities ) { |
|
359 | + $this->allow_quantities = (bool) $allow_quantities; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Set whether or not the item is required. |
|
364 | + * |
|
365 | + * @since 1.0.19 |
|
366 | + * @param bool $is_required |
|
367 | + */ |
|
368 | + public function set_is_required( $is_required ) { |
|
369 | + $this->is_required = (bool) $is_required; |
|
370 | + } |
|
371 | + |
|
372 | + /** |
|
373 | + * Sets the custom item description. |
|
374 | + * |
|
375 | + * @since 1.0.19 |
|
376 | + * @param string $description |
|
377 | + */ |
|
378 | + public function set_custom_description( $description ) { |
|
379 | + $this->custom_description = $description; |
|
380 | + } |
|
381 | 381 | |
382 | 382 | /** |
383 | 383 | * We do not want to save items to the database. |
384 | 384 | * |
385 | - * @return int item id |
|
385 | + * @return int item id |
|
386 | 386 | */ |
387 | 387 | public function save( $data = array() ) { |
388 | 388 | return $this->get_id(); |
389 | - } |
|
389 | + } |
|
390 | 390 | |
391 | 391 | /* |
392 | 392 | |-------------------------------------------------------------------------- |
@@ -398,23 +398,23 @@ discard block |
||
398 | 398 | */ |
399 | 399 | |
400 | 400 | /** |
401 | - * Checks whether the item has enabled dynamic pricing. |
|
402 | - * |
|
403 | - * @since 1.0.19 |
|
404 | - * @return bool |
|
405 | - */ |
|
406 | - public function is_required() { |
|
401 | + * Checks whether the item has enabled dynamic pricing. |
|
402 | + * |
|
403 | + * @since 1.0.19 |
|
404 | + * @return bool |
|
405 | + */ |
|
406 | + public function is_required() { |
|
407 | 407 | return (bool) $this->get_is_required(); |
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Checks whether users can edit the quantities. |
|
412 | - * |
|
413 | - * @since 1.0.19 |
|
414 | - * @return bool |
|
415 | - */ |
|
416 | - public function allows_quantities() { |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Checks whether users can edit the quantities. |
|
412 | + * |
|
413 | + * @since 1.0.19 |
|
414 | + * @return bool |
|
415 | + */ |
|
416 | + public function allows_quantities() { |
|
417 | 417 | return (bool) $this->get_allow_quantities(); |
418 | - } |
|
418 | + } |
|
419 | 419 | |
420 | 420 | } |
@@ -13,464 +13,464 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - |
|
141 | - do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this ); |
|
142 | - |
|
143 | - // Register gateway. |
|
144 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
145 | - |
|
146 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
147 | - |
|
148 | - // Add support for various features. |
|
149 | - foreach ( $this->supports as $feature ) { |
|
150 | - add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
151 | - add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
152 | - add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
153 | - } |
|
154 | - |
|
155 | - // Invoice addons. |
|
156 | - if ( $this->supports( 'addons' ) ) { |
|
157 | - add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
158 | - } |
|
159 | - |
|
160 | - // Gateway settings. |
|
161 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
162 | - |
|
163 | - // Gateway checkout fiellds. |
|
164 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
165 | - |
|
166 | - // Process payment. |
|
167 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
168 | - |
|
169 | - // Change the checkout button text. |
|
170 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
171 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
172 | - } |
|
173 | - |
|
174 | - // Check if a gateway is valid for a given currency. |
|
175 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
176 | - |
|
177 | - // Generate the transaction url. |
|
178 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
179 | - |
|
180 | - // Generate the subscription url. |
|
181 | - add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
182 | - |
|
183 | - // Confirm payments. |
|
184 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
185 | - |
|
186 | - // Verify IPNs. |
|
187 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
188 | - |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Checks if this gateway is a given gateway. |
|
193 | - * |
|
194 | - * @since 1.0.19 |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function is( $gateway ) { |
|
198 | - return $gateway == $this->id; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Returns a users saved tokens for this gateway. |
|
203 | - * |
|
204 | - * @since 1.0.19 |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function get_tokens( $sandbox = null ) { |
|
208 | - |
|
209 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
210 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
211 | - |
|
212 | - if ( is_array( $tokens ) ) { |
|
213 | - $this->tokens = $tokens; |
|
214 | - } |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + |
|
141 | + do_action( 'getpaid_before_init_payment_gateway_' . $this->id, $this ); |
|
142 | + |
|
143 | + // Register gateway. |
|
144 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
145 | + |
|
146 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
147 | + |
|
148 | + // Add support for various features. |
|
149 | + foreach ( $this->supports as $feature ) { |
|
150 | + add_filter( "wpinv_{$this->id}_support_{$feature}", '__return_true' ); |
|
151 | + add_filter( "getpaid_{$this->id}_support_{$feature}", '__return_true' ); |
|
152 | + add_filter( "getpaid_{$this->id}_supports_{$feature}", '__return_true' ); |
|
153 | + } |
|
154 | + |
|
155 | + // Invoice addons. |
|
156 | + if ( $this->supports( 'addons' ) ) { |
|
157 | + add_action( "getpaid_process_{$this->id}_invoice_addons", array( $this, 'process_addons' ), 10, 2 ); |
|
158 | + } |
|
159 | + |
|
160 | + // Gateway settings. |
|
161 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
162 | + |
|
163 | + // Gateway checkout fiellds. |
|
164 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
165 | + |
|
166 | + // Process payment. |
|
167 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
168 | + |
|
169 | + // Change the checkout button text. |
|
170 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
171 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
172 | + } |
|
173 | + |
|
174 | + // Check if a gateway is valid for a given currency. |
|
175 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
176 | + |
|
177 | + // Generate the transaction url. |
|
178 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
179 | + |
|
180 | + // Generate the subscription url. |
|
181 | + add_filter( 'getpaid_remote_subscription_profile_url', array( $this, 'generate_subscription_url' ), 10, 2 ); |
|
182 | + |
|
183 | + // Confirm payments. |
|
184 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
185 | + |
|
186 | + // Verify IPNs. |
|
187 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
188 | + |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Checks if this gateway is a given gateway. |
|
193 | + * |
|
194 | + * @since 1.0.19 |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function is( $gateway ) { |
|
198 | + return $gateway == $this->id; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Returns a users saved tokens for this gateway. |
|
203 | + * |
|
204 | + * @since 1.0.19 |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function get_tokens( $sandbox = null ) { |
|
208 | + |
|
209 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
210 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
211 | + |
|
212 | + if ( is_array( $tokens ) ) { |
|
213 | + $this->tokens = $tokens; |
|
214 | + } |
|
215 | 215 | } |
216 | 216 | |
217 | - if ( ! is_bool( $sandbox ) ) { |
|
218 | - return $this->tokens; |
|
219 | - } |
|
220 | - |
|
221 | - // Filter tokens. |
|
222 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
223 | - return wp_list_filter( $this->tokens, $args ); |
|
224 | - |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Saves a token for this gateway. |
|
229 | - * |
|
230 | - * @since 1.0.19 |
|
231 | - */ |
|
232 | - public function save_token( $token ) { |
|
233 | - |
|
234 | - $tokens = $this->get_tokens(); |
|
235 | - $tokens[] = $token; |
|
236 | - |
|
237 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
238 | - |
|
239 | - $this->tokens = $tokens; |
|
240 | - |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * Return the title for admin screens. |
|
245 | - * |
|
246 | - * @return string |
|
247 | - */ |
|
248 | - public function get_method_title() { |
|
249 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Return the description for admin screens. |
|
254 | - * |
|
255 | - * @return string |
|
256 | - */ |
|
257 | - public function get_method_description() { |
|
258 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
259 | - } |
|
260 | - |
|
261 | - /** |
|
262 | - * Get the success url. |
|
263 | - * |
|
264 | - * @param WPInv_Invoice $invoice Invoice object. |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function get_return_url( $invoice ) { |
|
268 | - |
|
269 | - // Payment success url |
|
270 | - $return_url = add_query_arg( |
|
271 | - array( |
|
272 | - 'payment-confirm' => $this->id, |
|
273 | - 'invoice_key' => $invoice->get_key(), |
|
274 | - 'utm_nooverride' => 1, |
|
275 | - ), |
|
276 | - wpinv_get_success_page_uri() |
|
277 | - ); |
|
278 | - |
|
279 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Confirms payments when rendering the success page. |
|
284 | - * |
|
285 | - * @param string $content Success page content. |
|
286 | - * @return string |
|
287 | - */ |
|
288 | - public function confirm_payment( $content ) { |
|
289 | - |
|
290 | - // Retrieve the invoice. |
|
291 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
292 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
293 | - |
|
294 | - // Ensure that it exists and that it is pending payment. |
|
295 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
296 | - return $content; |
|
297 | - } |
|
298 | - |
|
299 | - // Can the user view this invoice?? |
|
300 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
301 | - return $content; |
|
302 | - } |
|
303 | - |
|
304 | - // Show payment processing indicator. |
|
305 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Processes ipns and marks payments as complete. |
|
310 | - * |
|
311 | - * @return void |
|
312 | - */ |
|
313 | - public function verify_ipn() {} |
|
314 | - |
|
315 | - /** |
|
316 | - * Processes invoice addons. |
|
317 | - * |
|
318 | - * @param WPInv_Invoice $invoice |
|
319 | - * @param GetPaid_Form_Item[] $items |
|
320 | - * @return WPInv_Invoice |
|
321 | - */ |
|
322 | - public function process_addons( $invoice, $items ) { |
|
323 | - |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
328 | - * |
|
329 | - * @param string $transaction_url transaction url. |
|
330 | - * @param WPInv_Invoice $invoice Invoice object. |
|
331 | - * @return string transaction URL, or empty string. |
|
332 | - */ |
|
333 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
334 | - |
|
335 | - $transaction_id = $invoice->get_transaction_id(); |
|
336 | - |
|
337 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
338 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
339 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
340 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
341 | - } |
|
342 | - |
|
343 | - return $transaction_url; |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
348 | - * |
|
349 | - * @param string $subscription_url transaction url. |
|
350 | - * @param WPInv_Subscription $subscription Subscription objectt. |
|
351 | - * @return string subscription URL, or empty string. |
|
352 | - */ |
|
353 | - public function generate_subscription_url( $subscription_url, $subscription ) { |
|
354 | - |
|
355 | - $profile_id = $subscription->get_profile_id(); |
|
356 | - |
|
357 | - if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
358 | - |
|
359 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
360 | - $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
361 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
362 | - |
|
363 | - } |
|
364 | - |
|
365 | - return $subscription_url; |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Check if the gateway is available for use. |
|
370 | - * |
|
371 | - * @return bool |
|
372 | - */ |
|
373 | - public function is_available() { |
|
374 | - return ! empty( $this->enabled ); |
|
375 | - } |
|
376 | - |
|
377 | - /** |
|
378 | - * Return the gateway's title. |
|
379 | - * |
|
380 | - * @return string |
|
381 | - */ |
|
382 | - public function get_title() { |
|
383 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
384 | - } |
|
385 | - |
|
386 | - /** |
|
387 | - * Return the gateway's description. |
|
388 | - * |
|
389 | - * @return string |
|
390 | - */ |
|
391 | - public function get_description() { |
|
392 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Process Payment. |
|
397 | - * |
|
398 | - * |
|
399 | - * @param WPInv_Invoice $invoice Invoice. |
|
400 | - * @param array $submission_data Posted checkout fields. |
|
401 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
402 | - * @return void |
|
403 | - */ |
|
404 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
405 | - // Process the payment then either redirect to the success page or the gateway. |
|
406 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Process refund. |
|
411 | - * |
|
412 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
413 | - * a passed in amount. |
|
414 | - * |
|
415 | - * @param WPInv_Invoice $invoice Invoice. |
|
416 | - * @param float $amount Refund amount. |
|
417 | - * @param string $reason Refund reason. |
|
418 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
419 | - */ |
|
420 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
421 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
422 | - } |
|
423 | - |
|
424 | - /** |
|
425 | - * Displays the payment fields, credit cards etc. |
|
426 | - * |
|
427 | - * @param int $invoice_id 0 or invoice id. |
|
428 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
429 | - */ |
|
430 | - public function payment_fields( $invoice_id, $form ) { |
|
431 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Filters the gateway settings. |
|
436 | - * |
|
437 | - * @param array $admin_settings |
|
438 | - */ |
|
439 | - public function admin_settings( $admin_settings ) { |
|
440 | - return $admin_settings; |
|
441 | - } |
|
442 | - |
|
443 | - /** |
|
444 | - * Retrieves the value of a gateway setting. |
|
445 | - * |
|
446 | - * @param string $option |
|
447 | - */ |
|
448 | - public function get_option( $option, $default = false ) { |
|
449 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
450 | - } |
|
451 | - |
|
452 | - /** |
|
453 | - * Check if a gateway supports a given feature. |
|
454 | - * |
|
455 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
456 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
457 | - * |
|
458 | - * @param string $feature string The name of a feature to test support for. |
|
459 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
460 | - * @since 1.0.19 |
|
461 | - */ |
|
462 | - public function supports( $feature ) { |
|
463 | - return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Returns the credit card form html. |
|
468 | - * |
|
469 | - * @param bool $save whether or not to display the save button. |
|
470 | - */ |
|
217 | + if ( ! is_bool( $sandbox ) ) { |
|
218 | + return $this->tokens; |
|
219 | + } |
|
220 | + |
|
221 | + // Filter tokens. |
|
222 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
223 | + return wp_list_filter( $this->tokens, $args ); |
|
224 | + |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Saves a token for this gateway. |
|
229 | + * |
|
230 | + * @since 1.0.19 |
|
231 | + */ |
|
232 | + public function save_token( $token ) { |
|
233 | + |
|
234 | + $tokens = $this->get_tokens(); |
|
235 | + $tokens[] = $token; |
|
236 | + |
|
237 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
238 | + |
|
239 | + $this->tokens = $tokens; |
|
240 | + |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * Return the title for admin screens. |
|
245 | + * |
|
246 | + * @return string |
|
247 | + */ |
|
248 | + public function get_method_title() { |
|
249 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Return the description for admin screens. |
|
254 | + * |
|
255 | + * @return string |
|
256 | + */ |
|
257 | + public function get_method_description() { |
|
258 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
259 | + } |
|
260 | + |
|
261 | + /** |
|
262 | + * Get the success url. |
|
263 | + * |
|
264 | + * @param WPInv_Invoice $invoice Invoice object. |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function get_return_url( $invoice ) { |
|
268 | + |
|
269 | + // Payment success url |
|
270 | + $return_url = add_query_arg( |
|
271 | + array( |
|
272 | + 'payment-confirm' => $this->id, |
|
273 | + 'invoice_key' => $invoice->get_key(), |
|
274 | + 'utm_nooverride' => 1, |
|
275 | + ), |
|
276 | + wpinv_get_success_page_uri() |
|
277 | + ); |
|
278 | + |
|
279 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Confirms payments when rendering the success page. |
|
284 | + * |
|
285 | + * @param string $content Success page content. |
|
286 | + * @return string |
|
287 | + */ |
|
288 | + public function confirm_payment( $content ) { |
|
289 | + |
|
290 | + // Retrieve the invoice. |
|
291 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
292 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
293 | + |
|
294 | + // Ensure that it exists and that it is pending payment. |
|
295 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
296 | + return $content; |
|
297 | + } |
|
298 | + |
|
299 | + // Can the user view this invoice?? |
|
300 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
301 | + return $content; |
|
302 | + } |
|
303 | + |
|
304 | + // Show payment processing indicator. |
|
305 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Processes ipns and marks payments as complete. |
|
310 | + * |
|
311 | + * @return void |
|
312 | + */ |
|
313 | + public function verify_ipn() {} |
|
314 | + |
|
315 | + /** |
|
316 | + * Processes invoice addons. |
|
317 | + * |
|
318 | + * @param WPInv_Invoice $invoice |
|
319 | + * @param GetPaid_Form_Item[] $items |
|
320 | + * @return WPInv_Invoice |
|
321 | + */ |
|
322 | + public function process_addons( $invoice, $items ) { |
|
323 | + |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
328 | + * |
|
329 | + * @param string $transaction_url transaction url. |
|
330 | + * @param WPInv_Invoice $invoice Invoice object. |
|
331 | + * @return string transaction URL, or empty string. |
|
332 | + */ |
|
333 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
334 | + |
|
335 | + $transaction_id = $invoice->get_transaction_id(); |
|
336 | + |
|
337 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
338 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
339 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
340 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
341 | + } |
|
342 | + |
|
343 | + return $transaction_url; |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
348 | + * |
|
349 | + * @param string $subscription_url transaction url. |
|
350 | + * @param WPInv_Subscription $subscription Subscription objectt. |
|
351 | + * @return string subscription URL, or empty string. |
|
352 | + */ |
|
353 | + public function generate_subscription_url( $subscription_url, $subscription ) { |
|
354 | + |
|
355 | + $profile_id = $subscription->get_profile_id(); |
|
356 | + |
|
357 | + if ( $this->id == $subscription->get_gateway() && ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
358 | + |
|
359 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
360 | + $replace = $this->is_sandbox( $subscription->get_parent_invoice() ) ? 'sandbox' : ''; |
|
361 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
362 | + |
|
363 | + } |
|
364 | + |
|
365 | + return $subscription_url; |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Check if the gateway is available for use. |
|
370 | + * |
|
371 | + * @return bool |
|
372 | + */ |
|
373 | + public function is_available() { |
|
374 | + return ! empty( $this->enabled ); |
|
375 | + } |
|
376 | + |
|
377 | + /** |
|
378 | + * Return the gateway's title. |
|
379 | + * |
|
380 | + * @return string |
|
381 | + */ |
|
382 | + public function get_title() { |
|
383 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
384 | + } |
|
385 | + |
|
386 | + /** |
|
387 | + * Return the gateway's description. |
|
388 | + * |
|
389 | + * @return string |
|
390 | + */ |
|
391 | + public function get_description() { |
|
392 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Process Payment. |
|
397 | + * |
|
398 | + * |
|
399 | + * @param WPInv_Invoice $invoice Invoice. |
|
400 | + * @param array $submission_data Posted checkout fields. |
|
401 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
402 | + * @return void |
|
403 | + */ |
|
404 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
405 | + // Process the payment then either redirect to the success page or the gateway. |
|
406 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Process refund. |
|
411 | + * |
|
412 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
413 | + * a passed in amount. |
|
414 | + * |
|
415 | + * @param WPInv_Invoice $invoice Invoice. |
|
416 | + * @param float $amount Refund amount. |
|
417 | + * @param string $reason Refund reason. |
|
418 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
419 | + */ |
|
420 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
421 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
422 | + } |
|
423 | + |
|
424 | + /** |
|
425 | + * Displays the payment fields, credit cards etc. |
|
426 | + * |
|
427 | + * @param int $invoice_id 0 or invoice id. |
|
428 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
429 | + */ |
|
430 | + public function payment_fields( $invoice_id, $form ) { |
|
431 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Filters the gateway settings. |
|
436 | + * |
|
437 | + * @param array $admin_settings |
|
438 | + */ |
|
439 | + public function admin_settings( $admin_settings ) { |
|
440 | + return $admin_settings; |
|
441 | + } |
|
442 | + |
|
443 | + /** |
|
444 | + * Retrieves the value of a gateway setting. |
|
445 | + * |
|
446 | + * @param string $option |
|
447 | + */ |
|
448 | + public function get_option( $option, $default = false ) { |
|
449 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
450 | + } |
|
451 | + |
|
452 | + /** |
|
453 | + * Check if a gateway supports a given feature. |
|
454 | + * |
|
455 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
456 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
457 | + * |
|
458 | + * @param string $feature string The name of a feature to test support for. |
|
459 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
460 | + * @since 1.0.19 |
|
461 | + */ |
|
462 | + public function supports( $feature ) { |
|
463 | + return getpaid_payment_gateway_supports( $this->id, $feature ); |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Returns the credit card form html. |
|
468 | + * |
|
469 | + * @param bool $save whether or not to display the save button. |
|
470 | + */ |
|
471 | 471 | public function get_cc_form( $save = false ) { |
472 | 472 | |
473 | - ob_start(); |
|
473 | + ob_start(); |
|
474 | 474 | |
475 | 475 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
476 | 476 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | '11' => __( 'November', 'invoicing' ), |
489 | 489 | '12' => __( 'December', 'invoicing' ), |
490 | 490 | ); |
491 | - $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
491 | + $months = apply_filters( 'getpaid_cc_months', $months, $this ); |
|
492 | 492 | |
493 | 493 | $year = (int) current_time( 'Y' ); |
494 | 494 | $years = array(); |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | $years[ $year + $i ] = $year + $i; |
498 | 498 | } |
499 | 499 | |
500 | - $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
500 | + $years = apply_filters( 'getpaid_cc_years', $years, $this ); |
|
501 | 501 | |
502 | 502 | ?> |
503 | 503 | <div class="<?php echo esc_attr( $this->id ); ?>-cc-form getpaid-cc-form mt-1"> |
@@ -539,7 +539,7 @@ discard block |
||
539 | 539 | |
540 | 540 | <?php |
541 | 541 | foreach ( $months as $key => $month ) { |
542 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
542 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $month ) . '</option>'; |
|
543 | 543 | } |
544 | 544 | ?> |
545 | 545 | |
@@ -552,7 +552,7 @@ discard block |
||
552 | 552 | |
553 | 553 | <?php |
554 | 554 | foreach ( $years as $key => $year ) { |
555 | - echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
555 | + echo "<option value='" . esc_attr( $key ) . "'>" . esc_html( $year ) . '</option>'; |
|
556 | 556 | } |
557 | 557 | ?> |
558 | 558 | |
@@ -570,13 +570,13 @@ discard block |
||
570 | 570 | 'name' => $this->id . '[cc_cvv2]', |
571 | 571 | 'id' => "$id_prefix-cc-cvv2", |
572 | 572 | 'label' => __( 'CCV', 'invoicing' ), |
573 | - 'label_type' => 'vertical', |
|
574 | - 'class' => 'form-control-sm', |
|
575 | - 'extra_attributes' => array( |
|
576 | - 'autocomplete' => 'cc-csc', |
|
577 | - ), |
|
573 | + 'label_type' => 'vertical', |
|
574 | + 'class' => 'form-control-sm', |
|
575 | + 'extra_attributes' => array( |
|
576 | + 'autocomplete' => 'cc-csc', |
|
577 | + ), |
|
578 | 578 | ), |
579 | - true |
|
579 | + true |
|
580 | 580 | ); |
581 | 581 | ?> |
582 | 582 | </div> |
@@ -585,192 +585,192 @@ discard block |
||
585 | 585 | |
586 | 586 | <?php |
587 | 587 | |
588 | - if ( $save ) { |
|
589 | - $this->save_payment_method_checkbox(); |
|
590 | - } |
|
588 | + if ( $save ) { |
|
589 | + $this->save_payment_method_checkbox(); |
|
590 | + } |
|
591 | 591 | |
592 | - ?> |
|
592 | + ?> |
|
593 | 593 | </div> |
594 | 594 | |
595 | 595 | </div> |
596 | 596 | <?php |
597 | 597 | |
598 | - return ob_get_clean(); |
|
598 | + return ob_get_clean(); |
|
599 | + |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * Displays a new payment method entry form. |
|
604 | + * |
|
605 | + * @since 1.0.19 |
|
606 | + */ |
|
607 | + public function new_payment_method_entry( $form ) { |
|
608 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
609 | + } |
|
610 | + |
|
611 | + /** |
|
612 | + * Grab and display our saved payment methods. |
|
613 | + * |
|
614 | + * @since 1.0.19 |
|
615 | + */ |
|
616 | + public function saved_payment_methods() { |
|
617 | + echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
618 | + |
|
619 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
620 | + $this->get_saved_payment_method_option_html( $token ); |
|
621 | + } |
|
622 | + |
|
623 | + $this->get_new_payment_method_option_html(); |
|
624 | + echo '</ul>'; |
|
599 | 625 | |
600 | 626 | } |
601 | 627 | |
602 | - /** |
|
603 | - * Displays a new payment method entry form. |
|
604 | - * |
|
605 | - * @since 1.0.19 |
|
606 | - */ |
|
607 | - public function new_payment_method_entry( $form ) { |
|
608 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'> " . wp_kses( $form, getpaid_allowed_html() ) . '</div>'; |
|
609 | - } |
|
610 | - |
|
611 | - /** |
|
612 | - * Grab and display our saved payment methods. |
|
613 | - * |
|
614 | - * @since 1.0.19 |
|
615 | - */ |
|
616 | - public function saved_payment_methods() { |
|
617 | - echo '<ul class="getpaid-saved-payment-methods list-unstyled m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
618 | - |
|
619 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
620 | - $this->get_saved_payment_method_option_html( $token ); |
|
621 | - } |
|
622 | - |
|
623 | - $this->get_new_payment_method_option_html(); |
|
624 | - echo '</ul>'; |
|
625 | - |
|
626 | - } |
|
627 | - |
|
628 | - /** |
|
629 | - * Gets saved payment method HTML from a token. |
|
630 | - * |
|
631 | - * @since 1.0.19 |
|
632 | - * @param array $token Payment Token. |
|
633 | - * @return string Generated payment method HTML |
|
634 | - */ |
|
635 | - public function get_saved_payment_method_option_html( $token ) { |
|
636 | - |
|
637 | - printf( |
|
638 | - '<li class="getpaid-payment-method form-group mb-3"> |
|
628 | + /** |
|
629 | + * Gets saved payment method HTML from a token. |
|
630 | + * |
|
631 | + * @since 1.0.19 |
|
632 | + * @param array $token Payment Token. |
|
633 | + * @return string Generated payment method HTML |
|
634 | + */ |
|
635 | + public function get_saved_payment_method_option_html( $token ) { |
|
636 | + |
|
637 | + printf( |
|
638 | + '<li class="getpaid-payment-method form-group mb-3"> |
|
639 | 639 | <label> |
640 | 640 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" data-currency="%5$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
641 | 641 | <span>%3$s</span> |
642 | 642 | </label> |
643 | 643 | </li>', |
644 | - esc_attr( $this->id ), |
|
645 | - esc_attr( $token['id'] ), |
|
646 | - esc_html( $token['name'] ), |
|
647 | - checked( empty( $token['default'] ), false, false ), |
|
648 | - empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
649 | - ); |
|
650 | - |
|
651 | - } |
|
652 | - |
|
653 | - /** |
|
654 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
655 | - * |
|
656 | - * @since 1.0.19 |
|
657 | - */ |
|
658 | - public function get_new_payment_method_option_html() { |
|
659 | - |
|
660 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
661 | - |
|
662 | - printf( |
|
663 | - '<li class="getpaid-new-payment-method"> |
|
644 | + esc_attr( $this->id ), |
|
645 | + esc_attr( $token['id'] ), |
|
646 | + esc_html( $token['name'] ), |
|
647 | + checked( empty( $token['default'] ), false, false ), |
|
648 | + empty( $token['currency'] ) ? 'none' : esc_attr( $token['currency'] ) |
|
649 | + ); |
|
650 | + |
|
651 | + } |
|
652 | + |
|
653 | + /** |
|
654 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
655 | + * |
|
656 | + * @since 1.0.19 |
|
657 | + */ |
|
658 | + public function get_new_payment_method_option_html() { |
|
659 | + |
|
660 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
661 | + |
|
662 | + printf( |
|
663 | + '<li class="getpaid-new-payment-method"> |
|
664 | 664 | <label> |
665 | 665 | <input name="getpaid-%1$s-payment-method" type="radio" data-currency="none" value="new" style="width:auto;" /> |
666 | 666 | <span>%2$s</span> |
667 | 667 | </label> |
668 | 668 | </li>', |
669 | - esc_attr( $this->id ), |
|
670 | - esc_html( $label ) |
|
671 | - ); |
|
672 | - |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Outputs a checkbox for saving a new payment method to the database. |
|
677 | - * |
|
678 | - * @since 1.0.19 |
|
679 | - */ |
|
680 | - public function save_payment_method_checkbox() { |
|
681 | - |
|
682 | - aui()->input( |
|
683 | - array( |
|
684 | - 'type' => 'checkbox', |
|
685 | - 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
686 | - 'id' => esc_attr( uniqid( $this->id ) ), |
|
687 | - 'required' => false, |
|
688 | - 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
689 | - 'value' => 'true', |
|
690 | - 'checked' => true, |
|
691 | - 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
692 | - ), |
|
693 | - true |
|
694 | - ); |
|
695 | - |
|
696 | - } |
|
697 | - |
|
698 | - /** |
|
699 | - * Registers the gateway. |
|
700 | - * |
|
701 | - * @return array |
|
702 | - */ |
|
703 | - public function register_gateway( $gateways ) { |
|
704 | - |
|
705 | - $gateways[ $this->id ] = array( |
|
706 | - |
|
707 | - 'admin_label' => $this->method_title, |
|
669 | + esc_attr( $this->id ), |
|
670 | + esc_html( $label ) |
|
671 | + ); |
|
672 | + |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Outputs a checkbox for saving a new payment method to the database. |
|
677 | + * |
|
678 | + * @since 1.0.19 |
|
679 | + */ |
|
680 | + public function save_payment_method_checkbox() { |
|
681 | + |
|
682 | + aui()->input( |
|
683 | + array( |
|
684 | + 'type' => 'checkbox', |
|
685 | + 'name' => esc_attr( "getpaid-$this->id-new-payment-method" ), |
|
686 | + 'id' => esc_attr( uniqid( $this->id ) ), |
|
687 | + 'required' => false, |
|
688 | + 'label' => esc_html__( 'Save payment method', 'invoicing' ), |
|
689 | + 'value' => 'true', |
|
690 | + 'checked' => true, |
|
691 | + 'wrap_class' => 'getpaid-save-payment-method pt-1 pb-1', |
|
692 | + ), |
|
693 | + true |
|
694 | + ); |
|
695 | + |
|
696 | + } |
|
697 | + |
|
698 | + /** |
|
699 | + * Registers the gateway. |
|
700 | + * |
|
701 | + * @return array |
|
702 | + */ |
|
703 | + public function register_gateway( $gateways ) { |
|
704 | + |
|
705 | + $gateways[ $this->id ] = array( |
|
706 | + |
|
707 | + 'admin_label' => $this->method_title, |
|
708 | 708 | 'checkout_label' => $this->title, |
709 | - 'ordering' => $this->order, |
|
709 | + 'ordering' => $this->order, |
|
710 | 710 | |
711 | - ); |
|
711 | + ); |
|
712 | 712 | |
713 | - return $gateways; |
|
713 | + return $gateways; |
|
714 | 714 | |
715 | - } |
|
715 | + } |
|
716 | 716 | |
717 | - /** |
|
718 | - * Checks whether or not this is a sandbox request. |
|
719 | - * |
|
720 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
721 | - * @return bool |
|
722 | - */ |
|
723 | - public function is_sandbox( $invoice = null ) { |
|
717 | + /** |
|
718 | + * Checks whether or not this is a sandbox request. |
|
719 | + * |
|
720 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
721 | + * @return bool |
|
722 | + */ |
|
723 | + public function is_sandbox( $invoice = null ) { |
|
724 | 724 | |
725 | - if ( is_a( $invoice, 'WPInv_Invoice' ) && ! $invoice->needs_payment() ) { |
|
726 | - return $invoice->get_mode() === 'test'; |
|
727 | - } |
|
725 | + if ( is_a( $invoice, 'WPInv_Invoice' ) && ! $invoice->needs_payment() ) { |
|
726 | + return $invoice->get_mode() === 'test'; |
|
727 | + } |
|
728 | 728 | |
729 | - return wpinv_is_test_mode( $this->id ); |
|
729 | + return wpinv_is_test_mode( $this->id ); |
|
730 | 730 | |
731 | - } |
|
731 | + } |
|
732 | 732 | |
733 | - /** |
|
734 | - * Renames the checkout button |
|
735 | - * |
|
736 | - * @return string |
|
737 | - */ |
|
738 | - public function rename_checkout_button() { |
|
739 | - return $this->checkout_button_text; |
|
740 | - } |
|
733 | + /** |
|
734 | + * Renames the checkout button |
|
735 | + * |
|
736 | + * @return string |
|
737 | + */ |
|
738 | + public function rename_checkout_button() { |
|
739 | + return $this->checkout_button_text; |
|
740 | + } |
|
741 | 741 | |
742 | - /** |
|
743 | - * Validate gateway currency |
|
744 | - * |
|
745 | - * @return bool |
|
746 | - */ |
|
747 | - public function validate_currency( $validation, $currency ) { |
|
742 | + /** |
|
743 | + * Validate gateway currency |
|
744 | + * |
|
745 | + * @return bool |
|
746 | + */ |
|
747 | + public function validate_currency( $validation, $currency ) { |
|
748 | 748 | |
749 | - // Required currencies. |
|
750 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
751 | - return false; |
|
752 | - } |
|
749 | + // Required currencies. |
|
750 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
751 | + return false; |
|
752 | + } |
|
753 | 753 | |
754 | - // Excluded currencies. |
|
755 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
756 | - return false; |
|
757 | - } |
|
754 | + // Excluded currencies. |
|
755 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
756 | + return false; |
|
757 | + } |
|
758 | 758 | |
759 | - return $validation; |
|
760 | - } |
|
759 | + return $validation; |
|
760 | + } |
|
761 | 761 | |
762 | - /** |
|
763 | - * Displays an error |
|
764 | - * |
|
765 | - */ |
|
766 | - public function show_error( $code, $message, $type ) { |
|
762 | + /** |
|
763 | + * Displays an error |
|
764 | + * |
|
765 | + */ |
|
766 | + public function show_error( $code, $message, $type ) { |
|
767 | 767 | |
768 | - if ( is_admin() ) { |
|
769 | - getpaid_admin()->{"show_$type"}( $message ); |
|
770 | - } |
|
768 | + if ( is_admin() ) { |
|
769 | + getpaid_admin()->{"show_$type"}( $message ); |
|
770 | + } |
|
771 | 771 | |
772 | - wpinv_set_error( $code, $message, $type ); |
|
772 | + wpinv_set_error( $code, $message, $type ); |
|
773 | 773 | |
774 | - } |
|
774 | + } |
|
775 | 775 | |
776 | 776 | } |