@@ -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,77 +11,77 @@ 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; |
|
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 | - ); |
|
36 | - |
|
37 | - /** |
|
38 | - * Parse incoming $args into an array and merge it with $defaults |
|
39 | - */ |
|
40 | - $args = wp_parse_args( $args, $defaults ); |
|
41 | - |
|
42 | - $output = ''; |
|
43 | - |
|
44 | - // Don't print empty markup if there's only one page. |
|
45 | - if ( $args['total'] > 1 ) { |
|
46 | - |
|
47 | - // Set up paginated links. |
|
48 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | - |
|
50 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | - |
|
52 | - // make the output bootstrap ready |
|
53 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | - if ( ! empty( $links ) ) { |
|
55 | - foreach ( $links as $link ) { |
|
56 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | - $links_html .= "<li class='page-item $active'>"; |
|
58 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | - $links_html .= "</li>"; |
|
60 | - } |
|
61 | - } |
|
62 | - $links_html .= "</ul>"; |
|
63 | - |
|
64 | - if ( $links ) { |
|
65 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | - $output .= '</section>'; |
|
68 | - } |
|
69 | - |
|
70 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | - } |
|
73 | - |
|
74 | - if ( $output ) { |
|
75 | - if ( ! empty( $args['before_paging'] ) ) { |
|
76 | - $output = $args['before_paging'] . $output; |
|
77 | - } |
|
78 | - |
|
79 | - if ( ! empty( $args['after_paging'] ) ) { |
|
80 | - $output = $output . $args['after_paging']; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - return $output; |
|
85 | - } |
|
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; |
|
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 | + ); |
|
36 | + |
|
37 | + /** |
|
38 | + * Parse incoming $args into an array and merge it with $defaults |
|
39 | + */ |
|
40 | + $args = wp_parse_args( $args, $defaults ); |
|
41 | + |
|
42 | + $output = ''; |
|
43 | + |
|
44 | + // Don't print empty markup if there's only one page. |
|
45 | + if ( $args['total'] > 1 ) { |
|
46 | + |
|
47 | + // Set up paginated links. |
|
48 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
49 | + |
|
50 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
51 | + |
|
52 | + // make the output bootstrap ready |
|
53 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
54 | + if ( ! empty( $links ) ) { |
|
55 | + foreach ( $links as $link ) { |
|
56 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
57 | + $links_html .= "<li class='page-item $active'>"; |
|
58 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
59 | + $links_html .= "</li>"; |
|
60 | + } |
|
61 | + } |
|
62 | + $links_html .= "</ul>"; |
|
63 | + |
|
64 | + if ( $links ) { |
|
65 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
66 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
67 | + $output .= '</section>'; |
|
68 | + } |
|
69 | + |
|
70 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
71 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
72 | + } |
|
73 | + |
|
74 | + if ( $output ) { |
|
75 | + if ( ! empty( $args['before_paging'] ) ) { |
|
76 | + $output = $args['before_paging'] . $output; |
|
77 | + } |
|
78 | + |
|
79 | + if ( ! empty( $args['after_paging'] ) ) { |
|
80 | + $output = $output . $args['after_paging']; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + return $output; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | } |
88 | 88 | \ 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,249 +11,249 @@ 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 | - * |
|
19 | - * @return string |
|
20 | - */ |
|
21 | - public static function name($text,$multiple = false){ |
|
22 | - $output = ''; |
|
23 | - |
|
24 | - if($text){ |
|
25 | - $is_multiple = strpos($text, '[]') !== false || (strpos($text, '[]') === false && $multiple ) ? '[]' : ''; |
|
26 | - $output = ' name="'.sanitize_html_class($text).$is_multiple.'" '; |
|
27 | - } |
|
28 | - |
|
29 | - return $output; |
|
30 | - } |
|
31 | - |
|
32 | - /** |
|
33 | - * A component helper for generating a item id. |
|
34 | - * |
|
35 | - * @param $text string The text to be used as the value. |
|
36 | - * |
|
37 | - * @return string The sanitized item. |
|
38 | - */ |
|
39 | - public static function id($text){ |
|
40 | - $output = ''; |
|
41 | - |
|
42 | - if($text){ |
|
43 | - $output = ' id="'.sanitize_html_class($text).'" '; |
|
44 | - } |
|
45 | - |
|
46 | - return $output; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * A component helper for generating a item title. |
|
51 | - * |
|
52 | - * @param $text string The text to be used as the value. |
|
53 | - * |
|
54 | - * @return string The sanitized item. |
|
55 | - */ |
|
56 | - public static function title($text){ |
|
57 | - $output = ''; |
|
58 | - |
|
59 | - if($text){ |
|
60 | - $output = ' title="'.esc_attr($text).'" '; |
|
61 | - } |
|
62 | - |
|
63 | - return $output; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * A component helper for generating a item value. |
|
68 | - * |
|
69 | - * @param $text string The text to be used as the value. |
|
70 | - * |
|
71 | - * @return string The sanitized item. |
|
72 | - */ |
|
73 | - public static function value($text){ |
|
74 | - $output = ''; |
|
75 | - |
|
76 | - if($text){ |
|
77 | - $output = ' value="'.sanitize_text_field($text).'" '; |
|
78 | - } |
|
79 | - |
|
80 | - return $output; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * A component helper for generating a item class attribute. |
|
85 | - * |
|
86 | - * @param $text string The text to be used as the value. |
|
87 | - * |
|
88 | - * @return string The sanitized item. |
|
89 | - */ |
|
90 | - public static function class_attr($text){ |
|
91 | - $output = ''; |
|
92 | - |
|
93 | - if($text){ |
|
94 | - $classes = self::esc_classes($text); |
|
95 | - if(!empty($classes)){ |
|
96 | - $output = ' class="'.$classes.'" '; |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - return $output; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Escape a string of classes. |
|
105 | - * |
|
106 | - * @param $text |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public static function esc_classes($text){ |
|
111 | - $output = ''; |
|
112 | - |
|
113 | - if($text){ |
|
114 | - $classes = explode(" ",$text); |
|
115 | - $classes = array_map("trim",$classes); |
|
116 | - $classes = array_map("sanitize_html_class",$classes); |
|
117 | - if(!empty($classes)){ |
|
118 | - $output = implode(" ",$classes); |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - return $output; |
|
123 | - |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @param $args |
|
128 | - * |
|
129 | - * @return string |
|
130 | - */ |
|
131 | - public static function data_attributes($args){ |
|
132 | - $output = ''; |
|
133 | - |
|
134 | - if(!empty($args)){ |
|
135 | - |
|
136 | - foreach($args as $key => $val){ |
|
137 | - if(substr( $key, 0, 5 ) === "data-"){ |
|
138 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
139 | - } |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - return $output; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param $args |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public static function aria_attributes($args){ |
|
152 | - $output = ''; |
|
153 | - |
|
154 | - if(!empty($args)){ |
|
155 | - |
|
156 | - foreach($args as $key => $val){ |
|
157 | - if(substr( $key, 0, 5 ) === "aria-"){ |
|
158 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
159 | - } |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - return $output; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Build a font awesome icon from a class. |
|
168 | - * |
|
169 | - * @param $class |
|
170 | - * @param bool $space_after |
|
171 | - * @param array $extra_attributes An array of extra attributes. |
|
172 | - * |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
176 | - $output = ''; |
|
177 | - |
|
178 | - if($class){ |
|
179 | - $classes = self::esc_classes($class); |
|
180 | - if(!empty($classes)){ |
|
181 | - $output = '<i class="'.$classes.'" '; |
|
182 | - // extra attributes |
|
183 | - if(!empty($extra_attributes)){ |
|
184 | - $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
185 | - } |
|
186 | - $output .= '></i>'; |
|
187 | - if($space_after){ |
|
188 | - $output .= " "; |
|
189 | - } |
|
190 | - } |
|
191 | - } |
|
192 | - |
|
193 | - return $output; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param $args |
|
198 | - * |
|
199 | - * @return string |
|
200 | - */ |
|
201 | - public static function extra_attributes($args){ |
|
202 | - $output = ''; |
|
203 | - |
|
204 | - if(!empty($args)){ |
|
205 | - |
|
206 | - if( is_array($args) ){ |
|
207 | - foreach($args as $key => $val){ |
|
208 | - $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
209 | - } |
|
210 | - }else{ |
|
211 | - $output .= ' '.$args.' '; |
|
212 | - } |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - return $output; |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * @param $args |
|
221 | - * |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public static function help_text($text){ |
|
225 | - $output = ''; |
|
226 | - |
|
227 | - if($text){ |
|
228 | - $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - return $output; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Replace element require context with JS. |
|
237 | - * |
|
238 | - * @param $input |
|
239 | - * |
|
240 | - * @return string|void |
|
241 | - */ |
|
242 | - public static function element_require( $input ) { |
|
243 | - |
|
244 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
245 | - |
|
246 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
247 | - "jQuery(form).find('[data-argument=\"", |
|
248 | - "\"]').find('input,select,textarea').val()", |
|
249 | - "\"]').find('input:checked').val()", |
|
250 | - ), $input ) ); |
|
251 | - |
|
252 | - if($output){ |
|
253 | - $output = ' data-element-require="'.$output.'" '; |
|
254 | - } |
|
255 | - |
|
256 | - return $output; |
|
257 | - } |
|
14 | + /** |
|
15 | + * A component helper for generating a input name. |
|
16 | + * |
|
17 | + * @param $text |
|
18 | + * |
|
19 | + * @return string |
|
20 | + */ |
|
21 | + public static function name($text,$multiple = false){ |
|
22 | + $output = ''; |
|
23 | + |
|
24 | + if($text){ |
|
25 | + $is_multiple = strpos($text, '[]') !== false || (strpos($text, '[]') === false && $multiple ) ? '[]' : ''; |
|
26 | + $output = ' name="'.sanitize_html_class($text).$is_multiple.'" '; |
|
27 | + } |
|
28 | + |
|
29 | + return $output; |
|
30 | + } |
|
31 | + |
|
32 | + /** |
|
33 | + * A component helper for generating a item id. |
|
34 | + * |
|
35 | + * @param $text string The text to be used as the value. |
|
36 | + * |
|
37 | + * @return string The sanitized item. |
|
38 | + */ |
|
39 | + public static function id($text){ |
|
40 | + $output = ''; |
|
41 | + |
|
42 | + if($text){ |
|
43 | + $output = ' id="'.sanitize_html_class($text).'" '; |
|
44 | + } |
|
45 | + |
|
46 | + return $output; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * A component helper for generating a item title. |
|
51 | + * |
|
52 | + * @param $text string The text to be used as the value. |
|
53 | + * |
|
54 | + * @return string The sanitized item. |
|
55 | + */ |
|
56 | + public static function title($text){ |
|
57 | + $output = ''; |
|
58 | + |
|
59 | + if($text){ |
|
60 | + $output = ' title="'.esc_attr($text).'" '; |
|
61 | + } |
|
62 | + |
|
63 | + return $output; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * A component helper for generating a item value. |
|
68 | + * |
|
69 | + * @param $text string The text to be used as the value. |
|
70 | + * |
|
71 | + * @return string The sanitized item. |
|
72 | + */ |
|
73 | + public static function value($text){ |
|
74 | + $output = ''; |
|
75 | + |
|
76 | + if($text){ |
|
77 | + $output = ' value="'.sanitize_text_field($text).'" '; |
|
78 | + } |
|
79 | + |
|
80 | + return $output; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * A component helper for generating a item class attribute. |
|
85 | + * |
|
86 | + * @param $text string The text to be used as the value. |
|
87 | + * |
|
88 | + * @return string The sanitized item. |
|
89 | + */ |
|
90 | + public static function class_attr($text){ |
|
91 | + $output = ''; |
|
92 | + |
|
93 | + if($text){ |
|
94 | + $classes = self::esc_classes($text); |
|
95 | + if(!empty($classes)){ |
|
96 | + $output = ' class="'.$classes.'" '; |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + return $output; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Escape a string of classes. |
|
105 | + * |
|
106 | + * @param $text |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public static function esc_classes($text){ |
|
111 | + $output = ''; |
|
112 | + |
|
113 | + if($text){ |
|
114 | + $classes = explode(" ",$text); |
|
115 | + $classes = array_map("trim",$classes); |
|
116 | + $classes = array_map("sanitize_html_class",$classes); |
|
117 | + if(!empty($classes)){ |
|
118 | + $output = implode(" ",$classes); |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + return $output; |
|
123 | + |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @param $args |
|
128 | + * |
|
129 | + * @return string |
|
130 | + */ |
|
131 | + public static function data_attributes($args){ |
|
132 | + $output = ''; |
|
133 | + |
|
134 | + if(!empty($args)){ |
|
135 | + |
|
136 | + foreach($args as $key => $val){ |
|
137 | + if(substr( $key, 0, 5 ) === "data-"){ |
|
138 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
139 | + } |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + return $output; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param $args |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public static function aria_attributes($args){ |
|
152 | + $output = ''; |
|
153 | + |
|
154 | + if(!empty($args)){ |
|
155 | + |
|
156 | + foreach($args as $key => $val){ |
|
157 | + if(substr( $key, 0, 5 ) === "aria-"){ |
|
158 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
159 | + } |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + return $output; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Build a font awesome icon from a class. |
|
168 | + * |
|
169 | + * @param $class |
|
170 | + * @param bool $space_after |
|
171 | + * @param array $extra_attributes An array of extra attributes. |
|
172 | + * |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public static function icon($class,$space_after = false, $extra_attributes = array()){ |
|
176 | + $output = ''; |
|
177 | + |
|
178 | + if($class){ |
|
179 | + $classes = self::esc_classes($class); |
|
180 | + if(!empty($classes)){ |
|
181 | + $output = '<i class="'.$classes.'" '; |
|
182 | + // extra attributes |
|
183 | + if(!empty($extra_attributes)){ |
|
184 | + $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
185 | + } |
|
186 | + $output .= '></i>'; |
|
187 | + if($space_after){ |
|
188 | + $output .= " "; |
|
189 | + } |
|
190 | + } |
|
191 | + } |
|
192 | + |
|
193 | + return $output; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param $args |
|
198 | + * |
|
199 | + * @return string |
|
200 | + */ |
|
201 | + public static function extra_attributes($args){ |
|
202 | + $output = ''; |
|
203 | + |
|
204 | + if(!empty($args)){ |
|
205 | + |
|
206 | + if( is_array($args) ){ |
|
207 | + foreach($args as $key => $val){ |
|
208 | + $output .= ' '.sanitize_html_class($key).'="'.esc_attr($val).'" '; |
|
209 | + } |
|
210 | + }else{ |
|
211 | + $output .= ' '.$args.' '; |
|
212 | + } |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + return $output; |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * @param $args |
|
221 | + * |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + public static function help_text($text){ |
|
225 | + $output = ''; |
|
226 | + |
|
227 | + if($text){ |
|
228 | + $output .= '<small class="form-text text-muted">'.wp_kses_post($text).'</small>'; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + return $output; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Replace element require context with JS. |
|
237 | + * |
|
238 | + * @param $input |
|
239 | + * |
|
240 | + * @return string|void |
|
241 | + */ |
|
242 | + public static function element_require( $input ) { |
|
243 | + |
|
244 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
245 | + |
|
246 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
247 | + "jQuery(form).find('[data-argument=\"", |
|
248 | + "\"]').find('input,select,textarea').val()", |
|
249 | + "\"]').find('input:checked').val()", |
|
250 | + ), $input ) ); |
|
251 | + |
|
252 | + if($output){ |
|
253 | + $output = ' data-element-require="'.$output.'" '; |
|
254 | + } |
|
255 | + |
|
256 | + return $output; |
|
257 | + } |
|
258 | 258 | |
259 | 259 | } |
260 | 260 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wpinv_subscriptions_page() { |
16 | 16 | |
17 | - ?> |
|
17 | + ?> |
|
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | - // Verify user permissions. |
|
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
25 | + // Verify user permissions. |
|
26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
27 | 27 | |
28 | - echo aui()->alert( |
|
29 | - array( |
|
30 | - 'type' => 'danger', |
|
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | - ) |
|
33 | - ); |
|
28 | + echo aui()->alert( |
|
29 | + array( |
|
30 | + 'type' => 'danger', |
|
31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | + ) |
|
33 | + ); |
|
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
36 | 36 | |
37 | - // Display a single subscription. |
|
38 | - wpinv_recurring_subscription_details(); |
|
39 | - } else { |
|
37 | + // Display a single subscription. |
|
38 | + wpinv_recurring_subscription_details(); |
|
39 | + } else { |
|
40 | 40 | |
41 | - // Display a list of available subscriptions. |
|
42 | - getpaid_print_subscriptions_list(); |
|
43 | - } |
|
41 | + // Display a list of available subscriptions. |
|
42 | + getpaid_print_subscriptions_list(); |
|
43 | + } |
|
44 | 44 | |
45 | - ?> |
|
45 | + ?> |
|
46 | 46 | |
47 | 47 | </div> |
48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | */ |
60 | 60 | function getpaid_print_subscriptions_list() { |
61 | 61 | |
62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | - $subscribers_table->prepare_items(); |
|
62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | + $subscribers_table->prepare_items(); |
|
64 | 64 | |
65 | - ?> |
|
65 | + ?> |
|
66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,27 +80,27 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function wpinv_recurring_subscription_details() { |
82 | 82 | |
83 | - // Fetch the subscription. |
|
84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | - if ( ! $sub->get_id() ) { |
|
83 | + // Fetch the subscription. |
|
84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | + if ( ! $sub->get_id() ) { |
|
86 | 86 | |
87 | - echo aui()->alert( |
|
88 | - array( |
|
89 | - 'type' => 'danger', |
|
90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
91 | - ) |
|
92 | - ); |
|
87 | + echo aui()->alert( |
|
88 | + array( |
|
89 | + 'type' => 'danger', |
|
90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
91 | + ) |
|
92 | + ); |
|
93 | 93 | |
94 | - return; |
|
95 | - } |
|
94 | + return; |
|
95 | + } |
|
96 | 96 | |
97 | - // Use metaboxes to display the subscription details. |
|
98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
101 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
97 | + // Use metaboxes to display the subscription details. |
|
98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal' ); |
|
99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
101 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
102 | 102 | |
103 | - ?> |
|
103 | + ?> |
|
104 | 104 | |
105 | 105 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
106 | 106 | |
@@ -140,41 +140,41 @@ discard block |
||
140 | 140 | */ |
141 | 141 | function getpaid_admin_subscription_details_metabox( $sub ) { |
142 | 142 | |
143 | - // Prepare subscription detail columns. |
|
144 | - $fields = apply_filters( |
|
145 | - 'getpaid_subscription_admin_page_fields', |
|
146 | - array( |
|
147 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
148 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
149 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
150 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
151 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
152 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
153 | - 'item' => __( 'Item', 'invoicing' ), |
|
154 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
155 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
156 | - 'status' => __( 'Status', 'invoicing' ), |
|
157 | - ) |
|
158 | - ); |
|
159 | - |
|
160 | - if ( ! $sub->is_active() ) { |
|
161 | - |
|
162 | - if ( isset( $fields['renews_on'] ) ) { |
|
163 | - unset( $fields['renews_on'] ); |
|
164 | - } |
|
165 | - |
|
166 | - if ( isset( $fields['gateway'] ) ) { |
|
167 | - unset( $fields['gateway'] ); |
|
168 | - } |
|
143 | + // Prepare subscription detail columns. |
|
144 | + $fields = apply_filters( |
|
145 | + 'getpaid_subscription_admin_page_fields', |
|
146 | + array( |
|
147 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
148 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
149 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
150 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
151 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
152 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
153 | + 'item' => __( 'Item', 'invoicing' ), |
|
154 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
155 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
156 | + 'status' => __( 'Status', 'invoicing' ), |
|
157 | + ) |
|
158 | + ); |
|
159 | + |
|
160 | + if ( ! $sub->is_active() ) { |
|
161 | + |
|
162 | + if ( isset( $fields['renews_on'] ) ) { |
|
163 | + unset( $fields['renews_on'] ); |
|
164 | + } |
|
165 | + |
|
166 | + if ( isset( $fields['gateway'] ) ) { |
|
167 | + unset( $fields['gateway'] ); |
|
168 | + } |
|
169 | 169 | |
170 | - } |
|
170 | + } |
|
171 | 171 | |
172 | - $profile_id = $sub->get_profile_id(); |
|
173 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
174 | - unset( $fields['profile_id'] ); |
|
175 | - } |
|
172 | + $profile_id = $sub->get_profile_id(); |
|
173 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
174 | + unset( $fields['profile_id'] ); |
|
175 | + } |
|
176 | 176 | |
177 | - ?> |
|
177 | + ?> |
|
178 | 178 | |
179 | 179 | <table class="table table-borderless" style="font-size: 14px;"> |
180 | 180 | <tbody> |
@@ -208,20 +208,20 @@ discard block |
||
208 | 208 | */ |
209 | 209 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
210 | 210 | |
211 | - $username = __( '(Missing User)', 'invoicing' ); |
|
211 | + $username = __( '(Missing User)', 'invoicing' ); |
|
212 | 212 | |
213 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
214 | - if ( $user ) { |
|
213 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
214 | + if ( $user ) { |
|
215 | 215 | |
216 | - $username = sprintf( |
|
217 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
218 | - absint( $user->ID ), |
|
219 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
220 | - ); |
|
216 | + $username = sprintf( |
|
217 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
218 | + absint( $user->ID ), |
|
219 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
220 | + ); |
|
221 | 221 | |
222 | - } |
|
222 | + } |
|
223 | 223 | |
224 | - echo $username; |
|
224 | + echo $username; |
|
225 | 225 | } |
226 | 226 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
227 | 227 | |
@@ -231,8 +231,8 @@ discard block |
||
231 | 231 | * @param WPInv_Subscription $subscription |
232 | 232 | */ |
233 | 233 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
234 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
235 | - echo "<span>$amount</span>"; |
|
234 | + $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
235 | + echo "<span>$amount</span>"; |
|
236 | 236 | } |
237 | 237 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
238 | 238 | |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | * @param WPInv_Subscription $subscription |
243 | 243 | */ |
244 | 244 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
245 | - echo '#' . absint( $subscription->get_id() ); |
|
245 | + echo '#' . absint( $subscription->get_id() ); |
|
246 | 246 | } |
247 | 247 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
248 | 248 | |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | * @param WPInv_Subscription $subscription |
253 | 253 | */ |
254 | 254 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
255 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
255 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
256 | 256 | } |
257 | 257 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
258 | 258 | |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | * @param WPInv_Subscription $subscription |
263 | 263 | */ |
264 | 264 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
265 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
265 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
266 | 266 | } |
267 | 267 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
268 | 268 | |
@@ -272,8 +272,8 @@ discard block |
||
272 | 272 | * @param WPInv_Subscription $subscription |
273 | 273 | */ |
274 | 274 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
275 | - $max_bills = $subscription->get_bill_times(); |
|
276 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
275 | + $max_bills = $subscription->get_bill_times(); |
|
276 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
277 | 277 | } |
278 | 278 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
279 | 279 | /** |
@@ -283,16 +283,16 @@ discard block |
||
283 | 283 | */ |
284 | 284 | function getpaid_admin_subscription_metabox_display_item( $subscription ) { |
285 | 285 | |
286 | - $item = get_post( $subscription->get_product_id() ); |
|
286 | + $item = get_post( $subscription->get_product_id() ); |
|
287 | 287 | |
288 | - if ( ! empty( $item ) ) { |
|
289 | - $link = get_edit_post_link( $item ); |
|
290 | - $link = esc_url( $link ); |
|
291 | - $name = esc_html( get_the_title( $item ) ); |
|
292 | - echo "<a href='$link'>$name</a>"; |
|
293 | - } else { |
|
294 | - echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
295 | - } |
|
288 | + if ( ! empty( $item ) ) { |
|
289 | + $link = get_edit_post_link( $item ); |
|
290 | + $link = esc_url( $link ); |
|
291 | + $name = esc_html( get_the_title( $item ) ); |
|
292 | + echo "<a href='$link'>$name</a>"; |
|
293 | + } else { |
|
294 | + echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() ); |
|
295 | + } |
|
296 | 296 | |
297 | 297 | } |
298 | 298 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' ); |
@@ -304,13 +304,13 @@ discard block |
||
304 | 304 | */ |
305 | 305 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
306 | 306 | |
307 | - $gateway = $subscription->get_gateway(); |
|
307 | + $gateway = $subscription->get_gateway(); |
|
308 | 308 | |
309 | - if ( ! empty( $gateway ) ) { |
|
310 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
311 | - } else { |
|
312 | - echo "—"; |
|
313 | - } |
|
309 | + if ( ! empty( $gateway ) ) { |
|
310 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
311 | + } else { |
|
312 | + echo "—"; |
|
313 | + } |
|
314 | 314 | |
315 | 315 | } |
316 | 316 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * @param WPInv_Subscription $subscription |
322 | 322 | */ |
323 | 323 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
324 | - echo $subscription->get_status_label_html(); |
|
324 | + echo $subscription->get_status_label_html(); |
|
325 | 325 | } |
326 | 326 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
327 | 327 | |
@@ -332,14 +332,14 @@ discard block |
||
332 | 332 | */ |
333 | 333 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
334 | 334 | |
335 | - $profile_id = $subscription->get_profile_id(); |
|
335 | + $profile_id = $subscription->get_profile_id(); |
|
336 | 336 | |
337 | - if ( ! empty( $profile_id ) ) { |
|
338 | - $profile_id = sanitize_text_field( $profile_id ); |
|
339 | - echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
340 | - } else { |
|
341 | - echo "—"; |
|
342 | - } |
|
337 | + if ( ! empty( $profile_id ) ) { |
|
338 | + $profile_id = sanitize_text_field( $profile_id ); |
|
339 | + echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription ); |
|
340 | + } else { |
|
341 | + echo "—"; |
|
342 | + } |
|
343 | 343 | |
344 | 344 | } |
345 | 345 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -351,39 +351,39 @@ discard block |
||
351 | 351 | */ |
352 | 352 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
353 | 353 | |
354 | - ?> |
|
354 | + ?> |
|
355 | 355 | <div class="mt-3"> |
356 | 356 | |
357 | 357 | <?php |
358 | - echo aui()->select( |
|
359 | - array( |
|
360 | - 'options' => getpaid_get_subscription_statuses(), |
|
361 | - 'name' => 'subscription_status', |
|
362 | - 'id' => 'subscription_status_update_select', |
|
363 | - 'required' => true, |
|
364 | - 'no_wrap' => false, |
|
365 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
366 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
367 | - 'select2' => true, |
|
368 | - 'value' => $subscription->get_status( 'edit' ), |
|
369 | - ) |
|
370 | - ); |
|
371 | - ?> |
|
358 | + echo aui()->select( |
|
359 | + array( |
|
360 | + 'options' => getpaid_get_subscription_statuses(), |
|
361 | + 'name' => 'subscription_status', |
|
362 | + 'id' => 'subscription_status_update_select', |
|
363 | + 'required' => true, |
|
364 | + 'no_wrap' => false, |
|
365 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
366 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
367 | + 'select2' => true, |
|
368 | + 'value' => $subscription->get_status( 'edit' ), |
|
369 | + ) |
|
370 | + ); |
|
371 | + ?> |
|
372 | 372 | |
373 | 373 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
374 | 374 | |
375 | 375 | <?php |
376 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
376 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
377 | 377 | |
378 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
379 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
380 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
378 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
379 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
380 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
381 | 381 | |
382 | - if ( $subscription->is_active() ) { |
|
383 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
384 | - } |
|
382 | + if ( $subscription->is_active() ) { |
|
383 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
384 | + } |
|
385 | 385 | |
386 | - echo '</div></div>'; |
|
386 | + echo '</div></div>'; |
|
387 | 387 | } |
388 | 388 | |
389 | 389 | /** |
@@ -393,33 +393,33 @@ discard block |
||
393 | 393 | */ |
394 | 394 | function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
395 | 395 | |
396 | - $columns = apply_filters( |
|
397 | - 'getpaid_subscription_related_invoices_columns', |
|
398 | - array( |
|
399 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
400 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
401 | - 'date' => __( 'Date', 'invoicing' ), |
|
402 | - 'status' => __( 'Status', 'invoicing' ), |
|
403 | - 'total' => __( 'Total', 'invoicing' ), |
|
404 | - ), |
|
405 | - $subscription |
|
406 | - ); |
|
407 | - |
|
408 | - // Prepare the invoices. |
|
409 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
410 | - $parent = $subscription->get_parent_invoice(); |
|
411 | - |
|
412 | - if ( $parent->get_id() ) { |
|
413 | - $payments = array_merge( array( $parent ), $payments ); |
|
414 | - } |
|
396 | + $columns = apply_filters( |
|
397 | + 'getpaid_subscription_related_invoices_columns', |
|
398 | + array( |
|
399 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
400 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
401 | + 'date' => __( 'Date', 'invoicing' ), |
|
402 | + 'status' => __( 'Status', 'invoicing' ), |
|
403 | + 'total' => __( 'Total', 'invoicing' ), |
|
404 | + ), |
|
405 | + $subscription |
|
406 | + ); |
|
407 | + |
|
408 | + // Prepare the invoices. |
|
409 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
410 | + $parent = $subscription->get_parent_invoice(); |
|
411 | + |
|
412 | + if ( $parent->get_id() ) { |
|
413 | + $payments = array_merge( array( $parent ), $payments ); |
|
414 | + } |
|
415 | 415 | |
416 | - $table_class = 'w-100 bg-white'; |
|
416 | + $table_class = 'w-100 bg-white'; |
|
417 | 417 | |
418 | - if ( ! is_admin() ) { |
|
419 | - $table_class = 'table table-bordered table-striped'; |
|
420 | - } |
|
418 | + if ( ! is_admin() ) { |
|
419 | + $table_class = 'table table-bordered table-striped'; |
|
420 | + } |
|
421 | 421 | |
422 | - ?> |
|
422 | + ?> |
|
423 | 423 | <div class="m-0" style="overflow: auto;"> |
424 | 424 | |
425 | 425 | <table class="<?php echo $table_class; ?>"> |
@@ -427,13 +427,13 @@ discard block |
||
427 | 427 | <thead> |
428 | 428 | <tr> |
429 | 429 | <?php |
430 | - foreach ( $columns as $key => $label ) { |
|
431 | - $key = esc_attr( $key ); |
|
432 | - $label = sanitize_text_field( $label ); |
|
430 | + foreach ( $columns as $key => $label ) { |
|
431 | + $key = esc_attr( $key ); |
|
432 | + $label = sanitize_text_field( $label ); |
|
433 | 433 | |
434 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
435 | - } |
|
436 | - ?> |
|
434 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>"; |
|
435 | + } |
|
436 | + ?> |
|
437 | 437 | </tr> |
438 | 438 | </thead> |
439 | 439 | |
@@ -449,66 +449,66 @@ discard block |
||
449 | 449 | |
450 | 450 | <?php |
451 | 451 | |
452 | - foreach( $payments as $payment ) : |
|
452 | + foreach( $payments as $payment ) : |
|
453 | 453 | |
454 | - // Ensure that we have an invoice. |
|
455 | - $payment = new WPInv_Invoice( $payment ); |
|
454 | + // Ensure that we have an invoice. |
|
455 | + $payment = new WPInv_Invoice( $payment ); |
|
456 | 456 | |
457 | - // Abort if the invoice is invalid. |
|
458 | - if ( ! $payment->get_id() ) { |
|
459 | - continue; |
|
460 | - } |
|
457 | + // Abort if the invoice is invalid. |
|
458 | + if ( ! $payment->get_id() ) { |
|
459 | + continue; |
|
460 | + } |
|
461 | 461 | |
462 | - echo '<tr>'; |
|
462 | + echo '<tr>'; |
|
463 | 463 | |
464 | - foreach ( array_keys( $columns ) as $key ) { |
|
464 | + foreach ( array_keys( $columns ) as $key ) { |
|
465 | 465 | |
466 | - echo '<td class="p-2 text-left">'; |
|
466 | + echo '<td class="p-2 text-left">'; |
|
467 | 467 | |
468 | - switch( $key ) { |
|
468 | + switch( $key ) { |
|
469 | 469 | |
470 | - case 'total': |
|
471 | - echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total() ) ), $payment->get_currency() ) . '</strong>'; |
|
472 | - break; |
|
470 | + case 'total': |
|
471 | + echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total() ) ), $payment->get_currency() ) . '</strong>'; |
|
472 | + break; |
|
473 | 473 | |
474 | - case 'relationship': |
|
475 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
476 | - break; |
|
474 | + case 'relationship': |
|
475 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
476 | + break; |
|
477 | 477 | |
478 | - case 'date': |
|
479 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
480 | - break; |
|
478 | + case 'date': |
|
479 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
480 | + break; |
|
481 | 481 | |
482 | - case 'status': |
|
482 | + case 'status': |
|
483 | 483 | |
484 | - $status = $payment->get_status_nicename(); |
|
485 | - if ( is_admin() ) { |
|
486 | - $status = $payment->get_status_label_html(); |
|
487 | - } |
|
484 | + $status = $payment->get_status_nicename(); |
|
485 | + if ( is_admin() ) { |
|
486 | + $status = $payment->get_status_label_html(); |
|
487 | + } |
|
488 | 488 | |
489 | - echo $status; |
|
490 | - break; |
|
489 | + echo $status; |
|
490 | + break; |
|
491 | 491 | |
492 | - case 'invoice': |
|
493 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
492 | + case 'invoice': |
|
493 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
494 | 494 | |
495 | - if ( ! is_admin() ) { |
|
496 | - $link = esc_url( $payment->get_view_url() ); |
|
497 | - } |
|
495 | + if ( ! is_admin() ) { |
|
496 | + $link = esc_url( $payment->get_view_url() ); |
|
497 | + } |
|
498 | 498 | |
499 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
500 | - echo "<a href='$link'>$invoice</a>"; |
|
501 | - break; |
|
502 | - } |
|
499 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
500 | + echo "<a href='$link'>$invoice</a>"; |
|
501 | + break; |
|
502 | + } |
|
503 | 503 | |
504 | - echo '</td>'; |
|
504 | + echo '</td>'; |
|
505 | 505 | |
506 | - } |
|
506 | + } |
|
507 | 507 | |
508 | - echo '</tr>'; |
|
508 | + echo '</tr>'; |
|
509 | 509 | |
510 | - endforeach; |
|
511 | - ?> |
|
510 | + endforeach; |
|
511 | + ?> |
|
512 | 512 | |
513 | 513 | </tbody> |
514 | 514 |
@@ -15,125 +15,125 @@ discard block |
||
15 | 15 | */ |
16 | 16 | class WPInv_Subscription extends GetPaid_Data { |
17 | 17 | |
18 | - /** |
|
19 | - * Which data store to load. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - protected $data_store_name = 'subscription'; |
|
24 | - |
|
25 | - /** |
|
26 | - * This is the name of this object type. |
|
27 | - * |
|
28 | - * @var string |
|
29 | - */ |
|
30 | - protected $object_type = 'subscription'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Item Data array. This is the core item data exposed in APIs. |
|
34 | - * |
|
35 | - * @since 1.0.19 |
|
36 | - * @var array |
|
37 | - */ |
|
38 | - protected $data = array( |
|
39 | - 'customer_id' => 0, |
|
40 | - 'frequency' => 1, |
|
41 | - 'period' => 'D', |
|
42 | - 'initial_amount' => null, |
|
43 | - 'recurring_amount' => null, |
|
44 | - 'bill_times' => 0, |
|
45 | - 'transaction_id' => '', |
|
46 | - 'parent_payment_id' => null, |
|
47 | - 'product_id' => 0, |
|
48 | - 'created' => '0000-00-00 00:00:00', |
|
49 | - 'expiration' => '0000-00-00 00:00:00', |
|
50 | - 'trial_period' => '', |
|
51 | - 'status' => 'pending', |
|
52 | - 'profile_id' => '', |
|
53 | - 'gateway' => '', |
|
54 | - 'customer' => '', |
|
55 | - ); |
|
56 | - |
|
57 | - /** |
|
58 | - * Stores the status transition information. |
|
59 | - * |
|
60 | - * @since 1.0.19 |
|
61 | - * @var bool |
|
62 | - */ |
|
63 | - protected $status_transition = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | - * |
|
68 | - * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | - * @param bool $deprecated |
|
70 | - */ |
|
71 | - function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | - |
|
73 | - parent::__construct( $subscription ); |
|
74 | - |
|
75 | - if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | - $this->set_id( $subscription ); |
|
77 | - } elseif ( $subscription instanceof self ) { |
|
78 | - $this->set_id( $subscription->get_id() ); |
|
79 | - } elseif ( ! empty( $subscription->id ) ) { |
|
80 | - $this->set_id( $subscription->id ); |
|
81 | - } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
82 | - $this->set_id( $subscription_id ); |
|
83 | - } else { |
|
84 | - $this->set_object_read( true ); |
|
85 | - } |
|
86 | - |
|
87 | - // Load the datastore. |
|
88 | - $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | - |
|
90 | - if ( $this->get_id() > 0 ) { |
|
91 | - $this->data_store->read( $this ); |
|
92 | - } |
|
93 | - |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | - * |
|
99 | - * |
|
100 | - * @static |
|
101 | - * @param string $value |
|
102 | - * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | - * @since 1.0.19 |
|
104 | - * @return int |
|
105 | - */ |
|
106 | - public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
18 | + /** |
|
19 | + * Which data store to load. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + protected $data_store_name = 'subscription'; |
|
24 | + |
|
25 | + /** |
|
26 | + * This is the name of this object type. |
|
27 | + * |
|
28 | + * @var string |
|
29 | + */ |
|
30 | + protected $object_type = 'subscription'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Item Data array. This is the core item data exposed in APIs. |
|
34 | + * |
|
35 | + * @since 1.0.19 |
|
36 | + * @var array |
|
37 | + */ |
|
38 | + protected $data = array( |
|
39 | + 'customer_id' => 0, |
|
40 | + 'frequency' => 1, |
|
41 | + 'period' => 'D', |
|
42 | + 'initial_amount' => null, |
|
43 | + 'recurring_amount' => null, |
|
44 | + 'bill_times' => 0, |
|
45 | + 'transaction_id' => '', |
|
46 | + 'parent_payment_id' => null, |
|
47 | + 'product_id' => 0, |
|
48 | + 'created' => '0000-00-00 00:00:00', |
|
49 | + 'expiration' => '0000-00-00 00:00:00', |
|
50 | + 'trial_period' => '', |
|
51 | + 'status' => 'pending', |
|
52 | + 'profile_id' => '', |
|
53 | + 'gateway' => '', |
|
54 | + 'customer' => '', |
|
55 | + ); |
|
56 | + |
|
57 | + /** |
|
58 | + * Stores the status transition information. |
|
59 | + * |
|
60 | + * @since 1.0.19 |
|
61 | + * @var bool |
|
62 | + */ |
|
63 | + protected $status_transition = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * Get the subscription if ID is passed, otherwise the subscription is new and empty. |
|
67 | + * |
|
68 | + * @param int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read. |
|
69 | + * @param bool $deprecated |
|
70 | + */ |
|
71 | + function __construct( $subscription = 0, $deprecated = false ) { |
|
72 | + |
|
73 | + parent::__construct( $subscription ); |
|
74 | + |
|
75 | + if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) { |
|
76 | + $this->set_id( $subscription ); |
|
77 | + } elseif ( $subscription instanceof self ) { |
|
78 | + $this->set_id( $subscription->get_id() ); |
|
79 | + } elseif ( ! empty( $subscription->id ) ) { |
|
80 | + $this->set_id( $subscription->id ); |
|
81 | + } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) { |
|
82 | + $this->set_id( $subscription_id ); |
|
83 | + } else { |
|
84 | + $this->set_object_read( true ); |
|
85 | + } |
|
86 | + |
|
87 | + // Load the datastore. |
|
88 | + $this->data_store = GetPaid_Data_Store::load( $this->data_store_name ); |
|
89 | + |
|
90 | + if ( $this->get_id() > 0 ) { |
|
91 | + $this->data_store->read( $this ); |
|
92 | + } |
|
93 | + |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Given an invoice id, profile id, transaction id, it returns the subscription's id. |
|
98 | + * |
|
99 | + * |
|
100 | + * @static |
|
101 | + * @param string $value |
|
102 | + * @param string $field Either invoice_id, transaction_id or profile_id. |
|
103 | + * @since 1.0.19 |
|
104 | + * @return int |
|
105 | + */ |
|
106 | + public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) { |
|
107 | 107 | global $wpdb; |
108 | 108 | |
109 | - // Trim the value. |
|
110 | - $value = trim( $value ); |
|
109 | + // Trim the value. |
|
110 | + $value = trim( $value ); |
|
111 | 111 | |
112 | - if ( empty( $value ) ) { |
|
113 | - return 0; |
|
114 | - } |
|
112 | + if ( empty( $value ) ) { |
|
113 | + return 0; |
|
114 | + } |
|
115 | 115 | |
116 | - if ( 'invoice_id' == $field ) { |
|
117 | - $field = 'parent_payment_id'; |
|
118 | - } |
|
116 | + if ( 'invoice_id' == $field ) { |
|
117 | + $field = 'parent_payment_id'; |
|
118 | + } |
|
119 | 119 | |
120 | 120 | // Valid fields. |
121 | 121 | $fields = array( |
122 | - 'parent_payment_id', |
|
123 | - 'transaction_id', |
|
124 | - 'profile_id' |
|
125 | - ); |
|
126 | - |
|
127 | - // Ensure a field has been passed. |
|
128 | - if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | - return 0; |
|
130 | - } |
|
131 | - |
|
132 | - // Maybe retrieve from the cache. |
|
133 | - $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | - if ( ! empty( $subscription_id ) ) { |
|
135 | - return $subscription_id; |
|
136 | - } |
|
122 | + 'parent_payment_id', |
|
123 | + 'transaction_id', |
|
124 | + 'profile_id' |
|
125 | + ); |
|
126 | + |
|
127 | + // Ensure a field has been passed. |
|
128 | + if ( empty( $field ) || ! in_array( $field, $fields ) ) { |
|
129 | + return 0; |
|
130 | + } |
|
131 | + |
|
132 | + // Maybe retrieve from the cache. |
|
133 | + $subscription_id = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
134 | + if ( ! empty( $subscription_id ) ) { |
|
135 | + return $subscription_id; |
|
136 | + } |
|
137 | 137 | |
138 | 138 | // Fetch from the db. |
139 | 139 | $table = $wpdb->prefix . 'wpinv_subscriptions'; |
@@ -141,34 +141,34 @@ discard block |
||
141 | 141 | $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value ) |
142 | 142 | ); |
143 | 143 | |
144 | - if ( empty( $subscription_id ) ) { |
|
145 | - return 0; |
|
146 | - } |
|
144 | + if ( empty( $subscription_id ) ) { |
|
145 | + return 0; |
|
146 | + } |
|
147 | 147 | |
148 | - // Update the cache with our data. |
|
149 | - wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
148 | + // Update the cache with our data. |
|
149 | + wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" ); |
|
150 | 150 | |
151 | - return $subscription_id; |
|
152 | - } |
|
151 | + return $subscription_id; |
|
152 | + } |
|
153 | 153 | |
154 | - /** |
|
154 | + /** |
|
155 | 155 | * Clears the subscription's cache. |
156 | 156 | */ |
157 | 157 | public function clear_cache() { |
158 | - wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | - wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | - wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | - wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
162 | - } |
|
158 | + wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' ); |
|
159 | + wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' ); |
|
160 | + wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' ); |
|
161 | + wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' ); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
164 | + /** |
|
165 | 165 | * Checks if a subscription key is set. |
166 | 166 | */ |
167 | 167 | public function _isset( $key ) { |
168 | 168 | return isset( $this->data[$key] ) || method_exists( $this, "get_$key" ); |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /* |
|
171 | + /* |
|
172 | 172 | |-------------------------------------------------------------------------- |
173 | 173 | | CRUD methods |
174 | 174 | |-------------------------------------------------------------------------- |
@@ -177,545 +177,545 @@ discard block |
||
177 | 177 | | |
178 | 178 | */ |
179 | 179 | |
180 | - /* |
|
180 | + /* |
|
181 | 181 | |-------------------------------------------------------------------------- |
182 | 182 | | Getters |
183 | 183 | |-------------------------------------------------------------------------- |
184 | 184 | */ |
185 | 185 | |
186 | - /** |
|
187 | - * Get customer id. |
|
188 | - * |
|
189 | - * @since 1.0.19 |
|
190 | - * @param string $context View or edit context. |
|
191 | - * @return int |
|
192 | - */ |
|
193 | - public function get_customer_id( $context = 'view' ) { |
|
194 | - return (int) $this->get_prop( 'customer_id', $context ); |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Get customer information. |
|
199 | - * |
|
200 | - * @since 1.0.19 |
|
201 | - * @param string $context View or edit context. |
|
202 | - * @return WP_User|false WP_User object on success, false on failure. |
|
203 | - */ |
|
204 | - public function get_customer( $context = 'view' ) { |
|
205 | - return get_userdata( $this->get_customer_id( $context ) ); |
|
206 | - } |
|
207 | - |
|
208 | - /** |
|
209 | - * Get parent invoice id. |
|
210 | - * |
|
211 | - * @since 1.0.19 |
|
212 | - * @param string $context View or edit context. |
|
213 | - * @return int |
|
214 | - */ |
|
215 | - public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | - return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Alias for self::get_parent_invoice_id(). |
|
221 | - * |
|
222 | - * @since 1.0.19 |
|
223 | - * @param string $context View or edit context. |
|
224 | - * @return int |
|
225 | - */ |
|
186 | + /** |
|
187 | + * Get customer id. |
|
188 | + * |
|
189 | + * @since 1.0.19 |
|
190 | + * @param string $context View or edit context. |
|
191 | + * @return int |
|
192 | + */ |
|
193 | + public function get_customer_id( $context = 'view' ) { |
|
194 | + return (int) $this->get_prop( 'customer_id', $context ); |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Get customer information. |
|
199 | + * |
|
200 | + * @since 1.0.19 |
|
201 | + * @param string $context View or edit context. |
|
202 | + * @return WP_User|false WP_User object on success, false on failure. |
|
203 | + */ |
|
204 | + public function get_customer( $context = 'view' ) { |
|
205 | + return get_userdata( $this->get_customer_id( $context ) ); |
|
206 | + } |
|
207 | + |
|
208 | + /** |
|
209 | + * Get parent invoice id. |
|
210 | + * |
|
211 | + * @since 1.0.19 |
|
212 | + * @param string $context View or edit context. |
|
213 | + * @return int |
|
214 | + */ |
|
215 | + public function get_parent_invoice_id( $context = 'view' ) { |
|
216 | + return (int) $this->get_prop( 'parent_payment_id', $context ); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Alias for self::get_parent_invoice_id(). |
|
221 | + * |
|
222 | + * @since 1.0.19 |
|
223 | + * @param string $context View or edit context. |
|
224 | + * @return int |
|
225 | + */ |
|
226 | 226 | public function get_parent_payment_id( $context = 'view' ) { |
227 | 227 | return $this->get_parent_invoice_id( $context ); |
228 | - } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Alias for self::get_parent_invoice_id(). |
|
232 | + * |
|
233 | + * @since 1.0.0 |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + public function get_original_payment_id( $context = 'view' ) { |
|
237 | + return $this->get_parent_invoice_id( $context ); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Get parent invoice. |
|
242 | + * |
|
243 | + * @since 1.0.19 |
|
244 | + * @param string $context View or edit context. |
|
245 | + * @return WPInv_Invoice |
|
246 | + */ |
|
247 | + public function get_parent_invoice( $context = 'view' ) { |
|
248 | + return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * Alias for self::get_parent_invoice(). |
|
253 | + * |
|
254 | + * @since 1.0.19 |
|
255 | + * @param string $context View or edit context. |
|
256 | + * @return WPInv_Invoice |
|
257 | + */ |
|
258 | + public function get_parent_payment( $context = 'view' ) { |
|
259 | + return $this->get_parent_invoice( $context ); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * Get subscription's product id. |
|
264 | + * |
|
265 | + * @since 1.0.19 |
|
266 | + * @param string $context View or edit context. |
|
267 | + * @return int |
|
268 | + */ |
|
269 | + public function get_product_id( $context = 'view' ) { |
|
270 | + return (int) $this->get_prop( 'product_id', $context ); |
|
271 | + } |
|
272 | + |
|
273 | + /** |
|
274 | + * Get the subscription product. |
|
275 | + * |
|
276 | + * @since 1.0.19 |
|
277 | + * @param string $context View or edit context. |
|
278 | + * @return WPInv_Item |
|
279 | + */ |
|
280 | + public function get_product( $context = 'view' ) { |
|
281 | + return new WPInv_Item( $this->get_product_id( $context ) ); |
|
282 | + } |
|
283 | + |
|
284 | + /** |
|
285 | + * Get parent invoice's gateway. |
|
286 | + * |
|
287 | + * Here for backwards compatibility. |
|
288 | + * |
|
289 | + * @since 1.0.19 |
|
290 | + * @param string $context View or edit context. |
|
291 | + * @return string |
|
292 | + */ |
|
293 | + public function get_gateway( $context = 'view' ) { |
|
294 | + return $this->get_parent_invoice( $context )->get_gateway(); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get the period of a renewal. |
|
299 | + * |
|
300 | + * @since 1.0.19 |
|
301 | + * @param string $context View or edit context. |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public function get_period( $context = 'view' ) { |
|
305 | + return $this->get_prop( 'period', $context ); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get number of periods each renewal is valid for. |
|
310 | + * |
|
311 | + * @since 1.0.19 |
|
312 | + * @param string $context View or edit context. |
|
313 | + * @return int |
|
314 | + */ |
|
315 | + public function get_frequency( $context = 'view' ) { |
|
316 | + return (int) $this->get_prop( 'frequency', $context ); |
|
317 | + } |
|
318 | + |
|
319 | + /** |
|
320 | + * Get the initial amount for the subscription. |
|
321 | + * |
|
322 | + * @since 1.0.19 |
|
323 | + * @param string $context View or edit context. |
|
324 | + * @return float |
|
325 | + */ |
|
326 | + public function get_initial_amount( $context = 'view' ) { |
|
327 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Get the recurring amount for the subscription. |
|
332 | + * |
|
333 | + * @since 1.0.19 |
|
334 | + * @param string $context View or edit context. |
|
335 | + * @return float |
|
336 | + */ |
|
337 | + public function get_recurring_amount( $context = 'view' ) { |
|
338 | + return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
339 | + } |
|
340 | + |
|
341 | + /** |
|
342 | + * Get number of times that this subscription can be renewed. |
|
343 | + * |
|
344 | + * @since 1.0.19 |
|
345 | + * @param string $context View or edit context. |
|
346 | + * @return int |
|
347 | + */ |
|
348 | + public function get_bill_times( $context = 'view' ) { |
|
349 | + return (int) $this->get_prop( 'bill_times', $context ); |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Get transaction id of this subscription's parent invoice. |
|
354 | + * |
|
355 | + * @since 1.0.19 |
|
356 | + * @param string $context View or edit context. |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function get_transaction_id( $context = 'view' ) { |
|
360 | + return $this->get_prop( 'transaction_id', $context ); |
|
361 | + } |
|
362 | + |
|
363 | + /** |
|
364 | + * Get the date that the subscription was created. |
|
365 | + * |
|
366 | + * @since 1.0.19 |
|
367 | + * @param string $context View or edit context. |
|
368 | + * @return string |
|
369 | + */ |
|
370 | + public function get_created( $context = 'view' ) { |
|
371 | + return $this->get_prop( 'created', $context ); |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Alias for self::get_created(). |
|
376 | + * |
|
377 | + * @since 1.0.19 |
|
378 | + * @param string $context View or edit context. |
|
379 | + * @return string |
|
380 | + */ |
|
381 | + public function get_date_created( $context = 'view' ) { |
|
382 | + return $this->get_created( $context ); |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Retrieves the creation date in a timestamp |
|
387 | + * |
|
388 | + * @since 1.0.0 |
|
389 | + * @return int |
|
390 | + */ |
|
391 | + public function get_time_created() { |
|
392 | + $created = $this->get_date_created(); |
|
393 | + return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * Get GMT date when the subscription was created. |
|
398 | + * |
|
399 | + * @since 1.0.19 |
|
400 | + * @param string $context View or edit context. |
|
401 | + * @return string |
|
402 | + */ |
|
403 | + public function get_date_created_gmt( $context = 'view' ) { |
|
404 | + $date = $this->get_date_created( $context ); |
|
405 | + |
|
406 | + if ( $date ) { |
|
407 | + $date = get_gmt_from_date( $date ); |
|
408 | + } |
|
409 | + return $date; |
|
410 | + } |
|
411 | + |
|
412 | + /** |
|
413 | + * Get the date that the subscription will renew. |
|
414 | + * |
|
415 | + * @since 1.0.19 |
|
416 | + * @param string $context View or edit context. |
|
417 | + * @return string |
|
418 | + */ |
|
419 | + public function get_next_renewal_date( $context = 'view' ) { |
|
420 | + return $this->get_prop( 'expiration', $context ); |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Alias for self::get_next_renewal_date(). |
|
425 | + * |
|
426 | + * @since 1.0.19 |
|
427 | + * @param string $context View or edit context. |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function get_expiration( $context = 'view' ) { |
|
431 | + return $this->get_next_renewal_date( $context ); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Retrieves the expiration date in a timestamp |
|
436 | + * |
|
437 | + * @since 1.0.0 |
|
438 | + * @return int |
|
439 | + */ |
|
440 | + public function get_expiration_time() { |
|
441 | + $expiration = $this->get_expiration(); |
|
442 | + |
|
443 | + if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | + return current_time( 'timestamp' ); |
|
445 | + } |
|
446 | + |
|
447 | + $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | + return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * Get GMT date when the subscription will renew. |
|
453 | + * |
|
454 | + * @since 1.0.19 |
|
455 | + * @param string $context View or edit context. |
|
456 | + * @return string |
|
457 | + */ |
|
458 | + public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | + $date = $this->get_next_renewal_date( $context ); |
|
460 | + |
|
461 | + if ( $date ) { |
|
462 | + $date = get_gmt_from_date( $date ); |
|
463 | + } |
|
464 | + return $date; |
|
465 | + } |
|
466 | + |
|
467 | + /** |
|
468 | + * Get the subscription's trial period. |
|
469 | + * |
|
470 | + * @since 1.0.19 |
|
471 | + * @param string $context View or edit context. |
|
472 | + * @return string |
|
473 | + */ |
|
474 | + public function get_trial_period( $context = 'view' ) { |
|
475 | + return $this->get_prop( 'trial_period', $context ); |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Get the subscription's status. |
|
480 | + * |
|
481 | + * @since 1.0.19 |
|
482 | + * @param string $context View or edit context. |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + public function get_status( $context = 'view' ) { |
|
486 | + return $this->get_prop( 'status', $context ); |
|
487 | + } |
|
488 | + |
|
489 | + /** |
|
490 | + * Get the subscription's profile id. |
|
491 | + * |
|
492 | + * @since 1.0.19 |
|
493 | + * @param string $context View or edit context. |
|
494 | + * @return string |
|
495 | + */ |
|
496 | + public function get_profile_id( $context = 'view' ) { |
|
497 | + return $this->get_prop( 'profile_id', $context ); |
|
498 | + } |
|
499 | + |
|
500 | + /* |
|
501 | + |-------------------------------------------------------------------------- |
|
502 | + | Setters |
|
503 | + |-------------------------------------------------------------------------- |
|
504 | + */ |
|
505 | + |
|
506 | + /** |
|
507 | + * Set customer id. |
|
508 | + * |
|
509 | + * @since 1.0.19 |
|
510 | + * @param int $value The customer's id. |
|
511 | + */ |
|
512 | + public function set_customer_id( $value ) { |
|
513 | + $this->set_prop( 'customer_id', (int) $value ); |
|
514 | + } |
|
515 | + |
|
516 | + /** |
|
517 | + * Set parent invoice id. |
|
518 | + * |
|
519 | + * @since 1.0.19 |
|
520 | + * @param int $value The parent invoice id. |
|
521 | + */ |
|
522 | + public function set_parent_invoice_id( $value ) { |
|
523 | + $this->set_prop( 'parent_payment_id', (int) $value ); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Alias for self::set_parent_invoice_id(). |
|
528 | + * |
|
529 | + * @since 1.0.19 |
|
530 | + * @param int $value The parent invoice id. |
|
531 | + */ |
|
532 | + public function set_parent_payment_id( $value ) { |
|
533 | + $this->set_parent_invoice_id( $value ); |
|
534 | + } |
|
535 | + |
|
536 | + /** |
|
537 | + * Alias for self::set_parent_invoice_id(). |
|
538 | + * |
|
539 | + * @since 1.0.19 |
|
540 | + * @param int $value The parent invoice id. |
|
541 | + */ |
|
542 | + public function set_original_payment_id( $value ) { |
|
543 | + $this->set_parent_invoice_id( $value ); |
|
544 | + } |
|
545 | + |
|
546 | + /** |
|
547 | + * Set subscription's product id. |
|
548 | + * |
|
549 | + * @since 1.0.19 |
|
550 | + * @param int $value The subscription product id. |
|
551 | + */ |
|
552 | + public function set_product_id( $value ) { |
|
553 | + $this->set_prop( 'product_id', (int) $value ); |
|
554 | + } |
|
555 | + |
|
556 | + /** |
|
557 | + * Set the period of a renewal. |
|
558 | + * |
|
559 | + * @since 1.0.19 |
|
560 | + * @param string $value The renewal period. |
|
561 | + */ |
|
562 | + public function set_period( $value ) { |
|
563 | + $this->set_prop( 'period', $value ); |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Set number of periods each renewal is valid for. |
|
568 | + * |
|
569 | + * @since 1.0.19 |
|
570 | + * @param int $value The subscription frequency. |
|
571 | + */ |
|
572 | + public function set_frequency( $value ) { |
|
573 | + $value = empty( $value ) ? 1 : (int) $value; |
|
574 | + $this->set_prop( 'frequency', absint( $value ) ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Set the initial amount for the subscription. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + * @param float $value The initial subcription amount. |
|
582 | + */ |
|
583 | + public function set_initial_amount( $value ) { |
|
584 | + $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Set the recurring amount for the subscription. |
|
589 | + * |
|
590 | + * @since 1.0.19 |
|
591 | + * @param float $value The recurring subcription amount. |
|
592 | + */ |
|
593 | + public function set_recurring_amount( $value ) { |
|
594 | + $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
595 | + } |
|
596 | + |
|
597 | + /** |
|
598 | + * Set number of times that this subscription can be renewed. |
|
599 | + * |
|
600 | + * @since 1.0.19 |
|
601 | + * @param int $value Bill times. |
|
602 | + */ |
|
603 | + public function set_bill_times( $value ) { |
|
604 | + $this->set_prop( 'bill_times', (int) $value ); |
|
605 | + } |
|
229 | 606 | |
230 | - /** |
|
231 | - * Alias for self::get_parent_invoice_id(). |
|
607 | + /** |
|
608 | + * Get transaction id of this subscription's parent invoice. |
|
232 | 609 | * |
233 | - * @since 1.0.0 |
|
234 | - * @return int |
|
610 | + * @since 1.0.19 |
|
611 | + * @param string $value Bill times. |
|
235 | 612 | */ |
236 | - public function get_original_payment_id( $context = 'view' ) { |
|
237 | - return $this->get_parent_invoice_id( $context ); |
|
613 | + public function set_transaction_id( $value ) { |
|
614 | + $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
238 | 615 | } |
239 | 616 | |
240 | - /** |
|
241 | - * Get parent invoice. |
|
242 | - * |
|
243 | - * @since 1.0.19 |
|
244 | - * @param string $context View or edit context. |
|
245 | - * @return WPInv_Invoice |
|
246 | - */ |
|
247 | - public function get_parent_invoice( $context = 'view' ) { |
|
248 | - return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) ); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * Alias for self::get_parent_invoice(). |
|
253 | - * |
|
254 | - * @since 1.0.19 |
|
255 | - * @param string $context View or edit context. |
|
256 | - * @return WPInv_Invoice |
|
257 | - */ |
|
258 | - public function get_parent_payment( $context = 'view' ) { |
|
259 | - return $this->get_parent_invoice( $context ); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * Get subscription's product id. |
|
264 | - * |
|
265 | - * @since 1.0.19 |
|
266 | - * @param string $context View or edit context. |
|
267 | - * @return int |
|
268 | - */ |
|
269 | - public function get_product_id( $context = 'view' ) { |
|
270 | - return (int) $this->get_prop( 'product_id', $context ); |
|
271 | - } |
|
272 | - |
|
273 | - /** |
|
274 | - * Get the subscription product. |
|
275 | - * |
|
276 | - * @since 1.0.19 |
|
277 | - * @param string $context View or edit context. |
|
278 | - * @return WPInv_Item |
|
279 | - */ |
|
280 | - public function get_product( $context = 'view' ) { |
|
281 | - return new WPInv_Item( $this->get_product_id( $context ) ); |
|
282 | - } |
|
283 | - |
|
284 | - /** |
|
285 | - * Get parent invoice's gateway. |
|
286 | - * |
|
287 | - * Here for backwards compatibility. |
|
288 | - * |
|
289 | - * @since 1.0.19 |
|
290 | - * @param string $context View or edit context. |
|
291 | - * @return string |
|
292 | - */ |
|
293 | - public function get_gateway( $context = 'view' ) { |
|
294 | - return $this->get_parent_invoice( $context )->get_gateway(); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get the period of a renewal. |
|
299 | - * |
|
300 | - * @since 1.0.19 |
|
301 | - * @param string $context View or edit context. |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public function get_period( $context = 'view' ) { |
|
305 | - return $this->get_prop( 'period', $context ); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get number of periods each renewal is valid for. |
|
310 | - * |
|
311 | - * @since 1.0.19 |
|
312 | - * @param string $context View or edit context. |
|
313 | - * @return int |
|
314 | - */ |
|
315 | - public function get_frequency( $context = 'view' ) { |
|
316 | - return (int) $this->get_prop( 'frequency', $context ); |
|
317 | - } |
|
318 | - |
|
319 | - /** |
|
320 | - * Get the initial amount for the subscription. |
|
321 | - * |
|
322 | - * @since 1.0.19 |
|
323 | - * @param string $context View or edit context. |
|
324 | - * @return float |
|
325 | - */ |
|
326 | - public function get_initial_amount( $context = 'view' ) { |
|
327 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) ); |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Get the recurring amount for the subscription. |
|
332 | - * |
|
333 | - * @since 1.0.19 |
|
334 | - * @param string $context View or edit context. |
|
335 | - * @return float |
|
336 | - */ |
|
337 | - public function get_recurring_amount( $context = 'view' ) { |
|
338 | - return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) ); |
|
339 | - } |
|
340 | - |
|
341 | - /** |
|
342 | - * Get number of times that this subscription can be renewed. |
|
343 | - * |
|
344 | - * @since 1.0.19 |
|
345 | - * @param string $context View or edit context. |
|
346 | - * @return int |
|
347 | - */ |
|
348 | - public function get_bill_times( $context = 'view' ) { |
|
349 | - return (int) $this->get_prop( 'bill_times', $context ); |
|
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Get transaction id of this subscription's parent invoice. |
|
354 | - * |
|
355 | - * @since 1.0.19 |
|
356 | - * @param string $context View or edit context. |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function get_transaction_id( $context = 'view' ) { |
|
360 | - return $this->get_prop( 'transaction_id', $context ); |
|
361 | - } |
|
362 | - |
|
363 | - /** |
|
364 | - * Get the date that the subscription was created. |
|
365 | - * |
|
366 | - * @since 1.0.19 |
|
367 | - * @param string $context View or edit context. |
|
368 | - * @return string |
|
369 | - */ |
|
370 | - public function get_created( $context = 'view' ) { |
|
371 | - return $this->get_prop( 'created', $context ); |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Alias for self::get_created(). |
|
376 | - * |
|
377 | - * @since 1.0.19 |
|
378 | - * @param string $context View or edit context. |
|
379 | - * @return string |
|
380 | - */ |
|
381 | - public function get_date_created( $context = 'view' ) { |
|
382 | - return $this->get_created( $context ); |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Retrieves the creation date in a timestamp |
|
387 | - * |
|
388 | - * @since 1.0.0 |
|
389 | - * @return int |
|
390 | - */ |
|
391 | - public function get_time_created() { |
|
392 | - $created = $this->get_date_created(); |
|
393 | - return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) ); |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * Get GMT date when the subscription was created. |
|
398 | - * |
|
399 | - * @since 1.0.19 |
|
400 | - * @param string $context View or edit context. |
|
401 | - * @return string |
|
402 | - */ |
|
403 | - public function get_date_created_gmt( $context = 'view' ) { |
|
404 | - $date = $this->get_date_created( $context ); |
|
617 | + /** |
|
618 | + * Set date when this subscription started. |
|
619 | + * |
|
620 | + * @since 1.0.19 |
|
621 | + * @param string $value strtotime compliant date. |
|
622 | + */ |
|
623 | + public function set_created( $value ) { |
|
624 | + $date = strtotime( $value ); |
|
405 | 625 | |
406 | - if ( $date ) { |
|
407 | - $date = get_gmt_from_date( $date ); |
|
626 | + if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
627 | + $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
628 | + return; |
|
408 | 629 | } |
409 | - return $date; |
|
410 | - } |
|
411 | - |
|
412 | - /** |
|
413 | - * Get the date that the subscription will renew. |
|
414 | - * |
|
415 | - * @since 1.0.19 |
|
416 | - * @param string $context View or edit context. |
|
417 | - * @return string |
|
418 | - */ |
|
419 | - public function get_next_renewal_date( $context = 'view' ) { |
|
420 | - return $this->get_prop( 'expiration', $context ); |
|
421 | - } |
|
422 | - |
|
423 | - /** |
|
424 | - * Alias for self::get_next_renewal_date(). |
|
425 | - * |
|
426 | - * @since 1.0.19 |
|
427 | - * @param string $context View or edit context. |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function get_expiration( $context = 'view' ) { |
|
431 | - return $this->get_next_renewal_date( $context ); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Retrieves the expiration date in a timestamp |
|
436 | - * |
|
437 | - * @since 1.0.0 |
|
438 | - * @return int |
|
439 | - */ |
|
440 | - public function get_expiration_time() { |
|
441 | - $expiration = $this->get_expiration(); |
|
442 | - |
|
443 | - if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) { |
|
444 | - return current_time( 'timestamp' ); |
|
445 | - } |
|
446 | - |
|
447 | - $expiration = strtotime( $expiration, current_time( 'timestamp' ) ); |
|
448 | - return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Get GMT date when the subscription will renew. |
|
453 | - * |
|
454 | - * @since 1.0.19 |
|
455 | - * @param string $context View or edit context. |
|
456 | - * @return string |
|
457 | - */ |
|
458 | - public function get_next_renewal_date_gmt( $context = 'view' ) { |
|
459 | - $date = $this->get_next_renewal_date( $context ); |
|
460 | 630 | |
461 | - if ( $date ) { |
|
462 | - $date = get_gmt_from_date( $date ); |
|
463 | - } |
|
464 | - return $date; |
|
465 | - } |
|
466 | - |
|
467 | - /** |
|
468 | - * Get the subscription's trial period. |
|
469 | - * |
|
470 | - * @since 1.0.19 |
|
471 | - * @param string $context View or edit context. |
|
472 | - * @return string |
|
473 | - */ |
|
474 | - public function get_trial_period( $context = 'view' ) { |
|
475 | - return $this->get_prop( 'trial_period', $context ); |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Get the subscription's status. |
|
480 | - * |
|
481 | - * @since 1.0.19 |
|
482 | - * @param string $context View or edit context. |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - public function get_status( $context = 'view' ) { |
|
486 | - return $this->get_prop( 'status', $context ); |
|
487 | - } |
|
488 | - |
|
489 | - /** |
|
490 | - * Get the subscription's profile id. |
|
491 | - * |
|
492 | - * @since 1.0.19 |
|
493 | - * @param string $context View or edit context. |
|
494 | - * @return string |
|
495 | - */ |
|
496 | - public function get_profile_id( $context = 'view' ) { |
|
497 | - return $this->get_prop( 'profile_id', $context ); |
|
498 | - } |
|
499 | - |
|
500 | - /* |
|
501 | - |-------------------------------------------------------------------------- |
|
502 | - | Setters |
|
503 | - |-------------------------------------------------------------------------- |
|
504 | - */ |
|
631 | + $this->set_prop( 'created', '' ); |
|
505 | 632 | |
506 | - /** |
|
507 | - * Set customer id. |
|
508 | - * |
|
509 | - * @since 1.0.19 |
|
510 | - * @param int $value The customer's id. |
|
511 | - */ |
|
512 | - public function set_customer_id( $value ) { |
|
513 | - $this->set_prop( 'customer_id', (int) $value ); |
|
514 | - } |
|
515 | - |
|
516 | - /** |
|
517 | - * Set parent invoice id. |
|
518 | - * |
|
519 | - * @since 1.0.19 |
|
520 | - * @param int $value The parent invoice id. |
|
521 | - */ |
|
522 | - public function set_parent_invoice_id( $value ) { |
|
523 | - $this->set_prop( 'parent_payment_id', (int) $value ); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Alias for self::set_parent_invoice_id(). |
|
528 | - * |
|
529 | - * @since 1.0.19 |
|
530 | - * @param int $value The parent invoice id. |
|
531 | - */ |
|
532 | - public function set_parent_payment_id( $value ) { |
|
533 | - $this->set_parent_invoice_id( $value ); |
|
534 | - } |
|
633 | + } |
|
535 | 634 | |
536 | - /** |
|
537 | - * Alias for self::set_parent_invoice_id(). |
|
635 | + /** |
|
636 | + * Alias for self::set_created(). |
|
538 | 637 | * |
539 | 638 | * @since 1.0.19 |
540 | - * @param int $value The parent invoice id. |
|
639 | + * @param string $value strtotime compliant date. |
|
541 | 640 | */ |
542 | - public function set_original_payment_id( $value ) { |
|
543 | - $this->set_parent_invoice_id( $value ); |
|
544 | - } |
|
545 | - |
|
546 | - /** |
|
547 | - * Set subscription's product id. |
|
548 | - * |
|
549 | - * @since 1.0.19 |
|
550 | - * @param int $value The subscription product id. |
|
551 | - */ |
|
552 | - public function set_product_id( $value ) { |
|
553 | - $this->set_prop( 'product_id', (int) $value ); |
|
554 | - } |
|
555 | - |
|
556 | - /** |
|
557 | - * Set the period of a renewal. |
|
558 | - * |
|
559 | - * @since 1.0.19 |
|
560 | - * @param string $value The renewal period. |
|
561 | - */ |
|
562 | - public function set_period( $value ) { |
|
563 | - $this->set_prop( 'period', $value ); |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Set number of periods each renewal is valid for. |
|
568 | - * |
|
569 | - * @since 1.0.19 |
|
570 | - * @param int $value The subscription frequency. |
|
571 | - */ |
|
572 | - public function set_frequency( $value ) { |
|
573 | - $value = empty( $value ) ? 1 : (int) $value; |
|
574 | - $this->set_prop( 'frequency', absint( $value ) ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Set the initial amount for the subscription. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - * @param float $value The initial subcription amount. |
|
582 | - */ |
|
583 | - public function set_initial_amount( $value ) { |
|
584 | - $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) ); |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Set the recurring amount for the subscription. |
|
589 | - * |
|
590 | - * @since 1.0.19 |
|
591 | - * @param float $value The recurring subcription amount. |
|
592 | - */ |
|
593 | - public function set_recurring_amount( $value ) { |
|
594 | - $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) ); |
|
595 | - } |
|
596 | - |
|
597 | - /** |
|
598 | - * Set number of times that this subscription can be renewed. |
|
599 | - * |
|
600 | - * @since 1.0.19 |
|
601 | - * @param int $value Bill times. |
|
602 | - */ |
|
603 | - public function set_bill_times( $value ) { |
|
604 | - $this->set_prop( 'bill_times', (int) $value ); |
|
605 | - } |
|
606 | - |
|
607 | - /** |
|
608 | - * Get transaction id of this subscription's parent invoice. |
|
609 | - * |
|
610 | - * @since 1.0.19 |
|
611 | - * @param string $value Bill times. |
|
612 | - */ |
|
613 | - public function set_transaction_id( $value ) { |
|
614 | - $this->set_prop( 'transaction_id', sanitize_text_field( $value ) ); |
|
615 | - } |
|
616 | - |
|
617 | - /** |
|
618 | - * Set date when this subscription started. |
|
619 | - * |
|
620 | - * @since 1.0.19 |
|
621 | - * @param string $value strtotime compliant date. |
|
622 | - */ |
|
623 | - public function set_created( $value ) { |
|
641 | + public function set_date_created( $value ) { |
|
642 | + $this->set_created( $value ); |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Set the date that the subscription will renew. |
|
647 | + * |
|
648 | + * @since 1.0.19 |
|
649 | + * @param string $value strtotime compliant date. |
|
650 | + */ |
|
651 | + public function set_next_renewal_date( $value ) { |
|
624 | 652 | $date = strtotime( $value ); |
625 | 653 | |
626 | 654 | if ( $date && $value !== '0000-00-00 00:00:00' ) { |
627 | - $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) ); |
|
655 | + $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
628 | 656 | return; |
629 | 657 | } |
630 | 658 | |
631 | - $this->set_prop( 'created', '' ); |
|
659 | + $this->set_prop( 'expiration', '' ); |
|
632 | 660 | |
633 | - } |
|
661 | + } |
|
662 | + |
|
663 | + /** |
|
664 | + * Alias for self::set_next_renewal_date(). |
|
665 | + * |
|
666 | + * @since 1.0.19 |
|
667 | + * @param string $value strtotime compliant date. |
|
668 | + */ |
|
669 | + public function set_expiration( $value ) { |
|
670 | + $this->set_next_renewal_date( $value ); |
|
671 | + } |
|
634 | 672 | |
635 | - /** |
|
636 | - * Alias for self::set_created(). |
|
637 | - * |
|
638 | - * @since 1.0.19 |
|
639 | - * @param string $value strtotime compliant date. |
|
640 | - */ |
|
641 | - public function set_date_created( $value ) { |
|
642 | - $this->set_created( $value ); |
|
673 | + /** |
|
674 | + * Set the subscription's trial period. |
|
675 | + * |
|
676 | + * @since 1.0.19 |
|
677 | + * @param string $value trial period e.g 1 year. |
|
678 | + */ |
|
679 | + public function set_trial_period( $value ) { |
|
680 | + $this->set_prop( 'trial_period', $value ); |
|
643 | 681 | } |
644 | 682 | |
645 | - /** |
|
646 | - * Set the date that the subscription will renew. |
|
647 | - * |
|
648 | - * @since 1.0.19 |
|
649 | - * @param string $value strtotime compliant date. |
|
650 | - */ |
|
651 | - public function set_next_renewal_date( $value ) { |
|
652 | - $date = strtotime( $value ); |
|
683 | + /** |
|
684 | + * Set the subscription's status. |
|
685 | + * |
|
686 | + * @since 1.0.19 |
|
687 | + * @param string $new_status New subscription status. |
|
688 | + */ |
|
689 | + public function set_status( $new_status ) { |
|
653 | 690 | |
654 | - if ( $date && $value !== '0000-00-00 00:00:00' ) { |
|
655 | - $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) ); |
|
691 | + // Abort if this is not a valid status; |
|
692 | + if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
656 | 693 | return; |
657 | - } |
|
658 | - |
|
659 | - $this->set_prop( 'expiration', '' ); |
|
660 | - |
|
661 | - } |
|
662 | - |
|
663 | - /** |
|
664 | - * Alias for self::set_next_renewal_date(). |
|
665 | - * |
|
666 | - * @since 1.0.19 |
|
667 | - * @param string $value strtotime compliant date. |
|
668 | - */ |
|
669 | - public function set_expiration( $value ) { |
|
670 | - $this->set_next_renewal_date( $value ); |
|
671 | - } |
|
672 | - |
|
673 | - /** |
|
674 | - * Set the subscription's trial period. |
|
675 | - * |
|
676 | - * @since 1.0.19 |
|
677 | - * @param string $value trial period e.g 1 year. |
|
678 | - */ |
|
679 | - public function set_trial_period( $value ) { |
|
680 | - $this->set_prop( 'trial_period', $value ); |
|
681 | - } |
|
682 | - |
|
683 | - /** |
|
684 | - * Set the subscription's status. |
|
685 | - * |
|
686 | - * @since 1.0.19 |
|
687 | - * @param string $new_status New subscription status. |
|
688 | - */ |
|
689 | - public function set_status( $new_status ) { |
|
690 | - |
|
691 | - // Abort if this is not a valid status; |
|
692 | - if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) { |
|
693 | - return; |
|
694 | - } |
|
695 | - |
|
696 | - $old_status = $this->get_status(); |
|
697 | - $this->set_prop( 'status', $new_status ); |
|
698 | - |
|
699 | - if ( true === $this->object_read && $old_status !== $new_status ) { |
|
700 | - $this->status_transition = array( |
|
701 | - 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
702 | - 'to' => $new_status, |
|
703 | - ); |
|
704 | - } |
|
705 | - |
|
706 | - } |
|
707 | - |
|
708 | - /** |
|
709 | - * Set the subscription's (remote) profile id. |
|
710 | - * |
|
711 | - * @since 1.0.19 |
|
712 | - * @param string $value the remote profile id. |
|
713 | - */ |
|
714 | - public function set_profile_id( $value ) { |
|
715 | - $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
716 | - } |
|
717 | - |
|
718 | - /* |
|
694 | + } |
|
695 | + |
|
696 | + $old_status = $this->get_status(); |
|
697 | + $this->set_prop( 'status', $new_status ); |
|
698 | + |
|
699 | + if ( true === $this->object_read && $old_status !== $new_status ) { |
|
700 | + $this->status_transition = array( |
|
701 | + 'from' => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status, |
|
702 | + 'to' => $new_status, |
|
703 | + ); |
|
704 | + } |
|
705 | + |
|
706 | + } |
|
707 | + |
|
708 | + /** |
|
709 | + * Set the subscription's (remote) profile id. |
|
710 | + * |
|
711 | + * @since 1.0.19 |
|
712 | + * @param string $value the remote profile id. |
|
713 | + */ |
|
714 | + public function set_profile_id( $value ) { |
|
715 | + $this->set_prop( 'profile_id', sanitize_text_field( $value ) ); |
|
716 | + } |
|
717 | + |
|
718 | + /* |
|
719 | 719 | |-------------------------------------------------------------------------- |
720 | 720 | | Boolean methods |
721 | 721 | |-------------------------------------------------------------------------- |
@@ -724,55 +724,55 @@ discard block |
||
724 | 724 | | |
725 | 725 | */ |
726 | 726 | |
727 | - /** |
|
727 | + /** |
|
728 | 728 | * Checks if the subscription has a given status. |
729 | - * |
|
730 | - * @param string|array String or array of strings to check for. |
|
731 | - * @return bool |
|
729 | + * |
|
730 | + * @param string|array String or array of strings to check for. |
|
731 | + * @return bool |
|
732 | 732 | */ |
733 | 733 | public function has_status( $status ) { |
734 | 734 | return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) ); |
735 | - } |
|
735 | + } |
|
736 | 736 | |
737 | - /** |
|
737 | + /** |
|
738 | 738 | * Checks if the subscription has a trial period. |
739 | - * |
|
740 | - * @return bool |
|
739 | + * |
|
740 | + * @return bool |
|
741 | 741 | */ |
742 | 742 | public function has_trial_period() { |
743 | - $period = $this->get_trial_period(); |
|
743 | + $period = $this->get_trial_period(); |
|
744 | 744 | return ! empty( $period ); |
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * Is the subscription active? |
|
749 | - * |
|
750 | - * @return bool |
|
751 | - */ |
|
752 | - public function is_active() { |
|
753 | - return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
754 | - } |
|
755 | - |
|
756 | - /** |
|
757 | - * Is the subscription expired? |
|
758 | - * |
|
759 | - * @return bool |
|
760 | - */ |
|
761 | - public function is_expired() { |
|
762 | - return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
763 | - } |
|
764 | - |
|
765 | - /** |
|
766 | - * Is this the last renewals? |
|
767 | - * |
|
768 | - * @return bool |
|
769 | - */ |
|
770 | - public function is_last_renewal() { |
|
771 | - $max_bills = $this->get_bill_times(); |
|
772 | - return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
773 | - } |
|
774 | - |
|
775 | - /* |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * Is the subscription active? |
|
749 | + * |
|
750 | + * @return bool |
|
751 | + */ |
|
752 | + public function is_active() { |
|
753 | + return $this->has_status( 'active trialling' ) && ! $this->is_expired(); |
|
754 | + } |
|
755 | + |
|
756 | + /** |
|
757 | + * Is the subscription expired? |
|
758 | + * |
|
759 | + * @return bool |
|
760 | + */ |
|
761 | + public function is_expired() { |
|
762 | + return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) ); |
|
763 | + } |
|
764 | + |
|
765 | + /** |
|
766 | + * Is this the last renewals? |
|
767 | + * |
|
768 | + * @return bool |
|
769 | + */ |
|
770 | + public function is_last_renewal() { |
|
771 | + $max_bills = $this->get_bill_times(); |
|
772 | + return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed(); |
|
773 | + } |
|
774 | + |
|
775 | + /* |
|
776 | 776 | |-------------------------------------------------------------------------- |
777 | 777 | | Additional methods |
778 | 778 | |-------------------------------------------------------------------------- |
@@ -781,27 +781,27 @@ discard block |
||
781 | 781 | | |
782 | 782 | */ |
783 | 783 | |
784 | - /** |
|
785 | - * Backwards compatibilty. |
|
786 | - */ |
|
787 | - public function create( $data = array() ) { |
|
784 | + /** |
|
785 | + * Backwards compatibilty. |
|
786 | + */ |
|
787 | + public function create( $data = array() ) { |
|
788 | 788 | |
789 | - // Set the properties. |
|
790 | - if ( is_array( $data ) ) { |
|
791 | - $this->set_props( $data ); |
|
792 | - } |
|
789 | + // Set the properties. |
|
790 | + if ( is_array( $data ) ) { |
|
791 | + $this->set_props( $data ); |
|
792 | + } |
|
793 | 793 | |
794 | - // Save the item. |
|
795 | - return $this->save(); |
|
794 | + // Save the item. |
|
795 | + return $this->save(); |
|
796 | 796 | |
797 | - } |
|
797 | + } |
|
798 | 798 | |
799 | - /** |
|
800 | - * Backwards compatibilty. |
|
801 | - */ |
|
802 | - public function update( $args = array() ) { |
|
803 | - return $this->create( $args ); |
|
804 | - } |
|
799 | + /** |
|
800 | + * Backwards compatibilty. |
|
801 | + */ |
|
802 | + public function update( $args = array() ) { |
|
803 | + return $this->create( $args ); |
|
804 | + } |
|
805 | 805 | |
806 | 806 | /** |
807 | 807 | * Retrieve renewal payments for a subscription |
@@ -811,22 +811,22 @@ discard block |
||
811 | 811 | */ |
812 | 812 | public function get_child_payments( $hide_pending = true ) { |
813 | 813 | |
814 | - $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
814 | + $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' ); |
|
815 | 815 | |
816 | - if ( ! $hide_pending ) { |
|
817 | - $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
818 | - } |
|
816 | + if ( ! $hide_pending ) { |
|
817 | + $statuses = array_keys( wpinv_get_invoice_statuses() ); |
|
818 | + } |
|
819 | 819 | |
820 | 820 | return get_posts( |
821 | - array( |
|
822 | - 'post_parent' => $this->get_parent_payment_id(), |
|
823 | - 'numberposts' => -1, |
|
824 | - 'post_status' => $statuses, |
|
825 | - 'orderby' => 'ID', |
|
826 | - 'order' => 'DESC', |
|
827 | - 'post_type' => 'wpi_invoice' |
|
828 | - ) |
|
829 | - ); |
|
821 | + array( |
|
822 | + 'post_parent' => $this->get_parent_payment_id(), |
|
823 | + 'numberposts' => -1, |
|
824 | + 'post_status' => $statuses, |
|
825 | + 'orderby' => 'ID', |
|
826 | + 'order' => 'DESC', |
|
827 | + 'post_type' => 'wpi_invoice' |
|
828 | + ) |
|
829 | + ); |
|
830 | 830 | } |
831 | 831 | |
832 | 832 | /** |
@@ -836,16 +836,16 @@ discard block |
||
836 | 836 | * @return int |
837 | 837 | */ |
838 | 838 | public function get_total_payments() { |
839 | - global $wpdb; |
|
839 | + global $wpdb; |
|
840 | 840 | |
841 | - $count = (int) $wpdb->get_var( |
|
842 | - $wpdb->prepare( |
|
843 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
844 | - $this->get_parent_invoice_id() |
|
845 | - ) |
|
846 | - ); |
|
841 | + $count = (int) $wpdb->get_var( |
|
842 | + $wpdb->prepare( |
|
843 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
844 | + $this->get_parent_invoice_id() |
|
845 | + ) |
|
846 | + ); |
|
847 | 847 | |
848 | - // Maybe include parent invoice. |
|
848 | + // Maybe include parent invoice. |
|
849 | 849 | if ( $this->get_parent_payment()->is_paid() ) { |
850 | 850 | $count++; |
851 | 851 | } |
@@ -874,57 +874,57 @@ discard block |
||
874 | 874 | * |
875 | 875 | * @since 2.4 |
876 | 876 | * @param array $args Array of values for the payment, including amount and transaction ID |
877 | - * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
877 | + * @param WPInv_Invoice $invoice If adding an existing invoice. |
|
878 | 878 | * @return bool |
879 | 879 | */ |
880 | 880 | public function add_payment( $args = array(), $invoice = false ) { |
881 | 881 | |
882 | - // Process each payment once. |
|
882 | + // Process each payment once. |
|
883 | 883 | if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) { |
884 | 884 | return false; |
885 | 885 | } |
886 | 886 | |
887 | - // Are we creating a new invoice? |
|
888 | - if ( empty( $invoice ) ) { |
|
889 | - $invoice = $this->create_payment(); |
|
887 | + // Are we creating a new invoice? |
|
888 | + if ( empty( $invoice ) ) { |
|
889 | + $invoice = $this->create_payment(); |
|
890 | 890 | |
891 | - if ( empty( $invoice ) ) { |
|
892 | - return false; |
|
893 | - } |
|
891 | + if ( empty( $invoice ) ) { |
|
892 | + return false; |
|
893 | + } |
|
894 | 894 | |
895 | - } |
|
895 | + } |
|
896 | 896 | |
897 | - $invoice->set_status( 'wpi-renewal' ); |
|
897 | + $invoice->set_status( 'wpi-renewal' ); |
|
898 | 898 | |
899 | - // Maybe set a transaction id. |
|
900 | - if ( ! empty( $args['transaction_id'] ) ) { |
|
901 | - $invoice->set_transaction_id( $args['transaction_id'] ); |
|
902 | - } |
|
899 | + // Maybe set a transaction id. |
|
900 | + if ( ! empty( $args['transaction_id'] ) ) { |
|
901 | + $invoice->set_transaction_id( $args['transaction_id'] ); |
|
902 | + } |
|
903 | 903 | |
904 | - // Set the completed date. |
|
905 | - $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
904 | + // Set the completed date. |
|
905 | + $invoice->set_completed_date( current_time( 'mysql' ) ); |
|
906 | 906 | |
907 | - // And the gateway. |
|
908 | - if ( ! empty( $args['gateway'] ) ) { |
|
909 | - $invoice->set_gateway( $args['gateway'] ); |
|
910 | - } |
|
907 | + // And the gateway. |
|
908 | + if ( ! empty( $args['gateway'] ) ) { |
|
909 | + $invoice->set_gateway( $args['gateway'] ); |
|
910 | + } |
|
911 | 911 | |
912 | - $invoice->save(); |
|
912 | + $invoice->save(); |
|
913 | 913 | |
914 | - if ( ! $invoice->exists() ) { |
|
915 | - return false; |
|
916 | - } |
|
914 | + if ( ! $invoice->exists() ) { |
|
915 | + return false; |
|
916 | + } |
|
917 | 917 | |
918 | - do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
919 | - do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
918 | + do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this ); |
|
919 | + do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this ); |
|
920 | 920 | do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() ); |
921 | 921 | |
922 | 922 | update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id ); |
923 | 923 | |
924 | 924 | return $invoice->get_id(); |
925 | - } |
|
925 | + } |
|
926 | 926 | |
927 | - /** |
|
927 | + /** |
|
928 | 928 | * Creates a new invoice and returns it. |
929 | 929 | * |
930 | 930 | * @since 1.0.19 |
@@ -932,97 +932,97 @@ discard block |
||
932 | 932 | */ |
933 | 933 | public function create_payment() { |
934 | 934 | |
935 | - $parent_invoice = $this->get_parent_payment(); |
|
936 | - |
|
937 | - if ( ! $parent_invoice->exists() ) { |
|
938 | - return false; |
|
939 | - } |
|
940 | - |
|
941 | - // Duplicate the parent invoice. |
|
942 | - $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
943 | - $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
944 | - $invoice->recalculate_total(); |
|
945 | - $invoice->set_status( 'wpi-pending' ); |
|
946 | - $invoice->save(); |
|
947 | - |
|
948 | - return $invoice->exists() ? $invoice : false; |
|
949 | - } |
|
950 | - |
|
951 | - /** |
|
952 | - * Renews or completes a subscription |
|
953 | - * |
|
954 | - * @since 1.0.0 |
|
955 | - * @return int The subscription's id |
|
956 | - */ |
|
957 | - public function renew() { |
|
958 | - |
|
959 | - // Complete subscription if applicable |
|
960 | - if ( $this->is_last_renewal() ) { |
|
961 | - return $this->complete(); |
|
962 | - } |
|
963 | - |
|
964 | - // Calculate new expiration |
|
965 | - $frequency = $this->get_frequency(); |
|
966 | - $period = $this->get_period(); |
|
967 | - $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
968 | - |
|
969 | - $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
970 | - $this->set_status( 'active' ); |
|
971 | - return $this->save(); |
|
972 | - |
|
973 | - do_action( 'getpaid_subscription_renewed', $this ); |
|
974 | - |
|
975 | - } |
|
976 | - |
|
977 | - /** |
|
978 | - * Marks a subscription as completed |
|
979 | - * |
|
980 | - * Subscription is completed when the number of payments matches the billing_times field |
|
981 | - * |
|
982 | - * @since 1.0.0 |
|
983 | - * @return int|bool Subscription id or false if the subscription is cancelled. |
|
984 | - */ |
|
985 | - public function complete() { |
|
986 | - |
|
987 | - // Only mark a subscription as complete if it's not already cancelled. |
|
988 | - if ( $this->has_status( 'cancelled' ) ) { |
|
989 | - return false; |
|
990 | - } |
|
991 | - |
|
992 | - $this->set_status( 'completed' ); |
|
993 | - return $this->save(); |
|
994 | - |
|
995 | - } |
|
996 | - |
|
997 | - /** |
|
998 | - * Marks a subscription as expired |
|
999 | - * |
|
1000 | - * @since 1.0.0 |
|
1001 | - * @param bool $check_expiration |
|
1002 | - * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1003 | - */ |
|
1004 | - public function expire( $check_expiration = false ) { |
|
1005 | - |
|
1006 | - if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1007 | - // Do not mark as expired since real expiration date is in the future |
|
1008 | - return false; |
|
1009 | - } |
|
1010 | - |
|
1011 | - $this->set_status( 'expired' ); |
|
1012 | - return $this->save(); |
|
1013 | - |
|
1014 | - } |
|
1015 | - |
|
1016 | - /** |
|
1017 | - * Marks a subscription as failing |
|
1018 | - * |
|
1019 | - * @since 2.4.2 |
|
1020 | - * @return int Subscription id. |
|
1021 | - */ |
|
1022 | - public function failing() { |
|
1023 | - $this->set_status( 'failing' ); |
|
1024 | - return $this->save(); |
|
1025 | - } |
|
935 | + $parent_invoice = $this->get_parent_payment(); |
|
936 | + |
|
937 | + if ( ! $parent_invoice->exists() ) { |
|
938 | + return false; |
|
939 | + } |
|
940 | + |
|
941 | + // Duplicate the parent invoice. |
|
942 | + $invoice = getpaid_duplicate_invoice( $parent_invoice ); |
|
943 | + $invoice->set_parent_id( $parent_invoice->get_id() ); |
|
944 | + $invoice->recalculate_total(); |
|
945 | + $invoice->set_status( 'wpi-pending' ); |
|
946 | + $invoice->save(); |
|
947 | + |
|
948 | + return $invoice->exists() ? $invoice : false; |
|
949 | + } |
|
950 | + |
|
951 | + /** |
|
952 | + * Renews or completes a subscription |
|
953 | + * |
|
954 | + * @since 1.0.0 |
|
955 | + * @return int The subscription's id |
|
956 | + */ |
|
957 | + public function renew() { |
|
958 | + |
|
959 | + // Complete subscription if applicable |
|
960 | + if ( $this->is_last_renewal() ) { |
|
961 | + return $this->complete(); |
|
962 | + } |
|
963 | + |
|
964 | + // Calculate new expiration |
|
965 | + $frequency = $this->get_frequency(); |
|
966 | + $period = $this->get_period(); |
|
967 | + $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() ); |
|
968 | + |
|
969 | + $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) ); |
|
970 | + $this->set_status( 'active' ); |
|
971 | + return $this->save(); |
|
972 | + |
|
973 | + do_action( 'getpaid_subscription_renewed', $this ); |
|
974 | + |
|
975 | + } |
|
976 | + |
|
977 | + /** |
|
978 | + * Marks a subscription as completed |
|
979 | + * |
|
980 | + * Subscription is completed when the number of payments matches the billing_times field |
|
981 | + * |
|
982 | + * @since 1.0.0 |
|
983 | + * @return int|bool Subscription id or false if the subscription is cancelled. |
|
984 | + */ |
|
985 | + public function complete() { |
|
986 | + |
|
987 | + // Only mark a subscription as complete if it's not already cancelled. |
|
988 | + if ( $this->has_status( 'cancelled' ) ) { |
|
989 | + return false; |
|
990 | + } |
|
991 | + |
|
992 | + $this->set_status( 'completed' ); |
|
993 | + return $this->save(); |
|
994 | + |
|
995 | + } |
|
996 | + |
|
997 | + /** |
|
998 | + * Marks a subscription as expired |
|
999 | + * |
|
1000 | + * @since 1.0.0 |
|
1001 | + * @param bool $check_expiration |
|
1002 | + * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future. |
|
1003 | + */ |
|
1004 | + public function expire( $check_expiration = false ) { |
|
1005 | + |
|
1006 | + if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) { |
|
1007 | + // Do not mark as expired since real expiration date is in the future |
|
1008 | + return false; |
|
1009 | + } |
|
1010 | + |
|
1011 | + $this->set_status( 'expired' ); |
|
1012 | + return $this->save(); |
|
1013 | + |
|
1014 | + } |
|
1015 | + |
|
1016 | + /** |
|
1017 | + * Marks a subscription as failing |
|
1018 | + * |
|
1019 | + * @since 2.4.2 |
|
1020 | + * @return int Subscription id. |
|
1021 | + */ |
|
1022 | + public function failing() { |
|
1023 | + $this->set_status( 'failing' ); |
|
1024 | + return $this->save(); |
|
1025 | + } |
|
1026 | 1026 | |
1027 | 1027 | /** |
1028 | 1028 | * Marks a subscription as cancelled |
@@ -1031,19 +1031,19 @@ discard block |
||
1031 | 1031 | * @return int Subscription id. |
1032 | 1032 | */ |
1033 | 1033 | public function cancel() { |
1034 | - $this->set_status( 'cancelled' ); |
|
1035 | - return $this->save(); |
|
1034 | + $this->set_status( 'cancelled' ); |
|
1035 | + return $this->save(); |
|
1036 | 1036 | } |
1037 | 1037 | |
1038 | - /** |
|
1039 | - * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1040 | - * |
|
1041 | - * @since 1.0.0 |
|
1042 | - * @return bool |
|
1043 | - */ |
|
1044 | - public function can_cancel() { |
|
1045 | - return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1046 | - } |
|
1038 | + /** |
|
1039 | + * Determines if a subscription can be cancelled both locally and with a payment processor. |
|
1040 | + * |
|
1041 | + * @since 1.0.0 |
|
1042 | + * @return bool |
|
1043 | + */ |
|
1044 | + public function can_cancel() { |
|
1045 | + return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this ); |
|
1046 | + } |
|
1047 | 1047 | |
1048 | 1048 | /** |
1049 | 1049 | * Returns an array of subscription statuses that can be cancelled |
@@ -1056,93 +1056,93 @@ discard block |
||
1056 | 1056 | return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) ); |
1057 | 1057 | } |
1058 | 1058 | |
1059 | - /** |
|
1060 | - * Retrieves the URL to cancel subscription |
|
1061 | - * |
|
1062 | - * @since 1.0.0 |
|
1063 | - * @return string |
|
1064 | - */ |
|
1065 | - public function get_cancel_url() { |
|
1066 | - $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1067 | - return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1068 | - } |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * Retrieves the URL to view a subscription |
|
1072 | - * |
|
1073 | - * @since 1.0.19 |
|
1074 | - * @return string |
|
1075 | - */ |
|
1076 | - public function get_view_url() { |
|
1077 | - $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1078 | - return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1079 | - } |
|
1080 | - |
|
1081 | - /** |
|
1082 | - * Determines if subscription can be manually renewed |
|
1083 | - * |
|
1084 | - * This method is filtered by payment gateways in order to return true on subscriptions |
|
1085 | - * that can be renewed manually |
|
1086 | - * |
|
1087 | - * @since 2.5 |
|
1088 | - * @return bool |
|
1089 | - */ |
|
1090 | - public function can_renew() { |
|
1091 | - return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1092 | - } |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * Retrieves the URL to renew a subscription |
|
1096 | - * |
|
1097 | - * @since 2.5 |
|
1098 | - * @return string |
|
1099 | - */ |
|
1100 | - public function get_renew_url() { |
|
1101 | - $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1102 | - return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1103 | - } |
|
1104 | - |
|
1105 | - /** |
|
1106 | - * Determines if subscription can have their payment method updated |
|
1107 | - * |
|
1108 | - * @since 1.0.0 |
|
1109 | - * @return bool |
|
1110 | - */ |
|
1111 | - public function can_update() { |
|
1112 | - return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1113 | - } |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * Retrieves the URL to update subscription |
|
1117 | - * |
|
1118 | - * @since 1.0.0 |
|
1119 | - * @return string |
|
1120 | - */ |
|
1121 | - public function get_update_url() { |
|
1122 | - $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1123 | - return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1124 | - } |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * Retrieves the subscription status label |
|
1128 | - * |
|
1129 | - * @since 1.0.0 |
|
1130 | - * @return string |
|
1131 | - */ |
|
1132 | - public function get_status_label() { |
|
1133 | - return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1134 | - } |
|
1135 | - |
|
1136 | - /** |
|
1137 | - * Retrieves the subscription status class |
|
1138 | - * |
|
1139 | - * @since 1.0.19 |
|
1140 | - * @return string |
|
1141 | - */ |
|
1142 | - public function get_status_class() { |
|
1143 | - $statuses = getpaid_get_subscription_status_classes(); |
|
1144 | - return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1145 | - } |
|
1059 | + /** |
|
1060 | + * Retrieves the URL to cancel subscription |
|
1061 | + * |
|
1062 | + * @since 1.0.0 |
|
1063 | + * @return string |
|
1064 | + */ |
|
1065 | + public function get_cancel_url() { |
|
1066 | + $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() ); |
|
1067 | + return apply_filters( 'wpinv_subscription_cancel_url', $url, $this ); |
|
1068 | + } |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * Retrieves the URL to view a subscription |
|
1072 | + * |
|
1073 | + * @since 1.0.19 |
|
1074 | + * @return string |
|
1075 | + */ |
|
1076 | + public function get_view_url() { |
|
1077 | + $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
1078 | + return apply_filters( 'getpaid_get_subscription_view_url', $url, $this ); |
|
1079 | + } |
|
1080 | + |
|
1081 | + /** |
|
1082 | + * Determines if subscription can be manually renewed |
|
1083 | + * |
|
1084 | + * This method is filtered by payment gateways in order to return true on subscriptions |
|
1085 | + * that can be renewed manually |
|
1086 | + * |
|
1087 | + * @since 2.5 |
|
1088 | + * @return bool |
|
1089 | + */ |
|
1090 | + public function can_renew() { |
|
1091 | + return apply_filters( 'wpinv_subscription_can_renew', true, $this ); |
|
1092 | + } |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * Retrieves the URL to renew a subscription |
|
1096 | + * |
|
1097 | + * @since 2.5 |
|
1098 | + * @return string |
|
1099 | + */ |
|
1100 | + public function get_renew_url() { |
|
1101 | + $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' ); |
|
1102 | + return apply_filters( 'wpinv_subscription_renew_url', $url, $this ); |
|
1103 | + } |
|
1104 | + |
|
1105 | + /** |
|
1106 | + * Determines if subscription can have their payment method updated |
|
1107 | + * |
|
1108 | + * @since 1.0.0 |
|
1109 | + * @return bool |
|
1110 | + */ |
|
1111 | + public function can_update() { |
|
1112 | + return apply_filters( 'wpinv_subscription_can_update', false, $this ); |
|
1113 | + } |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * Retrieves the URL to update subscription |
|
1117 | + * |
|
1118 | + * @since 1.0.0 |
|
1119 | + * @return string |
|
1120 | + */ |
|
1121 | + public function get_update_url() { |
|
1122 | + $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) ); |
|
1123 | + return apply_filters( 'wpinv_subscription_update_url', $url, $this ); |
|
1124 | + } |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * Retrieves the subscription status label |
|
1128 | + * |
|
1129 | + * @since 1.0.0 |
|
1130 | + * @return string |
|
1131 | + */ |
|
1132 | + public function get_status_label() { |
|
1133 | + return getpaid_get_subscription_status_label( $this->get_status() ); |
|
1134 | + } |
|
1135 | + |
|
1136 | + /** |
|
1137 | + * Retrieves the subscription status class |
|
1138 | + * |
|
1139 | + * @since 1.0.19 |
|
1140 | + * @return string |
|
1141 | + */ |
|
1142 | + public function get_status_class() { |
|
1143 | + $statuses = getpaid_get_subscription_status_classes(); |
|
1144 | + return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary'; |
|
1145 | + } |
|
1146 | 1146 | |
1147 | 1147 | /** |
1148 | 1148 | * Retrieves the subscription status label |
@@ -1152,11 +1152,11 @@ discard block |
||
1152 | 1152 | */ |
1153 | 1153 | public function get_status_label_html() { |
1154 | 1154 | |
1155 | - $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1156 | - $class = esc_attr( $this->get_status_class() ); |
|
1157 | - $status = sanitize_html_class( $this->get_status_label() ); |
|
1155 | + $status_label = sanitize_text_field( $this->get_status_label() ); |
|
1156 | + $class = esc_attr( $this->get_status_class() ); |
|
1157 | + $status = sanitize_html_class( $this->get_status_label() ); |
|
1158 | 1158 | |
1159 | - return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1159 | + return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>"; |
|
1160 | 1160 | } |
1161 | 1161 | |
1162 | 1162 | /** |
@@ -1167,75 +1167,75 @@ discard block |
||
1167 | 1167 | * @return bool |
1168 | 1168 | */ |
1169 | 1169 | public function payment_exists( $txn_id = '' ) { |
1170 | - $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1170 | + $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' ); |
|
1171 | 1171 | return ! empty( $invoice_id ); |
1172 | - } |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * Handle the status transition. |
|
1176 | - */ |
|
1177 | - protected function status_transition() { |
|
1178 | - $status_transition = $this->status_transition; |
|
1179 | - |
|
1180 | - // Reset status transition variable. |
|
1181 | - $this->status_transition = false; |
|
1182 | - |
|
1183 | - if ( $status_transition ) { |
|
1184 | - try { |
|
1185 | - |
|
1186 | - // Fire a hook for the status change. |
|
1187 | - do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1188 | - do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1189 | - |
|
1190 | - if ( ! empty( $status_transition['from'] ) ) { |
|
1191 | - |
|
1192 | - /* translators: 1: old subscription status 2: new subscription status */ |
|
1193 | - $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1194 | - |
|
1195 | - // Note the transition occurred. |
|
1196 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1197 | - |
|
1198 | - // Fire another hook. |
|
1199 | - do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1200 | - do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1201 | - |
|
1202 | - } else { |
|
1203 | - /* translators: %s: new invoice status */ |
|
1204 | - $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1205 | - |
|
1206 | - // Note the transition occurred. |
|
1207 | - $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1208 | - |
|
1209 | - } |
|
1210 | - } catch ( Exception $e ) { |
|
1211 | - $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1212 | - } |
|
1213 | - } |
|
1214 | - |
|
1215 | - } |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * Save data to the database. |
|
1219 | - * |
|
1220 | - * @since 1.0.19 |
|
1221 | - * @return int subscription ID |
|
1222 | - */ |
|
1223 | - public function save() { |
|
1224 | - parent::save(); |
|
1225 | - $this->status_transition(); |
|
1226 | - return $this->get_id(); |
|
1227 | - } |
|
1228 | - |
|
1229 | - /** |
|
1230 | - * Activates a subscription. |
|
1231 | - * |
|
1232 | - * @since 1.0.19 |
|
1233 | - * @return int subscription ID |
|
1234 | - */ |
|
1235 | - public function activate() { |
|
1236 | - $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
1237 | - $this->set_status( $status ); |
|
1238 | - return $this->save(); |
|
1239 | - } |
|
1172 | + } |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * Handle the status transition. |
|
1176 | + */ |
|
1177 | + protected function status_transition() { |
|
1178 | + $status_transition = $this->status_transition; |
|
1179 | + |
|
1180 | + // Reset status transition variable. |
|
1181 | + $this->status_transition = false; |
|
1182 | + |
|
1183 | + if ( $status_transition ) { |
|
1184 | + try { |
|
1185 | + |
|
1186 | + // Fire a hook for the status change. |
|
1187 | + do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition ); |
|
1188 | + do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition ); |
|
1189 | + |
|
1190 | + if ( ! empty( $status_transition['from'] ) ) { |
|
1191 | + |
|
1192 | + /* translators: 1: old subscription status 2: new subscription status */ |
|
1193 | + $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1194 | + |
|
1195 | + // Note the transition occurred. |
|
1196 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1197 | + |
|
1198 | + // Fire another hook. |
|
1199 | + do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this ); |
|
1200 | + do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] ); |
|
1201 | + |
|
1202 | + } else { |
|
1203 | + /* translators: %s: new invoice status */ |
|
1204 | + $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) ); |
|
1205 | + |
|
1206 | + // Note the transition occurred. |
|
1207 | + $this->get_parent_payment()->add_note( $transition_note, false, false, true ); |
|
1208 | + |
|
1209 | + } |
|
1210 | + } catch ( Exception $e ) { |
|
1211 | + $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() ); |
|
1212 | + } |
|
1213 | + } |
|
1214 | + |
|
1215 | + } |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * Save data to the database. |
|
1219 | + * |
|
1220 | + * @since 1.0.19 |
|
1221 | + * @return int subscription ID |
|
1222 | + */ |
|
1223 | + public function save() { |
|
1224 | + parent::save(); |
|
1225 | + $this->status_transition(); |
|
1226 | + return $this->get_id(); |
|
1227 | + } |
|
1228 | + |
|
1229 | + /** |
|
1230 | + * Activates a subscription. |
|
1231 | + * |
|
1232 | + * @since 1.0.19 |
|
1233 | + * @return int subscription ID |
|
1234 | + */ |
|
1235 | + public function activate() { |
|
1236 | + $status = 'trialling' == $this->get_status() ? 'trialling' : 'active'; |
|
1237 | + $this->set_status( $status ); |
|
1238 | + return $this->save(); |
|
1239 | + } |
|
1240 | 1240 | |
1241 | 1241 | } |
@@ -13,58 +13,58 @@ discard block |
||
13 | 13 | class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway { |
14 | 14 | |
15 | 15 | /** |
16 | - * Payment method id. |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
16 | + * Payment method id. |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | 20 | public $id = 'authorizenet'; |
21 | 21 | |
22 | 22 | /** |
23 | - * An array of features that this gateway supports. |
|
24 | - * |
|
25 | - * @var array |
|
26 | - */ |
|
23 | + * An array of features that this gateway supports. |
|
24 | + * |
|
25 | + * @var array |
|
26 | + */ |
|
27 | 27 | protected $supports = array( 'subscription', 'sandbox', 'tokens' ); |
28 | 28 | |
29 | 29 | /** |
30 | - * Payment method order. |
|
31 | - * |
|
32 | - * @var int |
|
33 | - */ |
|
30 | + * Payment method order. |
|
31 | + * |
|
32 | + * @var int |
|
33 | + */ |
|
34 | 34 | public $order = 4; |
35 | 35 | |
36 | 36 | /** |
37 | - * Endpoint for requests from Authorize.net. |
|
38 | - * |
|
39 | - * @var string |
|
40 | - */ |
|
41 | - protected $notify_url; |
|
42 | - |
|
43 | - /** |
|
44 | - * Endpoint for requests to Authorize.net. |
|
45 | - * |
|
46 | - * @var string |
|
47 | - */ |
|
37 | + * Endpoint for requests from Authorize.net. |
|
38 | + * |
|
39 | + * @var string |
|
40 | + */ |
|
41 | + protected $notify_url; |
|
42 | + |
|
43 | + /** |
|
44 | + * Endpoint for requests to Authorize.net. |
|
45 | + * |
|
46 | + * @var string |
|
47 | + */ |
|
48 | 48 | protected $endpoint; |
49 | 49 | |
50 | 50 | /** |
51 | - * Currencies this gateway is allowed for. |
|
52 | - * |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
51 | + * Currencies this gateway is allowed for. |
|
52 | + * |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' ); |
|
56 | 56 | |
57 | 57 | /** |
58 | - * URL to view a transaction. |
|
59 | - * |
|
60 | - * @var string |
|
61 | - */ |
|
58 | + * URL to view a transaction. |
|
59 | + * |
|
60 | + * @var string |
|
61 | + */ |
|
62 | 62 | public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s'; |
63 | 63 | |
64 | 64 | /** |
65 | - * Class constructor. |
|
66 | - */ |
|
67 | - public function __construct() { |
|
65 | + * Class constructor. |
|
66 | + */ |
|
67 | + public function __construct() { |
|
68 | 68 | |
69 | 69 | $this->title = __( 'Credit Card / Debit Card', 'invoicing' ); |
70 | 70 | $this->method_title = __( 'Authorize.Net', 'invoicing' ); |
@@ -76,11 +76,11 @@ discard block |
||
76 | 76 | } |
77 | 77 | |
78 | 78 | /** |
79 | - * Displays the payment method select field. |
|
80 | - * |
|
81 | - * @param int $invoice_id 0 or invoice id. |
|
82 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | - */ |
|
79 | + * Displays the payment method select field. |
|
80 | + * |
|
81 | + * @param int $invoice_id 0 or invoice id. |
|
82 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
83 | + */ |
|
84 | 84 | public function payment_fields( $invoice_id, $form ) { |
85 | 85 | |
86 | 86 | // Let the user select a payment method. |
@@ -91,16 +91,16 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
94 | - * Creates a customer profile. |
|
95 | - * |
|
96 | - * |
|
97 | - * @param WPInv_Invoice $invoice Invoice. |
|
94 | + * Creates a customer profile. |
|
95 | + * |
|
96 | + * |
|
97 | + * @param WPInv_Invoice $invoice Invoice. |
|
98 | 98 | * @param array $submission_data Posted checkout fields. |
99 | 99 | * @param bool $save Whether or not to save the payment as a token. |
100 | 100 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
101 | - * @return string|WP_Error Payment profile id. |
|
102 | - */ |
|
103 | - public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
101 | + * @return string|WP_Error Payment profile id. |
|
102 | + */ |
|
103 | + public function create_customer_profile( $invoice, $submission_data, $save = true ) { |
|
104 | 104 | |
105 | 105 | // Remove non-digits from the number |
106 | 106 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -167,14 +167,14 @@ discard block |
||
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
170 | - * Retrieves a customer profile. |
|
171 | - * |
|
172 | - * |
|
173 | - * @param string $profile_id profile id. |
|
174 | - * @return string|WP_Error Profile id. |
|
170 | + * Retrieves a customer profile. |
|
171 | + * |
|
172 | + * |
|
173 | + * @param string $profile_id profile id. |
|
174 | + * @return string|WP_Error Profile id. |
|
175 | 175 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile |
176 | - */ |
|
177 | - public function get_customer_profile( $profile_id ) { |
|
176 | + */ |
|
177 | + public function get_customer_profile( $profile_id ) { |
|
178 | 178 | |
179 | 179 | // Generate args. |
180 | 180 | $args = array( |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
192 | - * Creates a customer profile. |
|
193 | - * |
|
194 | - * |
|
192 | + * Creates a customer profile. |
|
193 | + * |
|
194 | + * |
|
195 | 195 | * @param string $profile_id profile id. |
196 | - * @param WPInv_Invoice $invoice Invoice. |
|
196 | + * @param WPInv_Invoice $invoice Invoice. |
|
197 | 197 | * @param array $submission_data Posted checkout fields. |
198 | 198 | * @param bool $save Whether or not to save the payment as a token. |
199 | 199 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile |
200 | - * @return string|WP_Error Profile id. |
|
201 | - */ |
|
202 | - public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
200 | + * @return string|WP_Error Profile id. |
|
201 | + */ |
|
202 | + public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) { |
|
203 | 203 | |
204 | 204 | // Remove non-digits from the number |
205 | 205 | $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] ); |
@@ -259,15 +259,15 @@ discard block |
||
259 | 259 | } |
260 | 260 | |
261 | 261 | /** |
262 | - * Retrieves a customer payment profile. |
|
263 | - * |
|
264 | - * |
|
265 | - * @param string $customer_profile_id customer profile id. |
|
262 | + * Retrieves a customer payment profile. |
|
263 | + * |
|
264 | + * |
|
265 | + * @param string $customer_profile_id customer profile id. |
|
266 | 266 | * @param string $payment_profile_id payment profile id. |
267 | - * @return string|WP_Error Profile id. |
|
267 | + * @return string|WP_Error Profile id. |
|
268 | 268 | * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile |
269 | - */ |
|
270 | - public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
269 | + */ |
|
270 | + public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) { |
|
271 | 271 | |
272 | 272 | // Generate args. |
273 | 273 | $args = array( |
@@ -283,15 +283,15 @@ discard block |
||
283 | 283 | } |
284 | 284 | |
285 | 285 | /** |
286 | - * Charges a customer payment profile. |
|
287 | - * |
|
286 | + * Charges a customer payment profile. |
|
287 | + * |
|
288 | 288 | * @param string $customer_profile_id customer profile id. |
289 | 289 | * @param string $payment_profile_id payment profile id. |
290 | - * @param WPInv_Invoice $invoice Invoice. |
|
290 | + * @param WPInv_Invoice $invoice Invoice. |
|
291 | 291 | * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile |
292 | - * @return WP_Error|object |
|
293 | - */ |
|
294 | - public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
292 | + * @return WP_Error|object |
|
293 | + */ |
|
294 | + public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) { |
|
295 | 295 | |
296 | 296 | // Generate args. |
297 | 297 | $args = array( |
@@ -333,41 +333,41 @@ discard block |
||
333 | 333 | } |
334 | 334 | |
335 | 335 | /** |
336 | - * Processes a customer charge. |
|
337 | - * |
|
336 | + * Processes a customer charge. |
|
337 | + * |
|
338 | 338 | * @param stdClass $result Api response. |
339 | - * @param WPInv_Invoice $invoice Invoice. |
|
340 | - */ |
|
341 | - public function process_charge_response( $result, $invoice ) { |
|
339 | + * @param WPInv_Invoice $invoice Invoice. |
|
340 | + */ |
|
341 | + public function process_charge_response( $result, $invoice ) { |
|
342 | 342 | |
343 | 343 | wpinv_clear_errors(); |
344 | - $response_code = (int) $result->transactionResponse->responseCode; |
|
344 | + $response_code = (int) $result->transactionResponse->responseCode; |
|
345 | 345 | |
346 | - // Succeeded. |
|
347 | - if ( 1 == $response_code || 4 == $response_code ) { |
|
346 | + // Succeeded. |
|
347 | + if ( 1 == $response_code || 4 == $response_code ) { |
|
348 | 348 | |
349 | - // Maybe set a transaction id. |
|
350 | - if ( ! empty( $result->transactionResponse->transId ) ) { |
|
351 | - $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
352 | - } |
|
349 | + // Maybe set a transaction id. |
|
350 | + if ( ! empty( $result->transactionResponse->transId ) ) { |
|
351 | + $invoice->set_transaction_id( $result->transactionResponse->transId ); |
|
352 | + } |
|
353 | 353 | |
354 | - $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
354 | + $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true ); |
|
355 | 355 | |
356 | - if ( 1 == $response_code ) { |
|
357 | - return $invoice->mark_paid(); |
|
358 | - } |
|
356 | + if ( 1 == $response_code ) { |
|
357 | + return $invoice->mark_paid(); |
|
358 | + } |
|
359 | 359 | |
360 | - $invoice->set_status( 'wpi-onhold' ); |
|
361 | - $invoice->add_note( |
|
360 | + $invoice->set_status( 'wpi-onhold' ); |
|
361 | + $invoice->add_note( |
|
362 | 362 | sprintf( |
363 | 363 | __( 'Held for review: %s', 'invoicing' ), |
364 | 364 | $result->transactionResponse->messages->message[0]->description |
365 | 365 | ) |
366 | - ); |
|
366 | + ); |
|
367 | 367 | |
368 | - return $invoice->save(); |
|
368 | + return $invoice->save(); |
|
369 | 369 | |
370 | - } |
|
370 | + } |
|
371 | 371 | |
372 | 372 | wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) ); |
373 | 373 | |
@@ -379,13 +379,13 @@ discard block |
||
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
382 | - * Returns payment information. |
|
383 | - * |
|
384 | - * |
|
385 | - * @param array $card Card details. |
|
386 | - * @return array |
|
387 | - */ |
|
388 | - public function get_payment_information( $card ) { |
|
382 | + * Returns payment information. |
|
383 | + * |
|
384 | + * |
|
385 | + * @param array $card Card details. |
|
386 | + * @return array |
|
387 | + */ |
|
388 | + public function get_payment_information( $card ) { |
|
389 | 389 | return array( |
390 | 390 | |
391 | 391 | 'creditCard' => array ( |
@@ -398,25 +398,25 @@ discard block |
||
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
401 | - * Returns the customer profile meta name. |
|
402 | - * |
|
403 | - * |
|
404 | - * @param WPInv_Invoice $invoice Invoice. |
|
405 | - * @return string |
|
406 | - */ |
|
407 | - public function get_customer_profile_meta_name( $invoice ) { |
|
401 | + * Returns the customer profile meta name. |
|
402 | + * |
|
403 | + * |
|
404 | + * @param WPInv_Invoice $invoice Invoice. |
|
405 | + * @return string |
|
406 | + */ |
|
407 | + public function get_customer_profile_meta_name( $invoice ) { |
|
408 | 408 | return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id'; |
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |
412 | - * Validates the submitted data. |
|
413 | - * |
|
414 | - * |
|
415 | - * @param array $submission_data Posted checkout fields. |
|
412 | + * Validates the submitted data. |
|
413 | + * |
|
414 | + * |
|
415 | + * @param array $submission_data Posted checkout fields. |
|
416 | 416 | * @param WPInv_Invoice $invoice |
417 | - * @return WP_Error|string The payment profile id |
|
418 | - */ |
|
419 | - public function validate_submission_data( $submission_data, $invoice ) { |
|
417 | + * @return WP_Error|string The payment profile id |
|
418 | + */ |
|
419 | + public function validate_submission_data( $submission_data, $invoice ) { |
|
420 | 420 | |
421 | 421 | // Validate authentication details. |
422 | 422 | $auth = $this->get_auth_params(); |
@@ -448,13 +448,13 @@ discard block |
||
448 | 448 | } |
449 | 449 | |
450 | 450 | /** |
451 | - * Returns invoice line items. |
|
452 | - * |
|
453 | - * |
|
454 | - * @param WPInv_Invoice $invoice Invoice. |
|
455 | - * @return array |
|
456 | - */ |
|
457 | - public function get_line_items( $invoice ) { |
|
451 | + * Returns invoice line items. |
|
452 | + * |
|
453 | + * |
|
454 | + * @param WPInv_Invoice $invoice Invoice. |
|
455 | + * @return array |
|
456 | + */ |
|
457 | + public function get_line_items( $invoice ) { |
|
458 | 458 | $items = array(); |
459 | 459 | |
460 | 460 | foreach ( $invoice->get_items() as $item ) { |
@@ -474,15 +474,15 @@ discard block |
||
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
477 | - * Process Payment. |
|
478 | - * |
|
479 | - * |
|
480 | - * @param WPInv_Invoice $invoice Invoice. |
|
481 | - * @param array $submission_data Posted checkout fields. |
|
482 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
483 | - * @return array |
|
484 | - */ |
|
485 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
477 | + * Process Payment. |
|
478 | + * |
|
479 | + * |
|
480 | + * @param WPInv_Invoice $invoice Invoice. |
|
481 | + * @param array $submission_data Posted checkout fields. |
|
482 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
483 | + * @return array |
|
484 | + */ |
|
485 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
486 | 486 | |
487 | 487 | // Validate the submitted data. |
488 | 488 | $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice ); |
@@ -515,69 +515,69 @@ discard block |
||
515 | 515 | |
516 | 516 | exit; |
517 | 517 | |
518 | - } |
|
518 | + } |
|
519 | 519 | |
520 | - /** |
|
521 | - * Processes the initial payment. |
|
522 | - * |
|
520 | + /** |
|
521 | + * Processes the initial payment. |
|
522 | + * |
|
523 | 523 | * @param WPInv_Invoice $invoice Invoice. |
524 | - */ |
|
525 | - protected function process_initial_payment( $invoice ) { |
|
524 | + */ |
|
525 | + protected function process_initial_payment( $invoice ) { |
|
526 | 526 | |
527 | - $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
527 | + $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
528 | 528 | $customer_profile = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true ); |
529 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
529 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice ); |
|
530 | 530 | |
531 | - // Do we have an error? |
|
532 | - if ( is_wp_error( $result ) ) { |
|
533 | - wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
534 | - wpinv_send_back_to_checkout(); |
|
535 | - } |
|
531 | + // Do we have an error? |
|
532 | + if ( is_wp_error( $result ) ) { |
|
533 | + wpinv_set_error( $result->get_error_code(), $result->get_error_message() ); |
|
534 | + wpinv_send_back_to_checkout(); |
|
535 | + } |
|
536 | 536 | |
537 | - // Process the response. |
|
538 | - $this->process_charge_response( $result, $invoice ); |
|
537 | + // Process the response. |
|
538 | + $this->process_charge_response( $result, $invoice ); |
|
539 | 539 | |
540 | - if ( wpinv_get_errors() ) { |
|
541 | - wpinv_send_back_to_checkout(); |
|
542 | - } |
|
540 | + if ( wpinv_get_errors() ) { |
|
541 | + wpinv_send_back_to_checkout(); |
|
542 | + } |
|
543 | 543 | |
544 | - } |
|
544 | + } |
|
545 | 545 | |
546 | 546 | /** |
547 | - * Processes recurring payments. |
|
548 | - * |
|
547 | + * Processes recurring payments. |
|
548 | + * |
|
549 | 549 | * @param WPInv_Invoice $invoice Invoice. |
550 | 550 | * @param WPInv_Subscription $subscription Subscription. |
551 | - */ |
|
552 | - public function process_subscription( $invoice, $subscription ) { |
|
551 | + */ |
|
552 | + public function process_subscription( $invoice, $subscription ) { |
|
553 | 553 | |
554 | 554 | // Check if there is an initial amount to charge. |
555 | 555 | if ( (float) $invoice->get_total() > 0 ) { |
556 | - $this->process_initial_payment( $invoice ); |
|
556 | + $this->process_initial_payment( $invoice ); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | // Activate the subscription. |
560 | 560 | $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
561 | 561 | $expiry = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ); |
562 | 562 | |
563 | - $subscription->set_next_renewal_date( $expiry ); |
|
564 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
565 | - $subscription->set_profile_id( $invoice->generate_key() ); |
|
566 | - $subscription->activate(); |
|
563 | + $subscription->set_next_renewal_date( $expiry ); |
|
564 | + $subscription->set_date_created( current_time( 'mysql' ) ); |
|
565 | + $subscription->set_profile_id( $invoice->generate_key() ); |
|
566 | + $subscription->activate(); |
|
567 | 567 | |
568 | - // Redirect to the success page. |
|
568 | + // Redirect to the success page. |
|
569 | 569 | wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
570 | 570 | |
571 | 571 | } |
572 | 572 | |
573 | - /** |
|
574 | - * (Maybe) renews an authorize.net subscription profile. |
|
575 | - * |
|
576 | - * |
|
577 | - * @param bool $should_expire |
|
573 | + /** |
|
574 | + * (Maybe) renews an authorize.net subscription profile. |
|
575 | + * |
|
576 | + * |
|
577 | + * @param bool $should_expire |
|
578 | 578 | * @param WPInv_Subscription $subscription |
579 | - */ |
|
580 | - public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
579 | + */ |
|
580 | + public function maybe_renew_subscription( $should_expire, $subscription ) { |
|
581 | 581 | |
582 | 582 | // Ensure its our subscription && it's active. |
583 | 583 | if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) { |
@@ -594,18 +594,18 @@ discard block |
||
594 | 594 | |
595 | 595 | return false; |
596 | 596 | |
597 | - } |
|
597 | + } |
|
598 | 598 | |
599 | 599 | /** |
600 | - * Renews a subscription. |
|
601 | - * |
|
600 | + * Renews a subscription. |
|
601 | + * |
|
602 | 602 | * @param WPInv_Subscription $subscription |
603 | - */ |
|
604 | - public function renew_subscription( $subscription ) { |
|
603 | + */ |
|
604 | + public function renew_subscription( $subscription ) { |
|
605 | 605 | |
606 | - // Generate the renewal invoice. |
|
607 | - $new_invoice = $subscription->create_payment(); |
|
608 | - $old_invoice = $subscription->get_parent_payment(); |
|
606 | + // Generate the renewal invoice. |
|
607 | + $new_invoice = $subscription->create_payment(); |
|
608 | + $old_invoice = $subscription->get_parent_payment(); |
|
609 | 609 | |
610 | 610 | if ( empty( $new_invoice ) ) { |
611 | 611 | $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false ); |
@@ -614,37 +614,37 @@ discard block |
||
614 | 614 | } |
615 | 615 | |
616 | 616 | // Charge the payment method. |
617 | - $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
618 | - $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
619 | - $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
620 | - |
|
621 | - // Do we have an error? |
|
622 | - if ( is_wp_error( $result ) ) { |
|
623 | - |
|
624 | - $old_invoice->add_note( |
|
625 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
626 | - true, |
|
627 | - false, |
|
628 | - true |
|
629 | - ); |
|
630 | - $subscription->failing(); |
|
631 | - return; |
|
632 | - |
|
633 | - } |
|
634 | - |
|
635 | - // Process the response. |
|
636 | - $this->process_charge_response( $result, $new_invoice ); |
|
637 | - |
|
638 | - if ( wpinv_get_errors() ) { |
|
639 | - |
|
640 | - $old_invoice->add_note( |
|
641 | - sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
642 | - true, |
|
643 | - false, |
|
644 | - true |
|
645 | - ); |
|
646 | - $subscription->failing(); |
|
647 | - return; |
|
617 | + $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true ); |
|
618 | + $customer_profile = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true ); |
|
619 | + $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice ); |
|
620 | + |
|
621 | + // Do we have an error? |
|
622 | + if ( is_wp_error( $result ) ) { |
|
623 | + |
|
624 | + $old_invoice->add_note( |
|
625 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ), |
|
626 | + true, |
|
627 | + false, |
|
628 | + true |
|
629 | + ); |
|
630 | + $subscription->failing(); |
|
631 | + return; |
|
632 | + |
|
633 | + } |
|
634 | + |
|
635 | + // Process the response. |
|
636 | + $this->process_charge_response( $result, $new_invoice ); |
|
637 | + |
|
638 | + if ( wpinv_get_errors() ) { |
|
639 | + |
|
640 | + $old_invoice->add_note( |
|
641 | + sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ), |
|
642 | + true, |
|
643 | + false, |
|
644 | + true |
|
645 | + ); |
|
646 | + $subscription->failing(); |
|
647 | + return; |
|
648 | 648 | |
649 | 649 | } |
650 | 650 | |
@@ -670,11 +670,11 @@ discard block |
||
670 | 670 | } |
671 | 671 | |
672 | 672 | /** |
673 | - * Filters the gateway settings. |
|
674 | - * |
|
675 | - * @param array $admin_settings |
|
676 | - */ |
|
677 | - public function admin_settings( $admin_settings ) { |
|
673 | + * Filters the gateway settings. |
|
674 | + * |
|
675 | + * @param array $admin_settings |
|
676 | + */ |
|
677 | + public function admin_settings( $admin_settings ) { |
|
678 | 678 | |
679 | 679 | $currencies = sprintf( |
680 | 680 | __( 'Supported Currencies: %s', 'invoicing' ), |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | 'readonly' => true, |
715 | 715 | ); |
716 | 716 | |
717 | - return $admin_settings; |
|
718 | - } |
|
717 | + return $admin_settings; |
|
718 | + } |
|
719 | 719 | |
720 | 720 | } |
@@ -12,443 +12,443 @@ |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Invoice_Notification_Emails { |
14 | 14 | |
15 | - /** |
|
16 | - * The array of invoice email actions. |
|
17 | - * |
|
18 | - * @param array |
|
19 | - */ |
|
20 | - public $invoice_actions; |
|
21 | - |
|
22 | - /** |
|
23 | - * Class constructor |
|
24 | - * |
|
25 | - */ |
|
26 | - public function __construct() { |
|
27 | - |
|
28 | - $this->invoice_actions = apply_filters( |
|
29 | - 'getpaid_notification_email_invoice_triggers', |
|
30 | - array( |
|
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | - 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | - 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | - 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | - 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | - 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | - 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | - 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | - 'getpaid_new_customer_note' => 'user_note', |
|
40 | - 'getpaid_daily_maintenance' => 'overdue', |
|
41 | - ) |
|
42 | - ); |
|
43 | - |
|
44 | - $this->init_hooks(); |
|
45 | - |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Registers email hooks. |
|
50 | - */ |
|
51 | - public function init_hooks() { |
|
52 | - |
|
53 | - add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | - add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | - |
|
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Registers an email hook for an invoice action. |
|
63 | - * |
|
64 | - * @param string $hook |
|
65 | - * @param string|array $email_type |
|
66 | - */ |
|
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
68 | - |
|
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
70 | - |
|
71 | - foreach ( $email_type as $type ) { |
|
72 | - |
|
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
74 | - |
|
75 | - // Abort if it is not active. |
|
76 | - if ( ! $email->is_active() ) { |
|
77 | - continue; |
|
78 | - } |
|
79 | - |
|
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | - continue; |
|
83 | - } |
|
84 | - |
|
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type ); |
|
86 | - } |
|
87 | - |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Filters invoice merge tags. |
|
92 | - * |
|
93 | - * @param array $merge_tags |
|
94 | - * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | - */ |
|
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | - |
|
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | - return array_merge( |
|
100 | - $merge_tags, |
|
101 | - $this->get_invoice_merge_tags( $object ) |
|
102 | - ); |
|
103 | - } |
|
104 | - |
|
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | - return array_merge( |
|
107 | - $merge_tags, |
|
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - return $merge_tags; |
|
113 | - |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Generates invoice merge tags. |
|
118 | - * |
|
119 | - * @param WPInv_Invoice $invoice |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
123 | - |
|
124 | - // Abort if it does not exist. |
|
125 | - if ( ! $invoice->get_id() ) { |
|
126 | - return array(); |
|
127 | - } |
|
128 | - |
|
129 | - return array( |
|
130 | - '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | - '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | - '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | - '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | - '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | - '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | - '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | - '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | - '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | - '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | - '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | - '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | - '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | - '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | - '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | - '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | - '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | - ); |
|
149 | - |
|
150 | - } |
|
151 | - |
|
152 | - /** |
|
153 | - * Helper function to send an email. |
|
154 | - * |
|
155 | - * @param WPInv_Invoice $invoice |
|
156 | - * @param GetPaid_Notification_Email $email |
|
157 | - * @param string $type |
|
158 | - * @param string|array $recipients |
|
159 | - * @param array $extra_args Extra template args. |
|
160 | - */ |
|
161 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | - |
|
163 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | - |
|
165 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | - $merge_tags = $email->get_merge_tags(); |
|
167 | - |
|
168 | - $result = $mailer->send( |
|
169 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | - $email->get_content( $merge_tags, $extra_args ), |
|
172 | - $email->get_attachments() |
|
173 | - ); |
|
174 | - |
|
175 | - // Maybe send a copy to the admin. |
|
176 | - if ( $email->include_admin_bcc() ) { |
|
177 | - $mailer->send( |
|
178 | - wpinv_get_admin_email(), |
|
179 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | - $email->get_content( $merge_tags ), |
|
181 | - $email->get_attachments() |
|
182 | - ); |
|
183 | - } |
|
184 | - |
|
185 | - if ( ! $result ) { |
|
186 | - $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | - } |
|
188 | - |
|
189 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | - |
|
191 | - return $result; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Also send emails to any cc users. |
|
196 | - * |
|
197 | - * @param array $recipients |
|
198 | - * @param GetPaid_Notification_Email $email |
|
199 | - */ |
|
200 | - public function filter_email_recipients( $recipients, $email ) { |
|
201 | - |
|
202 | - if ( ! $email->is_admin_email() ) { |
|
203 | - $cc = $email->object->get_email_cc(); |
|
204 | - |
|
205 | - if ( ! empty( $cc ) ) { |
|
206 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | - } |
|
209 | - |
|
210 | - } |
|
211 | - |
|
212 | - return $recipients; |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * Sends a new invoice notification. |
|
218 | - * |
|
219 | - * @param WPInv_Invoice $invoice |
|
220 | - */ |
|
221 | - public function new_invoice( $invoice ) { |
|
222 | - |
|
223 | - // Only send this email for invoices created via the admin page. |
|
224 | - if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | - return; |
|
226 | - } |
|
227 | - |
|
228 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | - $recipient = wpinv_get_admin_email(); |
|
230 | - |
|
231 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | - |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * Sends a cancelled invoice notification. |
|
237 | - * |
|
238 | - * @param WPInv_Invoice $invoice |
|
239 | - */ |
|
240 | - public function cancelled_invoice( $invoice ) { |
|
15 | + /** |
|
16 | + * The array of invoice email actions. |
|
17 | + * |
|
18 | + * @param array |
|
19 | + */ |
|
20 | + public $invoice_actions; |
|
21 | + |
|
22 | + /** |
|
23 | + * Class constructor |
|
24 | + * |
|
25 | + */ |
|
26 | + public function __construct() { |
|
27 | + |
|
28 | + $this->invoice_actions = apply_filters( |
|
29 | + 'getpaid_notification_email_invoice_triggers', |
|
30 | + array( |
|
31 | + 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
32 | + 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
|
33 | + 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
|
34 | + 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
|
35 | + 'getpaid_invoice_status_wpi-processing' => 'processing_invoice', |
|
36 | + 'getpaid_invoice_status_publish' => 'completed_invoice', |
|
37 | + 'getpaid_invoice_status_wpi-renewal' => 'completed_invoice', |
|
38 | + 'getpaid_invoice_status_wpi-refunded' => 'refunded_invoice', |
|
39 | + 'getpaid_new_customer_note' => 'user_note', |
|
40 | + 'getpaid_daily_maintenance' => 'overdue', |
|
41 | + ) |
|
42 | + ); |
|
43 | + |
|
44 | + $this->init_hooks(); |
|
45 | + |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Registers email hooks. |
|
50 | + */ |
|
51 | + public function init_hooks() { |
|
52 | + |
|
53 | + add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 ); |
|
54 | + add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 ); |
|
55 | + |
|
56 | + foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | + $this->init_email_type_hook( $hook, $email_type ); |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Registers an email hook for an invoice action. |
|
63 | + * |
|
64 | + * @param string $hook |
|
65 | + * @param string|array $email_type |
|
66 | + */ |
|
67 | + public function init_email_type_hook( $hook, $email_type ) { |
|
68 | + |
|
69 | + $email_type = wpinv_parse_list( $email_type ); |
|
70 | + |
|
71 | + foreach ( $email_type as $type ) { |
|
72 | + |
|
73 | + $email = new GetPaid_Notification_Email( $type ); |
|
74 | + |
|
75 | + // Abort if it is not active. |
|
76 | + if ( ! $email->is_active() ) { |
|
77 | + continue; |
|
78 | + } |
|
79 | + |
|
80 | + if ( method_exists( $this, $type ) ) { |
|
81 | + add_action( $hook, array( $this, $type ), 100, 2 ); |
|
82 | + continue; |
|
83 | + } |
|
84 | + |
|
85 | + do_action( 'getpaid_invoice_init_email_type_hook', $type ); |
|
86 | + } |
|
87 | + |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Filters invoice merge tags. |
|
92 | + * |
|
93 | + * @param array $merge_tags |
|
94 | + * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
|
95 | + */ |
|
96 | + public function invoice_merge_tags( $merge_tags, $object ) { |
|
97 | + |
|
98 | + if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
99 | + return array_merge( |
|
100 | + $merge_tags, |
|
101 | + $this->get_invoice_merge_tags( $object ) |
|
102 | + ); |
|
103 | + } |
|
104 | + |
|
105 | + if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
106 | + return array_merge( |
|
107 | + $merge_tags, |
|
108 | + $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + return $merge_tags; |
|
113 | + |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Generates invoice merge tags. |
|
118 | + * |
|
119 | + * @param WPInv_Invoice $invoice |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function get_invoice_merge_tags( $invoice ) { |
|
123 | + |
|
124 | + // Abort if it does not exist. |
|
125 | + if ( ! $invoice->get_id() ) { |
|
126 | + return array(); |
|
127 | + } |
|
128 | + |
|
129 | + return array( |
|
130 | + '{name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
131 | + '{full_name}' => sanitize_text_field( $invoice->get_user_full_name() ), |
|
132 | + '{first_name}' => sanitize_text_field( $invoice->get_first_name() ), |
|
133 | + '{last_name}' => sanitize_text_field( $invoice->get_last_name() ), |
|
134 | + '{email}' => sanitize_email( $invoice->get_email() ), |
|
135 | + '{invoice_number}' => sanitize_text_field( $invoice->get_number() ), |
|
136 | + '{invoice_currency}' => sanitize_text_field( $invoice->get_currency() ), |
|
137 | + '{invoice_total}' => wpinv_price( wpinv_format_amount( $invoice->get_total() ) ), |
|
138 | + '{invoice_link}' => esc_url( $invoice->get_view_url() ), |
|
139 | + '{invoice_pay_link}' => esc_url( $invoice->get_checkout_payment_url() ), |
|
140 | + '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ), |
|
141 | + '{invoice_date}' => getpaid_format_date_value( $invoice->get_date_created() ), |
|
142 | + '{invoice_due_date}' => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ), |
|
143 | + '{invoice_quote}' => sanitize_text_field( $invoice->get_type() ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_type() ) ), |
|
145 | + '{invoice_description}' => wp_kses_post( $invoice->get_description() ), |
|
146 | + '{subscription_name}' => wp_kses_post( $invoice->get_subscription_name() ), |
|
147 | + '{is_was}' => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ), |
|
148 | + ); |
|
149 | + |
|
150 | + } |
|
151 | + |
|
152 | + /** |
|
153 | + * Helper function to send an email. |
|
154 | + * |
|
155 | + * @param WPInv_Invoice $invoice |
|
156 | + * @param GetPaid_Notification_Email $email |
|
157 | + * @param string $type |
|
158 | + * @param string|array $recipients |
|
159 | + * @param array $extra_args Extra template args. |
|
160 | + */ |
|
161 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
162 | + |
|
163 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
164 | + |
|
165 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
166 | + $merge_tags = $email->get_merge_tags(); |
|
167 | + |
|
168 | + $result = $mailer->send( |
|
169 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
170 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
171 | + $email->get_content( $merge_tags, $extra_args ), |
|
172 | + $email->get_attachments() |
|
173 | + ); |
|
174 | + |
|
175 | + // Maybe send a copy to the admin. |
|
176 | + if ( $email->include_admin_bcc() ) { |
|
177 | + $mailer->send( |
|
178 | + wpinv_get_admin_email(), |
|
179 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
180 | + $email->get_content( $merge_tags ), |
|
181 | + $email->get_attachments() |
|
182 | + ); |
|
183 | + } |
|
184 | + |
|
185 | + if ( ! $result ) { |
|
186 | + $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true ); |
|
187 | + } |
|
188 | + |
|
189 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
190 | + |
|
191 | + return $result; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Also send emails to any cc users. |
|
196 | + * |
|
197 | + * @param array $recipients |
|
198 | + * @param GetPaid_Notification_Email $email |
|
199 | + */ |
|
200 | + public function filter_email_recipients( $recipients, $email ) { |
|
201 | + |
|
202 | + if ( ! $email->is_admin_email() ) { |
|
203 | + $cc = $email->object->get_email_cc(); |
|
204 | + |
|
205 | + if ( ! empty( $cc ) ) { |
|
206 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
207 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
208 | + } |
|
209 | + |
|
210 | + } |
|
211 | + |
|
212 | + return $recipients; |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * Sends a new invoice notification. |
|
218 | + * |
|
219 | + * @param WPInv_Invoice $invoice |
|
220 | + */ |
|
221 | + public function new_invoice( $invoice ) { |
|
222 | + |
|
223 | + // Only send this email for invoices created via the admin page. |
|
224 | + if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
225 | + return; |
|
226 | + } |
|
227 | + |
|
228 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
229 | + $recipient = wpinv_get_admin_email(); |
|
230 | + |
|
231 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
232 | + |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * Sends a cancelled invoice notification. |
|
237 | + * |
|
238 | + * @param WPInv_Invoice $invoice |
|
239 | + */ |
|
240 | + public function cancelled_invoice( $invoice ) { |
|
241 | 241 | |
242 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | - $recipient = wpinv_get_admin_email(); |
|
242 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
243 | + $recipient = wpinv_get_admin_email(); |
|
244 | 244 | |
245 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
245 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
246 | 246 | |
247 | - } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
250 | - * Sends a failed invoice notification. |
|
251 | - * |
|
252 | - * @param WPInv_Invoice $invoice |
|
253 | - */ |
|
254 | - public function failed_invoice( $invoice ) { |
|
249 | + /** |
|
250 | + * Sends a failed invoice notification. |
|
251 | + * |
|
252 | + * @param WPInv_Invoice $invoice |
|
253 | + */ |
|
254 | + public function failed_invoice( $invoice ) { |
|
255 | 255 | |
256 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | - $recipient = wpinv_get_admin_email(); |
|
256 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
257 | + $recipient = wpinv_get_admin_email(); |
|
258 | 258 | |
259 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
259 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
260 | 260 | |
261 | - } |
|
261 | + } |
|
262 | 262 | |
263 | - /** |
|
264 | - * Sends a notification whenever an invoice is put on hold. |
|
265 | - * |
|
266 | - * @param WPInv_Invoice $invoice |
|
267 | - */ |
|
268 | - public function onhold_invoice( $invoice ) { |
|
263 | + /** |
|
264 | + * Sends a notification whenever an invoice is put on hold. |
|
265 | + * |
|
266 | + * @param WPInv_Invoice $invoice |
|
267 | + */ |
|
268 | + public function onhold_invoice( $invoice ) { |
|
269 | 269 | |
270 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | - $recipient = $invoice->get_email(); |
|
270 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $recipient = $invoice->get_email(); |
|
272 | 272 | |
273 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
273 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | 274 | |
275 | - } |
|
275 | + } |
|
276 | 276 | |
277 | - /** |
|
278 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | - * |
|
280 | - * @param WPInv_Invoice $invoice |
|
281 | - */ |
|
282 | - public function processing_invoice( $invoice ) { |
|
277 | + /** |
|
278 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
279 | + * |
|
280 | + * @param WPInv_Invoice $invoice |
|
281 | + */ |
|
282 | + public function processing_invoice( $invoice ) { |
|
283 | 283 | |
284 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | - $recipient = $invoice->get_email(); |
|
284 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $recipient = $invoice->get_email(); |
|
286 | 286 | |
287 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
287 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | 288 | |
289 | - } |
|
289 | + } |
|
290 | 290 | |
291 | - /** |
|
292 | - * Sends a notification whenever an invoice is paid. |
|
293 | - * |
|
294 | - * @param WPInv_Invoice $invoice |
|
295 | - */ |
|
296 | - public function completed_invoice( $invoice ) { |
|
291 | + /** |
|
292 | + * Sends a notification whenever an invoice is paid. |
|
293 | + * |
|
294 | + * @param WPInv_Invoice $invoice |
|
295 | + */ |
|
296 | + public function completed_invoice( $invoice ) { |
|
297 | 297 | |
298 | - // (Maybe) abort if it is a renewal invoice. |
|
299 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | - return; |
|
301 | - } |
|
298 | + // (Maybe) abort if it is a renewal invoice. |
|
299 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
300 | + return; |
|
301 | + } |
|
302 | 302 | |
303 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | - $recipient = $invoice->get_email(); |
|
303 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
304 | + $recipient = $invoice->get_email(); |
|
305 | 305 | |
306 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
306 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
307 | 307 | |
308 | - } |
|
308 | + } |
|
309 | 309 | |
310 | - /** |
|
311 | - * Sends a notification whenever an invoice is refunded. |
|
312 | - * |
|
313 | - * @param WPInv_Invoice $invoice |
|
314 | - */ |
|
315 | - public function refunded_invoice( $invoice ) { |
|
310 | + /** |
|
311 | + * Sends a notification whenever an invoice is refunded. |
|
312 | + * |
|
313 | + * @param WPInv_Invoice $invoice |
|
314 | + */ |
|
315 | + public function refunded_invoice( $invoice ) { |
|
316 | 316 | |
317 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | - $recipient = $invoice->get_email(); |
|
317 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
318 | + $recipient = $invoice->get_email(); |
|
319 | 319 | |
320 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
320 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
321 | 321 | |
322 | - } |
|
322 | + } |
|
323 | 323 | |
324 | - /** |
|
325 | - * Notifies a user about new invoices |
|
326 | - * |
|
327 | - * @param WPInv_Invoice $invoice |
|
328 | - */ |
|
329 | - public function user_invoice( $invoice ) { |
|
324 | + /** |
|
325 | + * Notifies a user about new invoices |
|
326 | + * |
|
327 | + * @param WPInv_Invoice $invoice |
|
328 | + */ |
|
329 | + public function user_invoice( $invoice ) { |
|
330 | 330 | |
331 | - // Only send this email for invoices created via the admin page. |
|
332 | - if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | - return; |
|
334 | - } |
|
331 | + // Only send this email for invoices created via the admin page. |
|
332 | + if ( $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
333 | + return; |
|
334 | + } |
|
335 | 335 | |
336 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | - $recipient = $invoice->get_email(); |
|
336 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
337 | + $recipient = $invoice->get_email(); |
|
338 | 338 | |
339 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
339 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
340 | 340 | |
341 | - } |
|
341 | + } |
|
342 | 342 | |
343 | - /** |
|
344 | - * Checks if an invoice is a payment form invoice. |
|
345 | - * |
|
346 | - * @param int $invoice |
|
347 | - * @return bool |
|
348 | - */ |
|
349 | - public function is_payment_form_invoice( $invoice ) { |
|
350 | - return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | - } |
|
343 | + /** |
|
344 | + * Checks if an invoice is a payment form invoice. |
|
345 | + * |
|
346 | + * @param int $invoice |
|
347 | + * @return bool |
|
348 | + */ |
|
349 | + public function is_payment_form_invoice( $invoice ) { |
|
350 | + return empty( $_GET['getpaid-admin-action'] ) && 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ); |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Notifies admin about new invoice notes |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - * @param string $note |
|
358 | - */ |
|
359 | - public function user_note( $invoice, $note ) { |
|
353 | + /** |
|
354 | + * Notifies admin about new invoice notes |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + * @param string $note |
|
358 | + */ |
|
359 | + public function user_note( $invoice, $note ) { |
|
360 | 360 | |
361 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | - $recipient = $invoice->get_email(); |
|
363 | - |
|
364 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | - |
|
366 | - } |
|
361 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
362 | + $recipient = $invoice->get_email(); |
|
363 | + |
|
364 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
365 | + |
|
366 | + } |
|
367 | 367 | |
368 | - /** |
|
369 | - * (Force) Sends overdue notices. |
|
370 | - * |
|
371 | - * @param WPInv_Invoice $invoice |
|
372 | - */ |
|
373 | - public function force_send_overdue_notice( $invoice ) { |
|
374 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | - } |
|
377 | - |
|
378 | - /** |
|
379 | - * Sends overdue notices. |
|
380 | - * |
|
381 | - * @TODO: Create an invoices query class. |
|
382 | - */ |
|
383 | - public function overdue() { |
|
384 | - global $wpdb; |
|
385 | - |
|
386 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | - |
|
388 | - // Fetch reminder days. |
|
389 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | - |
|
391 | - // Abort if non is set. |
|
392 | - if ( empty( $reminder_days ) ) { |
|
393 | - return; |
|
394 | - } |
|
395 | - |
|
396 | - // Retrieve date query. |
|
397 | - $date_query = $this->get_date_query( $reminder_days ); |
|
398 | - |
|
399 | - // Invoices table. |
|
400 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | - |
|
402 | - // Fetch invoices. |
|
403 | - $invoices = $wpdb->get_col( |
|
404 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
368 | + /** |
|
369 | + * (Force) Sends overdue notices. |
|
370 | + * |
|
371 | + * @param WPInv_Invoice $invoice |
|
372 | + */ |
|
373 | + public function force_send_overdue_notice( $invoice ) { |
|
374 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
375 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
376 | + } |
|
377 | + |
|
378 | + /** |
|
379 | + * Sends overdue notices. |
|
380 | + * |
|
381 | + * @TODO: Create an invoices query class. |
|
382 | + */ |
|
383 | + public function overdue() { |
|
384 | + global $wpdb; |
|
385 | + |
|
386 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
387 | + |
|
388 | + // Fetch reminder days. |
|
389 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
390 | + |
|
391 | + // Abort if non is set. |
|
392 | + if ( empty( $reminder_days ) ) { |
|
393 | + return; |
|
394 | + } |
|
395 | + |
|
396 | + // Retrieve date query. |
|
397 | + $date_query = $this->get_date_query( $reminder_days ); |
|
398 | + |
|
399 | + // Invoices table. |
|
400 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
401 | + |
|
402 | + // Fetch invoices. |
|
403 | + $invoices = $wpdb->get_col( |
|
404 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
405 | 405 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
406 | 406 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
407 | 407 | |
408 | - foreach ( $invoices as $invoice ) { |
|
408 | + foreach ( $invoices as $invoice ) { |
|
409 | 409 | |
410 | - // Only send this email for invoices created via the admin page. |
|
411 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | - $invoice = new WPInv_Invoice( $invoice ); |
|
413 | - $email->object = $invoice; |
|
410 | + // Only send this email for invoices created via the admin page. |
|
411 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
412 | + $invoice = new WPInv_Invoice( $invoice ); |
|
413 | + $email->object = $invoice; |
|
414 | 414 | |
415 | - if ( $invoice->needs_payment() ) { |
|
416 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | - } |
|
415 | + if ( $invoice->needs_payment() ) { |
|
416 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
417 | + } |
|
418 | 418 | |
419 | - } |
|
419 | + } |
|
420 | 420 | |
421 | - } |
|
421 | + } |
|
422 | 422 | |
423 | - } |
|
423 | + } |
|
424 | 424 | |
425 | - /** |
|
426 | - * Calculates the date query for an invoices query |
|
427 | - * |
|
428 | - * @param array $reminder_days |
|
429 | - * @return string |
|
430 | - */ |
|
431 | - public function get_date_query( $reminder_days ) { |
|
425 | + /** |
|
426 | + * Calculates the date query for an invoices query |
|
427 | + * |
|
428 | + * @param array $reminder_days |
|
429 | + * @return string |
|
430 | + */ |
|
431 | + public function get_date_query( $reminder_days ) { |
|
432 | 432 | |
433 | - $date_query = array( |
|
434 | - 'relation' => 'OR' |
|
435 | - ); |
|
433 | + $date_query = array( |
|
434 | + 'relation' => 'OR' |
|
435 | + ); |
|
436 | 436 | |
437 | - foreach ( $reminder_days as $days ) { |
|
438 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
437 | + foreach ( $reminder_days as $days ) { |
|
438 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
439 | 439 | |
440 | - $date_query[] = array( |
|
441 | - 'year' => $date['year'], |
|
442 | - 'month' => $date['month'], |
|
443 | - 'day' => $date['day'], |
|
444 | - ); |
|
440 | + $date_query[] = array( |
|
441 | + 'year' => $date['year'], |
|
442 | + 'month' => $date['month'], |
|
443 | + 'day' => $date['day'], |
|
444 | + ); |
|
445 | 445 | |
446 | - } |
|
446 | + } |
|
447 | 447 | |
448 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
448 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
449 | 449 | |
450 | - return $date_query->get_sql(); |
|
450 | + return $date_query->get_sql(); |
|
451 | 451 | |
452 | - } |
|
452 | + } |
|
453 | 453 | |
454 | 454 | } |
@@ -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,1012 +11,1012 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Input { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function input($args = array()){ |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'text', |
|
24 | - 'name' => '', |
|
25 | - 'class' => '', |
|
26 | - 'wrap_class' => '', |
|
27 | - 'id' => '', |
|
28 | - 'placeholder'=> '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'required' => false, |
|
32 | - 'label' => '', |
|
33 | - 'label_after'=> false, |
|
34 | - 'label_class'=> '', |
|
35 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | - 'help_text' => '', |
|
37 | - 'validation_text' => '', |
|
38 | - 'validation_pattern' => '', |
|
39 | - 'no_wrap' => false, |
|
40 | - 'input_group_right' => '', |
|
41 | - 'input_group_left' => '', |
|
42 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | - 'step' => '', |
|
45 | - 'switch' => false, // to show checkbox as a switch |
|
46 | - 'checked' => false, // set a checkbox or radio as selected |
|
47 | - 'password_toggle' => true, // toggle view/hide password |
|
48 | - 'element_require' => '', // [%element_id%] == "1" |
|
49 | - 'extra_attributes' => array() // an array of extra attributes |
|
50 | - ); |
|
51 | - |
|
52 | - /** |
|
53 | - * Parse incoming $args into an array and merge it with $defaults |
|
54 | - */ |
|
55 | - $args = wp_parse_args( $args, $defaults ); |
|
56 | - $output = ''; |
|
57 | - if ( ! empty( $args['type'] ) ) { |
|
58 | - // hidden label option needs to be empty |
|
59 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | - |
|
61 | - $type = sanitize_html_class( $args['type'] ); |
|
62 | - |
|
63 | - $help_text = ''; |
|
64 | - $label = ''; |
|
65 | - $label_after = $args['label_after']; |
|
66 | - $label_args = array( |
|
67 | - 'title'=> $args['label'], |
|
68 | - 'for'=> $args['id'], |
|
69 | - 'class' => $args['label_class']." ", |
|
70 | - 'label_type' => $args['label_type'] |
|
71 | - ); |
|
72 | - |
|
73 | - // floating labels need label after |
|
74 | - if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | - $label_after = true; |
|
76 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | - } |
|
78 | - |
|
79 | - // Some special sauce for files |
|
80 | - if($type=='file' ){ |
|
81 | - $label_after = true; // if type file we need the label after |
|
82 | - $args['class'] .= ' custom-file-input '; |
|
83 | - }elseif($type=='checkbox'){ |
|
84 | - $label_after = true; // if type file we need the label after |
|
85 | - $args['class'] .= ' custom-control-input '; |
|
86 | - }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | - $type = 'text'; |
|
88 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | - $args['class'] .= ' bg-initial '; |
|
90 | - |
|
91 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | - // enqueue the script |
|
93 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | - $aui_settings->enqueue_flatpickr(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - // open/type |
|
99 | - $output .= '<input type="' . $type . '" '; |
|
100 | - |
|
101 | - // name |
|
102 | - if(!empty($args['name'])){ |
|
103 | - $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | - } |
|
105 | - |
|
106 | - // id |
|
107 | - if(!empty($args['id'])){ |
|
108 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | - } |
|
110 | - |
|
111 | - // placeholder |
|
112 | - if(!empty($args['placeholder'])){ |
|
113 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | - } |
|
115 | - |
|
116 | - // title |
|
117 | - if(!empty($args['title'])){ |
|
118 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | - } |
|
120 | - |
|
121 | - // value |
|
122 | - if(!empty($args['value'])){ |
|
123 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | - } |
|
125 | - |
|
126 | - // checked, for radio and checkboxes |
|
127 | - if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | - $output .= ' checked '; |
|
129 | - } |
|
130 | - |
|
131 | - // validation text |
|
132 | - if(!empty($args['validation_text'])){ |
|
133 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | - } |
|
136 | - |
|
137 | - // validation_pattern |
|
138 | - if(!empty($args['validation_pattern'])){ |
|
139 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | - } |
|
141 | - |
|
142 | - // step (for numbers) |
|
143 | - if(!empty($args['step'])){ |
|
144 | - $output .= ' step="'.$args['step'].'" '; |
|
145 | - } |
|
146 | - |
|
147 | - // required |
|
148 | - if(!empty($args['required'])){ |
|
149 | - $output .= ' required '; |
|
150 | - } |
|
151 | - |
|
152 | - // class |
|
153 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | - $output .= ' class="form-control '.$class.'" '; |
|
155 | - |
|
156 | - // data-attributes |
|
157 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | - |
|
159 | - // extra attributes |
|
160 | - if(!empty($args['extra_attributes'])){ |
|
161 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | - } |
|
163 | - |
|
164 | - // close |
|
165 | - $output .= ' >'; |
|
166 | - |
|
167 | - |
|
168 | - // label |
|
169 | - if(!empty($args['label'])){ |
|
170 | - if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | - elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | - $label = self::label( $label_args, $type ); |
|
173 | - } |
|
174 | - |
|
175 | - // help text |
|
176 | - if(!empty($args['help_text'])){ |
|
177 | - $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - // set help text in the correct possition |
|
182 | - if($label_after){ |
|
183 | - $output .= $label . $help_text; |
|
184 | - } |
|
185 | - |
|
186 | - // some input types need a separate wrap |
|
187 | - if($type == 'file') { |
|
188 | - $output = self::wrap( array( |
|
189 | - 'content' => $output, |
|
190 | - 'class' => 'form-group custom-file' |
|
191 | - ) ); |
|
192 | - }elseif($type == 'checkbox'){ |
|
193 | - $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | - $output = self::wrap( array( |
|
195 | - 'content' => $output, |
|
196 | - 'class' => 'custom-control '.$wrap_class |
|
197 | - ) ); |
|
198 | - |
|
199 | - if($args['label_type']=='horizontal'){ |
|
200 | - $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | - } |
|
202 | - }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | - |
|
204 | - |
|
205 | - // allow password field to toggle view |
|
206 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input($args = array()){ |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'text', |
|
24 | + 'name' => '', |
|
25 | + 'class' => '', |
|
26 | + 'wrap_class' => '', |
|
27 | + 'id' => '', |
|
28 | + 'placeholder'=> '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'required' => false, |
|
32 | + 'label' => '', |
|
33 | + 'label_after'=> false, |
|
34 | + 'label_class'=> '', |
|
35 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | + 'help_text' => '', |
|
37 | + 'validation_text' => '', |
|
38 | + 'validation_pattern' => '', |
|
39 | + 'no_wrap' => false, |
|
40 | + 'input_group_right' => '', |
|
41 | + 'input_group_left' => '', |
|
42 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | + 'step' => '', |
|
45 | + 'switch' => false, // to show checkbox as a switch |
|
46 | + 'checked' => false, // set a checkbox or radio as selected |
|
47 | + 'password_toggle' => true, // toggle view/hide password |
|
48 | + 'element_require' => '', // [%element_id%] == "1" |
|
49 | + 'extra_attributes' => array() // an array of extra attributes |
|
50 | + ); |
|
51 | + |
|
52 | + /** |
|
53 | + * Parse incoming $args into an array and merge it with $defaults |
|
54 | + */ |
|
55 | + $args = wp_parse_args( $args, $defaults ); |
|
56 | + $output = ''; |
|
57 | + if ( ! empty( $args['type'] ) ) { |
|
58 | + // hidden label option needs to be empty |
|
59 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | + |
|
61 | + $type = sanitize_html_class( $args['type'] ); |
|
62 | + |
|
63 | + $help_text = ''; |
|
64 | + $label = ''; |
|
65 | + $label_after = $args['label_after']; |
|
66 | + $label_args = array( |
|
67 | + 'title'=> $args['label'], |
|
68 | + 'for'=> $args['id'], |
|
69 | + 'class' => $args['label_class']." ", |
|
70 | + 'label_type' => $args['label_type'] |
|
71 | + ); |
|
72 | + |
|
73 | + // floating labels need label after |
|
74 | + if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | + $label_after = true; |
|
76 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | + } |
|
78 | + |
|
79 | + // Some special sauce for files |
|
80 | + if($type=='file' ){ |
|
81 | + $label_after = true; // if type file we need the label after |
|
82 | + $args['class'] .= ' custom-file-input '; |
|
83 | + }elseif($type=='checkbox'){ |
|
84 | + $label_after = true; // if type file we need the label after |
|
85 | + $args['class'] .= ' custom-control-input '; |
|
86 | + }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | + $type = 'text'; |
|
88 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | + $args['class'] .= ' bg-initial '; |
|
90 | + |
|
91 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | + // enqueue the script |
|
93 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | + $aui_settings->enqueue_flatpickr(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + // open/type |
|
99 | + $output .= '<input type="' . $type . '" '; |
|
100 | + |
|
101 | + // name |
|
102 | + if(!empty($args['name'])){ |
|
103 | + $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | + } |
|
105 | + |
|
106 | + // id |
|
107 | + if(!empty($args['id'])){ |
|
108 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | + } |
|
110 | + |
|
111 | + // placeholder |
|
112 | + if(!empty($args['placeholder'])){ |
|
113 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | + } |
|
115 | + |
|
116 | + // title |
|
117 | + if(!empty($args['title'])){ |
|
118 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | + } |
|
120 | + |
|
121 | + // value |
|
122 | + if(!empty($args['value'])){ |
|
123 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | + } |
|
125 | + |
|
126 | + // checked, for radio and checkboxes |
|
127 | + if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | + $output .= ' checked '; |
|
129 | + } |
|
130 | + |
|
131 | + // validation text |
|
132 | + if(!empty($args['validation_text'])){ |
|
133 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | + } |
|
136 | + |
|
137 | + // validation_pattern |
|
138 | + if(!empty($args['validation_pattern'])){ |
|
139 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | + } |
|
141 | + |
|
142 | + // step (for numbers) |
|
143 | + if(!empty($args['step'])){ |
|
144 | + $output .= ' step="'.$args['step'].'" '; |
|
145 | + } |
|
146 | + |
|
147 | + // required |
|
148 | + if(!empty($args['required'])){ |
|
149 | + $output .= ' required '; |
|
150 | + } |
|
151 | + |
|
152 | + // class |
|
153 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | + $output .= ' class="form-control '.$class.'" '; |
|
155 | + |
|
156 | + // data-attributes |
|
157 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | + |
|
159 | + // extra attributes |
|
160 | + if(!empty($args['extra_attributes'])){ |
|
161 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | + } |
|
163 | + |
|
164 | + // close |
|
165 | + $output .= ' >'; |
|
166 | + |
|
167 | + |
|
168 | + // label |
|
169 | + if(!empty($args['label'])){ |
|
170 | + if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | + elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | + $label = self::label( $label_args, $type ); |
|
173 | + } |
|
174 | + |
|
175 | + // help text |
|
176 | + if(!empty($args['help_text'])){ |
|
177 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + // set help text in the correct possition |
|
182 | + if($label_after){ |
|
183 | + $output .= $label . $help_text; |
|
184 | + } |
|
185 | + |
|
186 | + // some input types need a separate wrap |
|
187 | + if($type == 'file') { |
|
188 | + $output = self::wrap( array( |
|
189 | + 'content' => $output, |
|
190 | + 'class' => 'form-group custom-file' |
|
191 | + ) ); |
|
192 | + }elseif($type == 'checkbox'){ |
|
193 | + $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | + $output = self::wrap( array( |
|
195 | + 'content' => $output, |
|
196 | + 'class' => 'custom-control '.$wrap_class |
|
197 | + ) ); |
|
198 | + |
|
199 | + if($args['label_type']=='horizontal'){ |
|
200 | + $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | + } |
|
202 | + }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | + |
|
204 | + |
|
205 | + // allow password field to toggle view |
|
206 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
207 | 207 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
208 | 208 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
209 | 209 | if($el.hasClass(\'fa-eye\')) |
210 | 210 | {$eli.attr(\'type\',\'text\');} |
211 | 211 | else{$eli.attr(\'type\',\'password\');}" |
212 | 212 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
213 | - } |
|
214 | - |
|
215 | - // input group wraps |
|
216 | - if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | - $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | - if($args['input_group_left']){ |
|
219 | - $output = self::wrap( array( |
|
220 | - 'content' => $output, |
|
221 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | - 'input_group_left' => $args['input_group_left'], |
|
223 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | - ) ); |
|
225 | - } |
|
226 | - if($args['input_group_right']){ |
|
227 | - $output = self::wrap( array( |
|
228 | - 'content' => $output, |
|
229 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | - 'input_group_right' => $args['input_group_right'], |
|
231 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | - ) ); |
|
233 | - } |
|
234 | - |
|
235 | - } |
|
236 | - |
|
237 | - if(!$label_after){ |
|
238 | - $output .= $help_text; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | - $output = self::wrap( array( |
|
244 | - 'content' => $output, |
|
245 | - 'class' => 'col-sm-10', |
|
246 | - ) ); |
|
247 | - } |
|
248 | - |
|
249 | - if(!$label_after){ |
|
250 | - $output = $label . $output; |
|
251 | - } |
|
252 | - |
|
253 | - // wrap |
|
254 | - if(!$args['no_wrap']){ |
|
255 | - |
|
256 | - $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | - $output = self::wrap(array( |
|
260 | - 'content' => $output, |
|
261 | - 'class' => $wrap_class, |
|
262 | - 'element_require' => $args['element_require'], |
|
263 | - 'argument_id' => $args['id'] |
|
264 | - )); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - } |
|
270 | - |
|
271 | - return $output; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Build the component. |
|
276 | - * |
|
277 | - * @param array $args |
|
278 | - * |
|
279 | - * @return string The rendered component. |
|
280 | - */ |
|
281 | - public static function textarea($args = array()){ |
|
282 | - $defaults = array( |
|
283 | - 'name' => '', |
|
284 | - 'class' => '', |
|
285 | - 'wrap_class' => '', |
|
286 | - 'id' => '', |
|
287 | - 'placeholder'=> '', |
|
288 | - 'title' => '', |
|
289 | - 'value' => '', |
|
290 | - 'required' => false, |
|
291 | - 'label' => '', |
|
292 | - 'label_after'=> false, |
|
293 | - 'label_class' => '', |
|
294 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | - 'help_text' => '', |
|
296 | - 'validation_text' => '', |
|
297 | - 'validation_pattern' => '', |
|
298 | - 'no_wrap' => false, |
|
299 | - 'rows' => '', |
|
300 | - 'wysiwyg' => false, |
|
301 | - 'element_require' => '', // [%element_id%] == "1" |
|
302 | - ); |
|
303 | - |
|
304 | - /** |
|
305 | - * Parse incoming $args into an array and merge it with $defaults |
|
306 | - */ |
|
307 | - $args = wp_parse_args( $args, $defaults ); |
|
308 | - $output = ''; |
|
309 | - |
|
310 | - // hidden label option needs to be empty |
|
311 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | - |
|
313 | - // floating labels don't work with wysiwyg so set it as top |
|
314 | - if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | - $args['label_type'] = 'top'; |
|
316 | - } |
|
317 | - |
|
318 | - $label_after = $args['label_after']; |
|
319 | - |
|
320 | - // floating labels need label after |
|
321 | - if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | - $label_after = true; |
|
323 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | - } |
|
325 | - |
|
326 | - // label |
|
327 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | - }elseif(!empty($args['label']) && !$label_after){ |
|
329 | - $label_args = array( |
|
330 | - 'title'=> $args['label'], |
|
331 | - 'for'=> $args['id'], |
|
332 | - 'class' => $args['label_class']." ", |
|
333 | - 'label_type' => $args['label_type'] |
|
334 | - ); |
|
335 | - $output .= self::label( $label_args ); |
|
336 | - } |
|
337 | - |
|
338 | - // maybe horizontal label |
|
339 | - if($args['label_type']=='horizontal'){ |
|
340 | - $output .= '<div class="col-sm-10">'; |
|
341 | - } |
|
342 | - |
|
343 | - if(!empty($args['wysiwyg'])){ |
|
344 | - ob_start(); |
|
345 | - $content = $args['value']; |
|
346 | - $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | - $settings = array( |
|
348 | - 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | - 'quicktags' => false, |
|
350 | - 'media_buttons' => false, |
|
351 | - 'editor_class' => 'form-control', |
|
352 | - 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | - 'teeny' => true, |
|
354 | - ); |
|
355 | - |
|
356 | - // maybe set settings if array |
|
357 | - if(is_array($args['wysiwyg'])){ |
|
358 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | - } |
|
360 | - |
|
361 | - wp_editor( $content, $editor_id, $settings ); |
|
362 | - $output .= ob_get_clean(); |
|
363 | - }else{ |
|
364 | - |
|
365 | - // open |
|
366 | - $output .= '<textarea '; |
|
367 | - |
|
368 | - // name |
|
369 | - if(!empty($args['name'])){ |
|
370 | - $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | - } |
|
372 | - |
|
373 | - // id |
|
374 | - if(!empty($args['id'])){ |
|
375 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | - } |
|
377 | - |
|
378 | - // placeholder |
|
379 | - if(!empty($args['placeholder'])){ |
|
380 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | - } |
|
382 | - |
|
383 | - // title |
|
384 | - if(!empty($args['title'])){ |
|
385 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | - } |
|
387 | - |
|
388 | - // validation text |
|
389 | - if(!empty($args['validation_text'])){ |
|
390 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | - } |
|
393 | - |
|
394 | - // validation_pattern |
|
395 | - if(!empty($args['validation_pattern'])){ |
|
396 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | - } |
|
398 | - |
|
399 | - // required |
|
400 | - if(!empty($args['required'])){ |
|
401 | - $output .= ' required '; |
|
402 | - } |
|
403 | - |
|
404 | - // rows |
|
405 | - if(!empty($args['rows'])){ |
|
406 | - $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - // class |
|
411 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | - $output .= ' class="form-control '.$class.'" '; |
|
413 | - |
|
414 | - |
|
415 | - // close tag |
|
416 | - $output .= ' >'; |
|
417 | - |
|
418 | - // value |
|
419 | - if(!empty($args['value'])){ |
|
420 | - $output .= sanitize_textarea_field($args['value']); |
|
421 | - } |
|
422 | - |
|
423 | - // closing tag |
|
424 | - $output .= '</textarea>'; |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - if(!empty($args['label']) && $label_after){ |
|
429 | - $label_args = array( |
|
430 | - 'title'=> $args['label'], |
|
431 | - 'for'=> $args['id'], |
|
432 | - 'class' => $args['label_class']." ", |
|
433 | - 'label_type' => $args['label_type'] |
|
434 | - ); |
|
435 | - $output .= self::label( $label_args ); |
|
436 | - } |
|
437 | - |
|
438 | - // help text |
|
439 | - if(!empty($args['help_text'])){ |
|
440 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | - } |
|
442 | - |
|
443 | - // maybe horizontal label |
|
444 | - if($args['label_type']=='horizontal'){ |
|
445 | - $output .= '</div>'; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - // wrap |
|
450 | - if(!$args['no_wrap']){ |
|
451 | - $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | - $output = self::wrap(array( |
|
455 | - 'content' => $output, |
|
456 | - 'class' => $wrap_class, |
|
457 | - 'element_require' => $args['element_require'], |
|
458 | - 'argument_id' => $args['id'] |
|
459 | - )); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - return $output; |
|
464 | - } |
|
465 | - |
|
466 | - public static function label($args = array(), $type = ''){ |
|
467 | - //<label for="exampleInputEmail1">Email address</label> |
|
468 | - $defaults = array( |
|
469 | - 'title' => 'div', |
|
470 | - 'for' => '', |
|
471 | - 'class' => '', |
|
472 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | - ); |
|
474 | - |
|
475 | - /** |
|
476 | - * Parse incoming $args into an array and merge it with $defaults |
|
477 | - */ |
|
478 | - $args = wp_parse_args( $args, $defaults ); |
|
479 | - $output = ''; |
|
480 | - |
|
481 | - if($args['title']){ |
|
482 | - |
|
483 | - // maybe hide labels //@todo set a global option for visibility class |
|
484 | - if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | - $class = $args['class']; |
|
486 | - }else{ |
|
487 | - $class = 'sr-only '.$args['class']; |
|
488 | - } |
|
489 | - |
|
490 | - // maybe horizontal |
|
491 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | - $class .= ' col-sm-2 col-form-label'; |
|
493 | - } |
|
494 | - |
|
495 | - // open |
|
496 | - $output .= '<label '; |
|
497 | - |
|
498 | - // for |
|
499 | - if(!empty($args['for'])){ |
|
500 | - $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | - } |
|
502 | - |
|
503 | - // class |
|
504 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | - $output .= ' class="'.$class.'" '; |
|
506 | - |
|
507 | - // close |
|
508 | - $output .= '>'; |
|
509 | - |
|
510 | - |
|
511 | - // title, don't escape fully as can contain html |
|
512 | - if(!empty($args['title'])){ |
|
513 | - $output .= wp_kses_post($args['title']); |
|
514 | - } |
|
515 | - |
|
516 | - // close wrap |
|
517 | - $output .= '</label>'; |
|
518 | - |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - return $output; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Wrap some content in a HTML wrapper. |
|
528 | - * |
|
529 | - * @param array $args |
|
530 | - * |
|
531 | - * @return string |
|
532 | - */ |
|
533 | - public static function wrap($args = array()){ |
|
534 | - $defaults = array( |
|
535 | - 'type' => 'div', |
|
536 | - 'class' => 'form-group', |
|
537 | - 'content' => '', |
|
538 | - 'input_group_left' => '', |
|
539 | - 'input_group_right' => '', |
|
540 | - 'input_group_left_inside' => false, |
|
541 | - 'input_group_right_inside' => false, |
|
542 | - 'element_require' => '', |
|
543 | - 'argument_id' => '', |
|
544 | - ); |
|
545 | - |
|
546 | - /** |
|
547 | - * Parse incoming $args into an array and merge it with $defaults |
|
548 | - */ |
|
549 | - $args = wp_parse_args( $args, $defaults ); |
|
550 | - $output = ''; |
|
551 | - if($args['type']){ |
|
552 | - |
|
553 | - // open |
|
554 | - $output .= '<'.sanitize_html_class($args['type']); |
|
555 | - |
|
556 | - // element require |
|
557 | - if(!empty($args['element_require'])){ |
|
558 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | - $args['class'] .= " aui-conditional-field"; |
|
560 | - } |
|
561 | - |
|
562 | - // argument_id |
|
563 | - if( !empty($args['argument_id']) ){ |
|
564 | - $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | - } |
|
566 | - |
|
567 | - // class |
|
568 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | - $output .= ' class="'.$class.'" '; |
|
570 | - |
|
571 | - // close wrap |
|
572 | - $output .= ' >'; |
|
573 | - |
|
574 | - |
|
575 | - // Input group left |
|
576 | - if(!empty($args['input_group_left'])){ |
|
577 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | - $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | - $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | - } |
|
581 | - |
|
582 | - // content |
|
583 | - $output .= $args['content']; |
|
584 | - |
|
585 | - // Input group right |
|
586 | - if(!empty($args['input_group_right'])){ |
|
587 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | - $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | - $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - // close wrap |
|
594 | - $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | - |
|
596 | - |
|
597 | - }else{ |
|
598 | - $output = $args['content']; |
|
599 | - } |
|
600 | - |
|
601 | - return $output; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Build the component. |
|
606 | - * |
|
607 | - * @param array $args |
|
608 | - * |
|
609 | - * @return string The rendered component. |
|
610 | - */ |
|
611 | - public static function select($args = array()){ |
|
612 | - $defaults = array( |
|
613 | - 'class' => '', |
|
614 | - 'wrap_class' => '', |
|
615 | - 'id' => '', |
|
616 | - 'title' => '', |
|
617 | - 'value' => '', // can be an array or a string |
|
618 | - 'required' => false, |
|
619 | - 'label' => '', |
|
620 | - 'label_after'=> false, |
|
621 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | - 'label_class' => '', |
|
623 | - 'help_text' => '', |
|
624 | - 'placeholder'=> '', |
|
625 | - 'options' => array(), // array or string |
|
626 | - 'icon' => '', |
|
627 | - 'multiple' => false, |
|
628 | - 'select2' => false, |
|
629 | - 'no_wrap' => false, |
|
630 | - 'element_require' => '', // [%element_id%] == "1" |
|
631 | - 'extra_attributes' => array(), // an array of extra attributes |
|
632 | - ); |
|
633 | - |
|
634 | - /** |
|
635 | - * Parse incoming $args into an array and merge it with $defaults |
|
636 | - */ |
|
637 | - $args = wp_parse_args( $args, $defaults ); |
|
638 | - $output = ''; |
|
639 | - |
|
640 | - // for now lets hide floating labels |
|
641 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | - |
|
643 | - // hidden label option needs to be empty |
|
644 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | - |
|
646 | - |
|
647 | - $label_after = $args['label_after']; |
|
648 | - |
|
649 | - // floating labels need label after |
|
650 | - if( $args['label_type'] == 'floating' ){ |
|
651 | - $label_after = true; |
|
652 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | - } |
|
654 | - |
|
655 | - // Maybe setup select2 |
|
656 | - $is_select2 = false; |
|
657 | - if(!empty($args['select2'])){ |
|
658 | - $args['class'] .= ' aui-select2'; |
|
659 | - $is_select2 = true; |
|
660 | - }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | - $is_select2 = true; |
|
662 | - } |
|
663 | - |
|
664 | - // select2 tags |
|
665 | - if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | - $args['data-tags'] = 'true'; |
|
667 | - $args['data-token-separators'] = "[',']"; |
|
668 | - $args['multiple'] = true; |
|
669 | - } |
|
670 | - |
|
671 | - // select2 placeholder |
|
672 | - if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){ |
|
673 | - $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | - $args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']); |
|
675 | - } |
|
676 | - |
|
677 | - // label |
|
678 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | - }elseif(!empty($args['label']) && !$label_after){ |
|
680 | - $label_args = array( |
|
681 | - 'title'=> $args['label'], |
|
682 | - 'for'=> $args['id'], |
|
683 | - 'class' => $args['label_class']." ", |
|
684 | - 'label_type' => $args['label_type'] |
|
685 | - ); |
|
686 | - $output .= self::label($label_args); |
|
687 | - } |
|
688 | - |
|
689 | - // maybe horizontal label |
|
690 | - if($args['label_type']=='horizontal'){ |
|
691 | - $output .= '<div class="col-sm-10">'; |
|
692 | - } |
|
693 | - |
|
694 | - // open/type |
|
695 | - $output .= '<select '; |
|
696 | - |
|
697 | - // style |
|
698 | - if($is_select2){ |
|
699 | - $output .= " style='width:100%;' "; |
|
700 | - } |
|
701 | - |
|
702 | - // element require |
|
703 | - if(!empty($args['element_require'])){ |
|
704 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | - $args['class'] .= " aui-conditional-field"; |
|
706 | - } |
|
707 | - |
|
708 | - // class |
|
709 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | - $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | - |
|
712 | - // name |
|
713 | - if(!empty($args['name'])){ |
|
714 | - $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | - } |
|
716 | - |
|
717 | - // id |
|
718 | - if(!empty($args['id'])){ |
|
719 | - $output .= AUI_Component_Helper::id($args['id']); |
|
720 | - } |
|
721 | - |
|
722 | - // title |
|
723 | - if(!empty($args['title'])){ |
|
724 | - $output .= AUI_Component_Helper::title($args['title']); |
|
725 | - } |
|
726 | - |
|
727 | - // data-attributes |
|
728 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | - |
|
730 | - // aria-attributes |
|
731 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | - |
|
733 | - // extra attributes |
|
734 | - if(!empty($args['extra_attributes'])){ |
|
735 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | - } |
|
737 | - |
|
738 | - // required |
|
739 | - if(!empty($args['required'])){ |
|
740 | - $output .= ' required '; |
|
741 | - } |
|
742 | - |
|
743 | - // multiple |
|
744 | - if(!empty($args['multiple'])){ |
|
745 | - $output .= ' multiple '; |
|
746 | - } |
|
747 | - |
|
748 | - // close opening tag |
|
749 | - $output .= ' >'; |
|
750 | - |
|
751 | - // placeholder |
|
752 | - if(!empty($args['placeholder']) && !$is_select2){ |
|
753 | - $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | - }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | - } |
|
757 | - |
|
758 | - // Options |
|
759 | - if(!empty($args['options'])){ |
|
760 | - |
|
761 | - if(!is_array($args['options'])){ |
|
762 | - $output .= $args['options']; // not the preferred way but an option |
|
763 | - }else{ |
|
764 | - foreach($args['options'] as $val => $name){ |
|
765 | - $selected = ''; |
|
766 | - if(is_array($name)){ |
|
767 | - if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | - |
|
770 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | - } else { |
|
772 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | - $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | - if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | - $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | - } elseif(!empty($args['value'])) { |
|
777 | - $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | - } |
|
779 | - |
|
780 | - $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | - } |
|
782 | - }else{ |
|
783 | - if(!empty($args['value'])){ |
|
784 | - if(is_array($args['value'])){ |
|
785 | - $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | - } elseif(!empty($args['value'])) { |
|
787 | - $selected = selected( $args['value'], $val, false); |
|
788 | - } |
|
789 | - } |
|
790 | - $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | - } |
|
792 | - } |
|
793 | - } |
|
794 | - |
|
795 | - } |
|
796 | - |
|
797 | - // closing tag |
|
798 | - $output .= '</select>'; |
|
799 | - |
|
800 | - if(!empty($args['label']) && $label_after){ |
|
801 | - $label_args = array( |
|
802 | - 'title'=> $args['label'], |
|
803 | - 'for'=> $args['id'], |
|
804 | - 'class' => $args['label_class']." ", |
|
805 | - 'label_type' => $args['label_type'] |
|
806 | - ); |
|
807 | - $output .= self::label($label_args); |
|
808 | - } |
|
809 | - |
|
810 | - // help text |
|
811 | - if(!empty($args['help_text'])){ |
|
812 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | - } |
|
814 | - |
|
815 | - // maybe horizontal label |
|
816 | - if($args['label_type']=='horizontal'){ |
|
817 | - $output .= '</div>'; |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - // wrap |
|
822 | - if(!$args['no_wrap']){ |
|
823 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | - $output = self::wrap(array( |
|
826 | - 'content' => $output, |
|
827 | - 'class' => $wrap_class, |
|
828 | - 'element_require' => $args['element_require'], |
|
829 | - 'argument_id' => $args['id'] |
|
830 | - )); |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - return $output; |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Build the component. |
|
839 | - * |
|
840 | - * @param array $args |
|
841 | - * |
|
842 | - * @return string The rendered component. |
|
843 | - */ |
|
844 | - public static function radio($args = array()){ |
|
845 | - $defaults = array( |
|
846 | - 'class' => '', |
|
847 | - 'wrap_class' => '', |
|
848 | - 'id' => '', |
|
849 | - 'title' => '', |
|
850 | - 'horizontal' => false, // sets the lable horizontal |
|
851 | - 'value' => '', |
|
852 | - 'label' => '', |
|
853 | - 'label_class'=> '', |
|
854 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | - 'inline' => true, |
|
856 | - 'required' => false, |
|
857 | - 'options' => array(), |
|
858 | - 'icon' => '', |
|
859 | - 'no_wrap' => false, |
|
860 | - 'element_require' => '', // [%element_id%] == "1" |
|
861 | - 'extra_attributes' => array() // an array of extra attributes |
|
862 | - ); |
|
863 | - |
|
864 | - /** |
|
865 | - * Parse incoming $args into an array and merge it with $defaults |
|
866 | - */ |
|
867 | - $args = wp_parse_args( $args, $defaults ); |
|
868 | - |
|
869 | - // for now lets use horizontal for floating |
|
870 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | - |
|
872 | - $label_args = array( |
|
873 | - 'title'=> $args['label'], |
|
874 | - 'class' => $args['label_class']." pt-0 ", |
|
875 | - 'label_type' => $args['label_type'] |
|
876 | - ); |
|
877 | - |
|
878 | - $output = ''; |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - // label before |
|
883 | - if(!empty($args['label'])){ |
|
884 | - $output .= self::label( $label_args, 'radio' ); |
|
885 | - } |
|
886 | - |
|
887 | - // maybe horizontal label |
|
888 | - if($args['label_type']=='horizontal'){ |
|
889 | - $output .= '<div class="col-sm-10">'; |
|
890 | - } |
|
891 | - |
|
892 | - if(!empty($args['options'])){ |
|
893 | - $count = 0; |
|
894 | - foreach($args['options'] as $value => $label){ |
|
895 | - $option_args = $args; |
|
896 | - $option_args['value'] = $value; |
|
897 | - $option_args['label'] = $label; |
|
898 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | - $output .= self::radio_option($option_args,$count); |
|
900 | - $count++; |
|
901 | - } |
|
902 | - } |
|
903 | - |
|
904 | - // maybe horizontal label |
|
905 | - if($args['label_type']=='horizontal'){ |
|
906 | - $output .= '</div>'; |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - // wrap |
|
911 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | - $output = self::wrap(array( |
|
914 | - 'content' => $output, |
|
915 | - 'class' => $wrap_class, |
|
916 | - 'element_require' => $args['element_require'], |
|
917 | - 'argument_id' => $args['id'] |
|
918 | - )); |
|
919 | - |
|
920 | - |
|
921 | - return $output; |
|
922 | - } |
|
923 | - |
|
924 | - /** |
|
925 | - * Build the component. |
|
926 | - * |
|
927 | - * @param array $args |
|
928 | - * |
|
929 | - * @return string The rendered component. |
|
930 | - */ |
|
931 | - public static function radio_option($args = array(),$count = ''){ |
|
932 | - $defaults = array( |
|
933 | - 'class' => '', |
|
934 | - 'id' => '', |
|
935 | - 'title' => '', |
|
936 | - 'value' => '', |
|
937 | - 'required' => false, |
|
938 | - 'inline' => true, |
|
939 | - 'label' => '', |
|
940 | - 'options' => array(), |
|
941 | - 'icon' => '', |
|
942 | - 'no_wrap' => false, |
|
943 | - 'extra_attributes' => array() // an array of extra attributes |
|
944 | - ); |
|
945 | - |
|
946 | - /** |
|
947 | - * Parse incoming $args into an array and merge it with $defaults |
|
948 | - */ |
|
949 | - $args = wp_parse_args( $args, $defaults ); |
|
950 | - |
|
951 | - $output = ''; |
|
952 | - |
|
953 | - // open/type |
|
954 | - $output .= '<input type="radio"'; |
|
955 | - |
|
956 | - // class |
|
957 | - $output .= ' class="form-check-input" '; |
|
958 | - |
|
959 | - // name |
|
960 | - if(!empty($args['name'])){ |
|
961 | - $output .= AUI_Component_Helper::name($args['name']); |
|
962 | - } |
|
963 | - |
|
964 | - // id |
|
965 | - if(!empty($args['id'])){ |
|
966 | - $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | - } |
|
968 | - |
|
969 | - // title |
|
970 | - if(!empty($args['title'])){ |
|
971 | - $output .= AUI_Component_Helper::title($args['title']); |
|
972 | - } |
|
973 | - |
|
974 | - // value |
|
975 | - if(isset($args['value'])){ |
|
976 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | - } |
|
978 | - |
|
979 | - // checked, for radio and checkboxes |
|
980 | - if( $args['checked'] ){ |
|
981 | - $output .= ' checked '; |
|
982 | - } |
|
983 | - |
|
984 | - // data-attributes |
|
985 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | - |
|
987 | - // aria-attributes |
|
988 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | - |
|
990 | - // extra attributes |
|
991 | - if(!empty($args['extra_attributes'])){ |
|
992 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | - } |
|
994 | - |
|
995 | - // required |
|
996 | - if(!empty($args['required'])){ |
|
997 | - $output .= ' required '; |
|
998 | - } |
|
999 | - |
|
1000 | - // close opening tag |
|
1001 | - $output .= ' >'; |
|
1002 | - |
|
1003 | - // label |
|
1004 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | - }elseif(!empty($args['label'])){ |
|
1006 | - $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | - } |
|
1008 | - |
|
1009 | - // wrap |
|
1010 | - if(!$args['no_wrap']){ |
|
1011 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | - $output = self::wrap(array( |
|
1013 | - 'content' => $output, |
|
1014 | - 'class' => $wrap_class |
|
1015 | - )); |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - return $output; |
|
1020 | - } |
|
213 | + } |
|
214 | + |
|
215 | + // input group wraps |
|
216 | + if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | + if($args['input_group_left']){ |
|
219 | + $output = self::wrap( array( |
|
220 | + 'content' => $output, |
|
221 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | + 'input_group_left' => $args['input_group_left'], |
|
223 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | + ) ); |
|
225 | + } |
|
226 | + if($args['input_group_right']){ |
|
227 | + $output = self::wrap( array( |
|
228 | + 'content' => $output, |
|
229 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | + 'input_group_right' => $args['input_group_right'], |
|
231 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | + ) ); |
|
233 | + } |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + if(!$label_after){ |
|
238 | + $output .= $help_text; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | + $output = self::wrap( array( |
|
244 | + 'content' => $output, |
|
245 | + 'class' => 'col-sm-10', |
|
246 | + ) ); |
|
247 | + } |
|
248 | + |
|
249 | + if(!$label_after){ |
|
250 | + $output = $label . $output; |
|
251 | + } |
|
252 | + |
|
253 | + // wrap |
|
254 | + if(!$args['no_wrap']){ |
|
255 | + |
|
256 | + $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | + $output = self::wrap(array( |
|
260 | + 'content' => $output, |
|
261 | + 'class' => $wrap_class, |
|
262 | + 'element_require' => $args['element_require'], |
|
263 | + 'argument_id' => $args['id'] |
|
264 | + )); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + } |
|
270 | + |
|
271 | + return $output; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Build the component. |
|
276 | + * |
|
277 | + * @param array $args |
|
278 | + * |
|
279 | + * @return string The rendered component. |
|
280 | + */ |
|
281 | + public static function textarea($args = array()){ |
|
282 | + $defaults = array( |
|
283 | + 'name' => '', |
|
284 | + 'class' => '', |
|
285 | + 'wrap_class' => '', |
|
286 | + 'id' => '', |
|
287 | + 'placeholder'=> '', |
|
288 | + 'title' => '', |
|
289 | + 'value' => '', |
|
290 | + 'required' => false, |
|
291 | + 'label' => '', |
|
292 | + 'label_after'=> false, |
|
293 | + 'label_class' => '', |
|
294 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | + 'help_text' => '', |
|
296 | + 'validation_text' => '', |
|
297 | + 'validation_pattern' => '', |
|
298 | + 'no_wrap' => false, |
|
299 | + 'rows' => '', |
|
300 | + 'wysiwyg' => false, |
|
301 | + 'element_require' => '', // [%element_id%] == "1" |
|
302 | + ); |
|
303 | + |
|
304 | + /** |
|
305 | + * Parse incoming $args into an array and merge it with $defaults |
|
306 | + */ |
|
307 | + $args = wp_parse_args( $args, $defaults ); |
|
308 | + $output = ''; |
|
309 | + |
|
310 | + // hidden label option needs to be empty |
|
311 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | + |
|
313 | + // floating labels don't work with wysiwyg so set it as top |
|
314 | + if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | + $args['label_type'] = 'top'; |
|
316 | + } |
|
317 | + |
|
318 | + $label_after = $args['label_after']; |
|
319 | + |
|
320 | + // floating labels need label after |
|
321 | + if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | + $label_after = true; |
|
323 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | + } |
|
325 | + |
|
326 | + // label |
|
327 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | + }elseif(!empty($args['label']) && !$label_after){ |
|
329 | + $label_args = array( |
|
330 | + 'title'=> $args['label'], |
|
331 | + 'for'=> $args['id'], |
|
332 | + 'class' => $args['label_class']." ", |
|
333 | + 'label_type' => $args['label_type'] |
|
334 | + ); |
|
335 | + $output .= self::label( $label_args ); |
|
336 | + } |
|
337 | + |
|
338 | + // maybe horizontal label |
|
339 | + if($args['label_type']=='horizontal'){ |
|
340 | + $output .= '<div class="col-sm-10">'; |
|
341 | + } |
|
342 | + |
|
343 | + if(!empty($args['wysiwyg'])){ |
|
344 | + ob_start(); |
|
345 | + $content = $args['value']; |
|
346 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | + $settings = array( |
|
348 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | + 'quicktags' => false, |
|
350 | + 'media_buttons' => false, |
|
351 | + 'editor_class' => 'form-control', |
|
352 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | + 'teeny' => true, |
|
354 | + ); |
|
355 | + |
|
356 | + // maybe set settings if array |
|
357 | + if(is_array($args['wysiwyg'])){ |
|
358 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | + } |
|
360 | + |
|
361 | + wp_editor( $content, $editor_id, $settings ); |
|
362 | + $output .= ob_get_clean(); |
|
363 | + }else{ |
|
364 | + |
|
365 | + // open |
|
366 | + $output .= '<textarea '; |
|
367 | + |
|
368 | + // name |
|
369 | + if(!empty($args['name'])){ |
|
370 | + $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | + } |
|
372 | + |
|
373 | + // id |
|
374 | + if(!empty($args['id'])){ |
|
375 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | + } |
|
377 | + |
|
378 | + // placeholder |
|
379 | + if(!empty($args['placeholder'])){ |
|
380 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | + } |
|
382 | + |
|
383 | + // title |
|
384 | + if(!empty($args['title'])){ |
|
385 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | + } |
|
387 | + |
|
388 | + // validation text |
|
389 | + if(!empty($args['validation_text'])){ |
|
390 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | + } |
|
393 | + |
|
394 | + // validation_pattern |
|
395 | + if(!empty($args['validation_pattern'])){ |
|
396 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | + } |
|
398 | + |
|
399 | + // required |
|
400 | + if(!empty($args['required'])){ |
|
401 | + $output .= ' required '; |
|
402 | + } |
|
403 | + |
|
404 | + // rows |
|
405 | + if(!empty($args['rows'])){ |
|
406 | + $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + // class |
|
411 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | + $output .= ' class="form-control '.$class.'" '; |
|
413 | + |
|
414 | + |
|
415 | + // close tag |
|
416 | + $output .= ' >'; |
|
417 | + |
|
418 | + // value |
|
419 | + if(!empty($args['value'])){ |
|
420 | + $output .= sanitize_textarea_field($args['value']); |
|
421 | + } |
|
422 | + |
|
423 | + // closing tag |
|
424 | + $output .= '</textarea>'; |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + if(!empty($args['label']) && $label_after){ |
|
429 | + $label_args = array( |
|
430 | + 'title'=> $args['label'], |
|
431 | + 'for'=> $args['id'], |
|
432 | + 'class' => $args['label_class']." ", |
|
433 | + 'label_type' => $args['label_type'] |
|
434 | + ); |
|
435 | + $output .= self::label( $label_args ); |
|
436 | + } |
|
437 | + |
|
438 | + // help text |
|
439 | + if(!empty($args['help_text'])){ |
|
440 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | + } |
|
442 | + |
|
443 | + // maybe horizontal label |
|
444 | + if($args['label_type']=='horizontal'){ |
|
445 | + $output .= '</div>'; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + // wrap |
|
450 | + if(!$args['no_wrap']){ |
|
451 | + $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | + $output = self::wrap(array( |
|
455 | + 'content' => $output, |
|
456 | + 'class' => $wrap_class, |
|
457 | + 'element_require' => $args['element_require'], |
|
458 | + 'argument_id' => $args['id'] |
|
459 | + )); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + return $output; |
|
464 | + } |
|
465 | + |
|
466 | + public static function label($args = array(), $type = ''){ |
|
467 | + //<label for="exampleInputEmail1">Email address</label> |
|
468 | + $defaults = array( |
|
469 | + 'title' => 'div', |
|
470 | + 'for' => '', |
|
471 | + 'class' => '', |
|
472 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | + ); |
|
474 | + |
|
475 | + /** |
|
476 | + * Parse incoming $args into an array and merge it with $defaults |
|
477 | + */ |
|
478 | + $args = wp_parse_args( $args, $defaults ); |
|
479 | + $output = ''; |
|
480 | + |
|
481 | + if($args['title']){ |
|
482 | + |
|
483 | + // maybe hide labels //@todo set a global option for visibility class |
|
484 | + if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | + $class = $args['class']; |
|
486 | + }else{ |
|
487 | + $class = 'sr-only '.$args['class']; |
|
488 | + } |
|
489 | + |
|
490 | + // maybe horizontal |
|
491 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | + $class .= ' col-sm-2 col-form-label'; |
|
493 | + } |
|
494 | + |
|
495 | + // open |
|
496 | + $output .= '<label '; |
|
497 | + |
|
498 | + // for |
|
499 | + if(!empty($args['for'])){ |
|
500 | + $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | + } |
|
502 | + |
|
503 | + // class |
|
504 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | + $output .= ' class="'.$class.'" '; |
|
506 | + |
|
507 | + // close |
|
508 | + $output .= '>'; |
|
509 | + |
|
510 | + |
|
511 | + // title, don't escape fully as can contain html |
|
512 | + if(!empty($args['title'])){ |
|
513 | + $output .= wp_kses_post($args['title']); |
|
514 | + } |
|
515 | + |
|
516 | + // close wrap |
|
517 | + $output .= '</label>'; |
|
518 | + |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + return $output; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Wrap some content in a HTML wrapper. |
|
528 | + * |
|
529 | + * @param array $args |
|
530 | + * |
|
531 | + * @return string |
|
532 | + */ |
|
533 | + public static function wrap($args = array()){ |
|
534 | + $defaults = array( |
|
535 | + 'type' => 'div', |
|
536 | + 'class' => 'form-group', |
|
537 | + 'content' => '', |
|
538 | + 'input_group_left' => '', |
|
539 | + 'input_group_right' => '', |
|
540 | + 'input_group_left_inside' => false, |
|
541 | + 'input_group_right_inside' => false, |
|
542 | + 'element_require' => '', |
|
543 | + 'argument_id' => '', |
|
544 | + ); |
|
545 | + |
|
546 | + /** |
|
547 | + * Parse incoming $args into an array and merge it with $defaults |
|
548 | + */ |
|
549 | + $args = wp_parse_args( $args, $defaults ); |
|
550 | + $output = ''; |
|
551 | + if($args['type']){ |
|
552 | + |
|
553 | + // open |
|
554 | + $output .= '<'.sanitize_html_class($args['type']); |
|
555 | + |
|
556 | + // element require |
|
557 | + if(!empty($args['element_require'])){ |
|
558 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | + $args['class'] .= " aui-conditional-field"; |
|
560 | + } |
|
561 | + |
|
562 | + // argument_id |
|
563 | + if( !empty($args['argument_id']) ){ |
|
564 | + $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | + } |
|
566 | + |
|
567 | + // class |
|
568 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | + $output .= ' class="'.$class.'" '; |
|
570 | + |
|
571 | + // close wrap |
|
572 | + $output .= ' >'; |
|
573 | + |
|
574 | + |
|
575 | + // Input group left |
|
576 | + if(!empty($args['input_group_left'])){ |
|
577 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | + $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | + } |
|
581 | + |
|
582 | + // content |
|
583 | + $output .= $args['content']; |
|
584 | + |
|
585 | + // Input group right |
|
586 | + if(!empty($args['input_group_right'])){ |
|
587 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | + $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + // close wrap |
|
594 | + $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | + |
|
596 | + |
|
597 | + }else{ |
|
598 | + $output = $args['content']; |
|
599 | + } |
|
600 | + |
|
601 | + return $output; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Build the component. |
|
606 | + * |
|
607 | + * @param array $args |
|
608 | + * |
|
609 | + * @return string The rendered component. |
|
610 | + */ |
|
611 | + public static function select($args = array()){ |
|
612 | + $defaults = array( |
|
613 | + 'class' => '', |
|
614 | + 'wrap_class' => '', |
|
615 | + 'id' => '', |
|
616 | + 'title' => '', |
|
617 | + 'value' => '', // can be an array or a string |
|
618 | + 'required' => false, |
|
619 | + 'label' => '', |
|
620 | + 'label_after'=> false, |
|
621 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | + 'label_class' => '', |
|
623 | + 'help_text' => '', |
|
624 | + 'placeholder'=> '', |
|
625 | + 'options' => array(), // array or string |
|
626 | + 'icon' => '', |
|
627 | + 'multiple' => false, |
|
628 | + 'select2' => false, |
|
629 | + 'no_wrap' => false, |
|
630 | + 'element_require' => '', // [%element_id%] == "1" |
|
631 | + 'extra_attributes' => array(), // an array of extra attributes |
|
632 | + ); |
|
633 | + |
|
634 | + /** |
|
635 | + * Parse incoming $args into an array and merge it with $defaults |
|
636 | + */ |
|
637 | + $args = wp_parse_args( $args, $defaults ); |
|
638 | + $output = ''; |
|
639 | + |
|
640 | + // for now lets hide floating labels |
|
641 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | + |
|
643 | + // hidden label option needs to be empty |
|
644 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | + |
|
646 | + |
|
647 | + $label_after = $args['label_after']; |
|
648 | + |
|
649 | + // floating labels need label after |
|
650 | + if( $args['label_type'] == 'floating' ){ |
|
651 | + $label_after = true; |
|
652 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | + } |
|
654 | + |
|
655 | + // Maybe setup select2 |
|
656 | + $is_select2 = false; |
|
657 | + if(!empty($args['select2'])){ |
|
658 | + $args['class'] .= ' aui-select2'; |
|
659 | + $is_select2 = true; |
|
660 | + }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | + $is_select2 = true; |
|
662 | + } |
|
663 | + |
|
664 | + // select2 tags |
|
665 | + if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | + $args['data-tags'] = 'true'; |
|
667 | + $args['data-token-separators'] = "[',']"; |
|
668 | + $args['multiple'] = true; |
|
669 | + } |
|
670 | + |
|
671 | + // select2 placeholder |
|
672 | + if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){ |
|
673 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | + $args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']); |
|
675 | + } |
|
676 | + |
|
677 | + // label |
|
678 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | + }elseif(!empty($args['label']) && !$label_after){ |
|
680 | + $label_args = array( |
|
681 | + 'title'=> $args['label'], |
|
682 | + 'for'=> $args['id'], |
|
683 | + 'class' => $args['label_class']." ", |
|
684 | + 'label_type' => $args['label_type'] |
|
685 | + ); |
|
686 | + $output .= self::label($label_args); |
|
687 | + } |
|
688 | + |
|
689 | + // maybe horizontal label |
|
690 | + if($args['label_type']=='horizontal'){ |
|
691 | + $output .= '<div class="col-sm-10">'; |
|
692 | + } |
|
693 | + |
|
694 | + // open/type |
|
695 | + $output .= '<select '; |
|
696 | + |
|
697 | + // style |
|
698 | + if($is_select2){ |
|
699 | + $output .= " style='width:100%;' "; |
|
700 | + } |
|
701 | + |
|
702 | + // element require |
|
703 | + if(!empty($args['element_require'])){ |
|
704 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | + $args['class'] .= " aui-conditional-field"; |
|
706 | + } |
|
707 | + |
|
708 | + // class |
|
709 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | + $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | + |
|
712 | + // name |
|
713 | + if(!empty($args['name'])){ |
|
714 | + $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | + } |
|
716 | + |
|
717 | + // id |
|
718 | + if(!empty($args['id'])){ |
|
719 | + $output .= AUI_Component_Helper::id($args['id']); |
|
720 | + } |
|
721 | + |
|
722 | + // title |
|
723 | + if(!empty($args['title'])){ |
|
724 | + $output .= AUI_Component_Helper::title($args['title']); |
|
725 | + } |
|
726 | + |
|
727 | + // data-attributes |
|
728 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | + |
|
730 | + // aria-attributes |
|
731 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | + |
|
733 | + // extra attributes |
|
734 | + if(!empty($args['extra_attributes'])){ |
|
735 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | + } |
|
737 | + |
|
738 | + // required |
|
739 | + if(!empty($args['required'])){ |
|
740 | + $output .= ' required '; |
|
741 | + } |
|
742 | + |
|
743 | + // multiple |
|
744 | + if(!empty($args['multiple'])){ |
|
745 | + $output .= ' multiple '; |
|
746 | + } |
|
747 | + |
|
748 | + // close opening tag |
|
749 | + $output .= ' >'; |
|
750 | + |
|
751 | + // placeholder |
|
752 | + if(!empty($args['placeholder']) && !$is_select2){ |
|
753 | + $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | + }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | + } |
|
757 | + |
|
758 | + // Options |
|
759 | + if(!empty($args['options'])){ |
|
760 | + |
|
761 | + if(!is_array($args['options'])){ |
|
762 | + $output .= $args['options']; // not the preferred way but an option |
|
763 | + }else{ |
|
764 | + foreach($args['options'] as $val => $name){ |
|
765 | + $selected = ''; |
|
766 | + if(is_array($name)){ |
|
767 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | + |
|
770 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | + } else { |
|
772 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | + if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | + } elseif(!empty($args['value'])) { |
|
777 | + $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | + } |
|
779 | + |
|
780 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | + } |
|
782 | + }else{ |
|
783 | + if(!empty($args['value'])){ |
|
784 | + if(is_array($args['value'])){ |
|
785 | + $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | + } elseif(!empty($args['value'])) { |
|
787 | + $selected = selected( $args['value'], $val, false); |
|
788 | + } |
|
789 | + } |
|
790 | + $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | + } |
|
792 | + } |
|
793 | + } |
|
794 | + |
|
795 | + } |
|
796 | + |
|
797 | + // closing tag |
|
798 | + $output .= '</select>'; |
|
799 | + |
|
800 | + if(!empty($args['label']) && $label_after){ |
|
801 | + $label_args = array( |
|
802 | + 'title'=> $args['label'], |
|
803 | + 'for'=> $args['id'], |
|
804 | + 'class' => $args['label_class']." ", |
|
805 | + 'label_type' => $args['label_type'] |
|
806 | + ); |
|
807 | + $output .= self::label($label_args); |
|
808 | + } |
|
809 | + |
|
810 | + // help text |
|
811 | + if(!empty($args['help_text'])){ |
|
812 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | + } |
|
814 | + |
|
815 | + // maybe horizontal label |
|
816 | + if($args['label_type']=='horizontal'){ |
|
817 | + $output .= '</div>'; |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + // wrap |
|
822 | + if(!$args['no_wrap']){ |
|
823 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | + $output = self::wrap(array( |
|
826 | + 'content' => $output, |
|
827 | + 'class' => $wrap_class, |
|
828 | + 'element_require' => $args['element_require'], |
|
829 | + 'argument_id' => $args['id'] |
|
830 | + )); |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + return $output; |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Build the component. |
|
839 | + * |
|
840 | + * @param array $args |
|
841 | + * |
|
842 | + * @return string The rendered component. |
|
843 | + */ |
|
844 | + public static function radio($args = array()){ |
|
845 | + $defaults = array( |
|
846 | + 'class' => '', |
|
847 | + 'wrap_class' => '', |
|
848 | + 'id' => '', |
|
849 | + 'title' => '', |
|
850 | + 'horizontal' => false, // sets the lable horizontal |
|
851 | + 'value' => '', |
|
852 | + 'label' => '', |
|
853 | + 'label_class'=> '', |
|
854 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | + 'inline' => true, |
|
856 | + 'required' => false, |
|
857 | + 'options' => array(), |
|
858 | + 'icon' => '', |
|
859 | + 'no_wrap' => false, |
|
860 | + 'element_require' => '', // [%element_id%] == "1" |
|
861 | + 'extra_attributes' => array() // an array of extra attributes |
|
862 | + ); |
|
863 | + |
|
864 | + /** |
|
865 | + * Parse incoming $args into an array and merge it with $defaults |
|
866 | + */ |
|
867 | + $args = wp_parse_args( $args, $defaults ); |
|
868 | + |
|
869 | + // for now lets use horizontal for floating |
|
870 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | + |
|
872 | + $label_args = array( |
|
873 | + 'title'=> $args['label'], |
|
874 | + 'class' => $args['label_class']." pt-0 ", |
|
875 | + 'label_type' => $args['label_type'] |
|
876 | + ); |
|
877 | + |
|
878 | + $output = ''; |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + // label before |
|
883 | + if(!empty($args['label'])){ |
|
884 | + $output .= self::label( $label_args, 'radio' ); |
|
885 | + } |
|
886 | + |
|
887 | + // maybe horizontal label |
|
888 | + if($args['label_type']=='horizontal'){ |
|
889 | + $output .= '<div class="col-sm-10">'; |
|
890 | + } |
|
891 | + |
|
892 | + if(!empty($args['options'])){ |
|
893 | + $count = 0; |
|
894 | + foreach($args['options'] as $value => $label){ |
|
895 | + $option_args = $args; |
|
896 | + $option_args['value'] = $value; |
|
897 | + $option_args['label'] = $label; |
|
898 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | + $output .= self::radio_option($option_args,$count); |
|
900 | + $count++; |
|
901 | + } |
|
902 | + } |
|
903 | + |
|
904 | + // maybe horizontal label |
|
905 | + if($args['label_type']=='horizontal'){ |
|
906 | + $output .= '</div>'; |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + // wrap |
|
911 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | + $output = self::wrap(array( |
|
914 | + 'content' => $output, |
|
915 | + 'class' => $wrap_class, |
|
916 | + 'element_require' => $args['element_require'], |
|
917 | + 'argument_id' => $args['id'] |
|
918 | + )); |
|
919 | + |
|
920 | + |
|
921 | + return $output; |
|
922 | + } |
|
923 | + |
|
924 | + /** |
|
925 | + * Build the component. |
|
926 | + * |
|
927 | + * @param array $args |
|
928 | + * |
|
929 | + * @return string The rendered component. |
|
930 | + */ |
|
931 | + public static function radio_option($args = array(),$count = ''){ |
|
932 | + $defaults = array( |
|
933 | + 'class' => '', |
|
934 | + 'id' => '', |
|
935 | + 'title' => '', |
|
936 | + 'value' => '', |
|
937 | + 'required' => false, |
|
938 | + 'inline' => true, |
|
939 | + 'label' => '', |
|
940 | + 'options' => array(), |
|
941 | + 'icon' => '', |
|
942 | + 'no_wrap' => false, |
|
943 | + 'extra_attributes' => array() // an array of extra attributes |
|
944 | + ); |
|
945 | + |
|
946 | + /** |
|
947 | + * Parse incoming $args into an array and merge it with $defaults |
|
948 | + */ |
|
949 | + $args = wp_parse_args( $args, $defaults ); |
|
950 | + |
|
951 | + $output = ''; |
|
952 | + |
|
953 | + // open/type |
|
954 | + $output .= '<input type="radio"'; |
|
955 | + |
|
956 | + // class |
|
957 | + $output .= ' class="form-check-input" '; |
|
958 | + |
|
959 | + // name |
|
960 | + if(!empty($args['name'])){ |
|
961 | + $output .= AUI_Component_Helper::name($args['name']); |
|
962 | + } |
|
963 | + |
|
964 | + // id |
|
965 | + if(!empty($args['id'])){ |
|
966 | + $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | + } |
|
968 | + |
|
969 | + // title |
|
970 | + if(!empty($args['title'])){ |
|
971 | + $output .= AUI_Component_Helper::title($args['title']); |
|
972 | + } |
|
973 | + |
|
974 | + // value |
|
975 | + if(isset($args['value'])){ |
|
976 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | + } |
|
978 | + |
|
979 | + // checked, for radio and checkboxes |
|
980 | + if( $args['checked'] ){ |
|
981 | + $output .= ' checked '; |
|
982 | + } |
|
983 | + |
|
984 | + // data-attributes |
|
985 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | + |
|
987 | + // aria-attributes |
|
988 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | + |
|
990 | + // extra attributes |
|
991 | + if(!empty($args['extra_attributes'])){ |
|
992 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | + } |
|
994 | + |
|
995 | + // required |
|
996 | + if(!empty($args['required'])){ |
|
997 | + $output .= ' required '; |
|
998 | + } |
|
999 | + |
|
1000 | + // close opening tag |
|
1001 | + $output .= ' >'; |
|
1002 | + |
|
1003 | + // label |
|
1004 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | + }elseif(!empty($args['label'])){ |
|
1006 | + $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | + } |
|
1008 | + |
|
1009 | + // wrap |
|
1010 | + if(!$args['no_wrap']){ |
|
1011 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | + $output = self::wrap(array( |
|
1013 | + 'content' => $output, |
|
1014 | + 'class' => $wrap_class |
|
1015 | + )); |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + return $output; |
|
1020 | + } |
|
1021 | 1021 | |
1022 | 1022 | } |
1023 | 1023 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,199 +21,199 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class AyeCode_UI_Settings |
|
28 | - * @ver 1.0.0 |
|
29 | - * @todo decide how to implement textdomain |
|
30 | - */ |
|
31 | - class AyeCode_UI_Settings { |
|
32 | - |
|
33 | - /** |
|
34 | - * Class version version. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $version = '1.0.1'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Class textdomain. |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $textdomain = 'aui'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Latest version of Bootstrap at time of publish published. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $latest = "4.3.1"; |
|
53 | - |
|
54 | - /** |
|
55 | - * Current version of select2 being used. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $select2_version = "4.0.11"; |
|
60 | - |
|
61 | - /** |
|
62 | - * The title. |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public $name = 'AyeCode UI'; |
|
67 | - |
|
68 | - /** |
|
69 | - * The relative url to the assets. |
|
70 | - * |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - public $url = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * Holds the settings values. |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - private $settings; |
|
81 | - |
|
82 | - /** |
|
83 | - * AyeCode_UI_Settings instance. |
|
84 | - * |
|
85 | - * @access private |
|
86 | - * @since 1.0.0 |
|
87 | - * @var AyeCode_UI_Settings There can be only one! |
|
88 | - */ |
|
89 | - private static $instance = null; |
|
90 | - |
|
91 | - /** |
|
92 | - * Main AyeCode_UI_Settings Instance. |
|
93 | - * |
|
94 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | - * |
|
96 | - * @since 1.0.0 |
|
97 | - * @static |
|
98 | - * @return AyeCode_UI_Settings - Main instance. |
|
99 | - */ |
|
100 | - public static function instance() { |
|
101 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | - |
|
103 | - self::$instance = new AyeCode_UI_Settings; |
|
104 | - |
|
105 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | - |
|
107 | - if ( is_admin() ) { |
|
108 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | - |
|
111 | - // Maybe show example page |
|
112 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | - } |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class AyeCode_UI_Settings |
|
28 | + * @ver 1.0.0 |
|
29 | + * @todo decide how to implement textdomain |
|
30 | + */ |
|
31 | + class AyeCode_UI_Settings { |
|
32 | + |
|
33 | + /** |
|
34 | + * Class version version. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $version = '1.0.1'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Class textdomain. |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $textdomain = 'aui'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Latest version of Bootstrap at time of publish published. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $latest = "4.3.1"; |
|
53 | + |
|
54 | + /** |
|
55 | + * Current version of select2 being used. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $select2_version = "4.0.11"; |
|
60 | + |
|
61 | + /** |
|
62 | + * The title. |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public $name = 'AyeCode UI'; |
|
67 | + |
|
68 | + /** |
|
69 | + * The relative url to the assets. |
|
70 | + * |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + public $url = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * Holds the settings values. |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + private $settings; |
|
81 | + |
|
82 | + /** |
|
83 | + * AyeCode_UI_Settings instance. |
|
84 | + * |
|
85 | + * @access private |
|
86 | + * @since 1.0.0 |
|
87 | + * @var AyeCode_UI_Settings There can be only one! |
|
88 | + */ |
|
89 | + private static $instance = null; |
|
90 | + |
|
91 | + /** |
|
92 | + * Main AyeCode_UI_Settings Instance. |
|
93 | + * |
|
94 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | + * |
|
96 | + * @since 1.0.0 |
|
97 | + * @static |
|
98 | + * @return AyeCode_UI_Settings - Main instance. |
|
99 | + */ |
|
100 | + public static function instance() { |
|
101 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | + |
|
103 | + self::$instance = new AyeCode_UI_Settings; |
|
104 | + |
|
105 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | + |
|
107 | + if ( is_admin() ) { |
|
108 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | + |
|
111 | + // Maybe show example page |
|
112 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | + } |
|
114 | 114 | |
115 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | - |
|
117 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | - } |
|
119 | - |
|
120 | - return self::$instance; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Setup some constants. |
|
125 | - */ |
|
126 | - public function constants(){ |
|
127 | - define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | - define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | - if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | - if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Initiate the settings and add the required action hooks. |
|
135 | - */ |
|
136 | - public function init() { |
|
137 | - $this->constants(); |
|
138 | - $this->settings = $this->get_settings(); |
|
139 | - $this->url = $this->get_url(); |
|
140 | - |
|
141 | - /** |
|
142 | - * Maybe load CSS |
|
143 | - * |
|
144 | - * We load super early in case there is a theme version that might change the colors |
|
145 | - */ |
|
146 | - if ( $this->settings['css'] ) { |
|
147 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | - } |
|
149 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | - } |
|
152 | - |
|
153 | - // maybe load JS |
|
154 | - if ( $this->settings['js'] ) { |
|
155 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
156 | - } |
|
157 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
158 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
159 | - } |
|
160 | - |
|
161 | - // Maybe set the HTML font size |
|
162 | - if ( $this->settings['html_font_size'] ) { |
|
163 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Check if we should load the admin scripts or not. |
|
171 | - * |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function load_admin_scripts(){ |
|
175 | - $result = true; |
|
176 | - |
|
177 | - if(!empty($this->settings['disable_admin'])){ |
|
178 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
179 | - foreach($url_parts as $part){ |
|
180 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
181 | - return false; // return early, no point checking further |
|
182 | - } |
|
183 | - } |
|
184 | - } |
|
115 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | + |
|
117 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | + } |
|
119 | + |
|
120 | + return self::$instance; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Setup some constants. |
|
125 | + */ |
|
126 | + public function constants(){ |
|
127 | + define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | + define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | + if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | + if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Initiate the settings and add the required action hooks. |
|
135 | + */ |
|
136 | + public function init() { |
|
137 | + $this->constants(); |
|
138 | + $this->settings = $this->get_settings(); |
|
139 | + $this->url = $this->get_url(); |
|
140 | + |
|
141 | + /** |
|
142 | + * Maybe load CSS |
|
143 | + * |
|
144 | + * We load super early in case there is a theme version that might change the colors |
|
145 | + */ |
|
146 | + if ( $this->settings['css'] ) { |
|
147 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | + } |
|
149 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | + } |
|
152 | + |
|
153 | + // maybe load JS |
|
154 | + if ( $this->settings['js'] ) { |
|
155 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
156 | + } |
|
157 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
158 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
159 | + } |
|
160 | + |
|
161 | + // Maybe set the HTML font size |
|
162 | + if ( $this->settings['html_font_size'] ) { |
|
163 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Check if we should load the admin scripts or not. |
|
171 | + * |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function load_admin_scripts(){ |
|
175 | + $result = true; |
|
176 | + |
|
177 | + if(!empty($this->settings['disable_admin'])){ |
|
178 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
179 | + foreach($url_parts as $part){ |
|
180 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
181 | + return false; // return early, no point checking further |
|
182 | + } |
|
183 | + } |
|
184 | + } |
|
185 | 185 | |
186 | - return $result; |
|
187 | - } |
|
186 | + return $result; |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Add a html font size to the footer. |
|
191 | - */ |
|
192 | - public function html_font_size(){ |
|
193 | - $this->settings = $this->get_settings(); |
|
194 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
195 | - } |
|
189 | + /** |
|
190 | + * Add a html font size to the footer. |
|
191 | + */ |
|
192 | + public function html_font_size(){ |
|
193 | + $this->settings = $this->get_settings(); |
|
194 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Adds the Font Awesome styles. |
|
199 | - */ |
|
200 | - public function enqueue_style() { |
|
197 | + /** |
|
198 | + * Adds the Font Awesome styles. |
|
199 | + */ |
|
200 | + public function enqueue_style() { |
|
201 | 201 | |
202 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
202 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
203 | 203 | |
204 | - if($this->settings[$css_setting]){ |
|
205 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
206 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
207 | - wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
208 | - wp_enqueue_style( 'ayecode-ui' ); |
|
204 | + if($this->settings[$css_setting]){ |
|
205 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
206 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
207 | + wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
208 | + wp_enqueue_style( 'ayecode-ui' ); |
|
209 | 209 | |
210 | - // flatpickr |
|
211 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
210 | + // flatpickr |
|
211 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
212 | 212 | |
213 | 213 | |
214 | - // fix some wp-admin issues |
|
215 | - if(is_admin()){ |
|
216 | - $custom_css = " |
|
214 | + // fix some wp-admin issues |
|
215 | + if(is_admin()){ |
|
216 | + $custom_css = " |
|
217 | 217 | body{ |
218 | 218 | background-color: #f1f1f1; |
219 | 219 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -249,29 +249,29 @@ discard block |
||
249 | 249 | } |
250 | 250 | "; |
251 | 251 | |
252 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
253 | - $custom_css .= " |
|
252 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
253 | + $custom_css .= " |
|
254 | 254 | .edit-post-sidebar input[type=color].components-text-control__input{ |
255 | 255 | padding: 0; |
256 | 256 | } |
257 | 257 | "; |
258 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
259 | - } |
|
258 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
259 | + } |
|
260 | 260 | |
261 | - // custom changes |
|
262 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
261 | + // custom changes |
|
262 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
263 | 263 | |
264 | - } |
|
265 | - } |
|
264 | + } |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * Get inline script used if bootstrap enqueued |
|
269 | - * |
|
270 | - * If this remains small then its best to use this than to add another JS file. |
|
271 | - */ |
|
272 | - public function inline_script(){ |
|
273 | - ob_start(); |
|
274 | - ?> |
|
267 | + /** |
|
268 | + * Get inline script used if bootstrap enqueued |
|
269 | + * |
|
270 | + * If this remains small then its best to use this than to add another JS file. |
|
271 | + */ |
|
272 | + public function inline_script(){ |
|
273 | + ob_start(); |
|
274 | + ?> |
|
275 | 275 | <script> |
276 | 276 | |
277 | 277 | /** |
@@ -758,25 +758,25 @@ discard block |
||
758 | 758 | |
759 | 759 | </script> |
760 | 760 | <?php |
761 | - $output = ob_get_clean(); |
|
761 | + $output = ob_get_clean(); |
|
762 | 762 | |
763 | - /* |
|
763 | + /* |
|
764 | 764 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
765 | 765 | */ |
766 | - return str_replace( array( |
|
767 | - '<script>', |
|
768 | - '</script>' |
|
769 | - ), '', $output ); |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Get inline script used if bootstrap file browser enqueued. |
|
774 | - * |
|
775 | - * If this remains small then its best to use this than to add another JS file. |
|
776 | - */ |
|
777 | - public function inline_script_file_browser(){ |
|
778 | - ob_start(); |
|
779 | - ?> |
|
766 | + return str_replace( array( |
|
767 | + '<script>', |
|
768 | + '</script>' |
|
769 | + ), '', $output ); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Get inline script used if bootstrap file browser enqueued. |
|
774 | + * |
|
775 | + * If this remains small then its best to use this than to add another JS file. |
|
776 | + */ |
|
777 | + public function inline_script_file_browser(){ |
|
778 | + ob_start(); |
|
779 | + ?> |
|
780 | 780 | <script> |
781 | 781 | // run on doc ready |
782 | 782 | jQuery(document).ready(function () { |
@@ -784,184 +784,184 @@ discard block |
||
784 | 784 | }); |
785 | 785 | </script> |
786 | 786 | <?php |
787 | - $output = ob_get_clean(); |
|
787 | + $output = ob_get_clean(); |
|
788 | 788 | |
789 | - /* |
|
789 | + /* |
|
790 | 790 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
791 | 791 | */ |
792 | - return str_replace( array( |
|
793 | - '<script>', |
|
794 | - '</script>' |
|
795 | - ), '', $output ); |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * Adds the Font Awesome JS. |
|
800 | - */ |
|
801 | - public function enqueue_scripts() { |
|
802 | - |
|
803 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
804 | - |
|
805 | - // select2 |
|
806 | - wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
807 | - |
|
808 | - // flatpickr |
|
809 | - wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
810 | - |
|
811 | - // Bootstrap file browser |
|
812 | - wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
813 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
814 | - |
|
815 | - $load_inline = false; |
|
816 | - |
|
817 | - if($this->settings[$js_setting]=='core-popper'){ |
|
818 | - // Bootstrap bundle |
|
819 | - $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
820 | - wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
821 | - // if in admin then add to footer for compatibility. |
|
822 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
823 | - $script = $this->inline_script(); |
|
824 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
825 | - }elseif($this->settings[$js_setting]=='popper'){ |
|
826 | - $url = $this->url.'assets/js/popper.min.js'; |
|
827 | - wp_register_script( 'bootstrap-js-popper', $url, array('select2','jquery'), $this->latest ); |
|
828 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
829 | - $load_inline = true; |
|
830 | - }else{ |
|
831 | - $load_inline = true; |
|
832 | - } |
|
833 | - |
|
834 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
835 | - if($load_inline){ |
|
836 | - wp_register_script( 'bootstrap-dummy', '',array('select2','jquery') ); |
|
837 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
838 | - $script = $this->inline_script(); |
|
839 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
840 | - } |
|
841 | - |
|
842 | - } |
|
843 | - |
|
844 | - /** |
|
845 | - * Enqueue flatpickr if called. |
|
846 | - */ |
|
847 | - public function enqueue_flatpickr(){ |
|
848 | - wp_enqueue_style( 'flatpickr' ); |
|
849 | - wp_enqueue_script( 'flatpickr' ); |
|
850 | - } |
|
851 | - |
|
852 | - /** |
|
853 | - * Get the url path to the current folder. |
|
854 | - * |
|
855 | - * @return string |
|
856 | - */ |
|
857 | - public function get_url() { |
|
858 | - |
|
859 | - $url = ''; |
|
860 | - // check if we are inside a plugin |
|
861 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
862 | - |
|
863 | - // add check in-case user has changed wp-content dir name. |
|
864 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
865 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
866 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
867 | - |
|
868 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
869 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
870 | - } |
|
871 | - |
|
872 | - return $url; |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Register the database settings with WordPress. |
|
877 | - */ |
|
878 | - public function register_settings() { |
|
879 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * Add the WordPress settings menu item. |
|
884 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
885 | - */ |
|
886 | - public function menu_item() { |
|
887 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
888 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
889 | - $this, |
|
890 | - 'settings_page' |
|
891 | - ) ); |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Get a list of themes and their default JS settings. |
|
896 | - * |
|
897 | - * @return array |
|
898 | - */ |
|
899 | - public function theme_js_settings(){ |
|
900 | - return array( |
|
901 | - 'ayetheme' => 'popper', |
|
902 | - 'listimia' => 'required', |
|
903 | - 'listimia_backend' => 'core-popper', |
|
904 | - 'avada' => 'required', |
|
905 | - ); |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * Get the current Font Awesome output settings. |
|
910 | - * |
|
911 | - * @return array The array of settings. |
|
912 | - */ |
|
913 | - public function get_settings() { |
|
914 | - |
|
915 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
916 | - $js_default = 'core-popper'; |
|
917 | - $js_default_backend = $js_default; |
|
918 | - |
|
919 | - // maybe set defaults (if no settings set) |
|
920 | - if(empty($db_settings)){ |
|
921 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
922 | - $theme_js_settings = self::theme_js_settings(); |
|
923 | - if(isset($theme_js_settings[$active_theme])){ |
|
924 | - $js_default = $theme_js_settings[$active_theme]; |
|
925 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
926 | - } |
|
927 | - } |
|
928 | - |
|
929 | - $defaults = array( |
|
930 | - 'css' => 'compatibility', // core, compatibility |
|
931 | - 'js' => $js_default, // js to load, core-popper, popper |
|
932 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
933 | - 'css_backend' => 'compatibility', // core, compatibility |
|
934 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
935 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
936 | - ); |
|
937 | - |
|
938 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
939 | - |
|
940 | - /** |
|
941 | - * Filter the Bootstrap settings. |
|
942 | - * |
|
943 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
944 | - */ |
|
945 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - /** |
|
950 | - * The settings page html output. |
|
951 | - */ |
|
952 | - public function settings_page() { |
|
953 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
954 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
955 | - } |
|
956 | - ?> |
|
792 | + return str_replace( array( |
|
793 | + '<script>', |
|
794 | + '</script>' |
|
795 | + ), '', $output ); |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * Adds the Font Awesome JS. |
|
800 | + */ |
|
801 | + public function enqueue_scripts() { |
|
802 | + |
|
803 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
804 | + |
|
805 | + // select2 |
|
806 | + wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
807 | + |
|
808 | + // flatpickr |
|
809 | + wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
810 | + |
|
811 | + // Bootstrap file browser |
|
812 | + wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
813 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
814 | + |
|
815 | + $load_inline = false; |
|
816 | + |
|
817 | + if($this->settings[$js_setting]=='core-popper'){ |
|
818 | + // Bootstrap bundle |
|
819 | + $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
820 | + wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
821 | + // if in admin then add to footer for compatibility. |
|
822 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
823 | + $script = $this->inline_script(); |
|
824 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
825 | + }elseif($this->settings[$js_setting]=='popper'){ |
|
826 | + $url = $this->url.'assets/js/popper.min.js'; |
|
827 | + wp_register_script( 'bootstrap-js-popper', $url, array('select2','jquery'), $this->latest ); |
|
828 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
829 | + $load_inline = true; |
|
830 | + }else{ |
|
831 | + $load_inline = true; |
|
832 | + } |
|
833 | + |
|
834 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
835 | + if($load_inline){ |
|
836 | + wp_register_script( 'bootstrap-dummy', '',array('select2','jquery') ); |
|
837 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
838 | + $script = $this->inline_script(); |
|
839 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
840 | + } |
|
841 | + |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | + * Enqueue flatpickr if called. |
|
846 | + */ |
|
847 | + public function enqueue_flatpickr(){ |
|
848 | + wp_enqueue_style( 'flatpickr' ); |
|
849 | + wp_enqueue_script( 'flatpickr' ); |
|
850 | + } |
|
851 | + |
|
852 | + /** |
|
853 | + * Get the url path to the current folder. |
|
854 | + * |
|
855 | + * @return string |
|
856 | + */ |
|
857 | + public function get_url() { |
|
858 | + |
|
859 | + $url = ''; |
|
860 | + // check if we are inside a plugin |
|
861 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
862 | + |
|
863 | + // add check in-case user has changed wp-content dir name. |
|
864 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
865 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
866 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
867 | + |
|
868 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
869 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
870 | + } |
|
871 | + |
|
872 | + return $url; |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Register the database settings with WordPress. |
|
877 | + */ |
|
878 | + public function register_settings() { |
|
879 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * Add the WordPress settings menu item. |
|
884 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
885 | + */ |
|
886 | + public function menu_item() { |
|
887 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
888 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
889 | + $this, |
|
890 | + 'settings_page' |
|
891 | + ) ); |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Get a list of themes and their default JS settings. |
|
896 | + * |
|
897 | + * @return array |
|
898 | + */ |
|
899 | + public function theme_js_settings(){ |
|
900 | + return array( |
|
901 | + 'ayetheme' => 'popper', |
|
902 | + 'listimia' => 'required', |
|
903 | + 'listimia_backend' => 'core-popper', |
|
904 | + 'avada' => 'required', |
|
905 | + ); |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * Get the current Font Awesome output settings. |
|
910 | + * |
|
911 | + * @return array The array of settings. |
|
912 | + */ |
|
913 | + public function get_settings() { |
|
914 | + |
|
915 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
916 | + $js_default = 'core-popper'; |
|
917 | + $js_default_backend = $js_default; |
|
918 | + |
|
919 | + // maybe set defaults (if no settings set) |
|
920 | + if(empty($db_settings)){ |
|
921 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
922 | + $theme_js_settings = self::theme_js_settings(); |
|
923 | + if(isset($theme_js_settings[$active_theme])){ |
|
924 | + $js_default = $theme_js_settings[$active_theme]; |
|
925 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
926 | + } |
|
927 | + } |
|
928 | + |
|
929 | + $defaults = array( |
|
930 | + 'css' => 'compatibility', // core, compatibility |
|
931 | + 'js' => $js_default, // js to load, core-popper, popper |
|
932 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
933 | + 'css_backend' => 'compatibility', // core, compatibility |
|
934 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
935 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
936 | + ); |
|
937 | + |
|
938 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
939 | + |
|
940 | + /** |
|
941 | + * Filter the Bootstrap settings. |
|
942 | + * |
|
943 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
944 | + */ |
|
945 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + /** |
|
950 | + * The settings page html output. |
|
951 | + */ |
|
952 | + public function settings_page() { |
|
953 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
954 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
955 | + } |
|
956 | + ?> |
|
957 | 957 | <div class="wrap"> |
958 | 958 | <h1><?php echo $this->name; ?></h1> |
959 | 959 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p> |
960 | 960 | <form method="post" action="options.php"> |
961 | 961 | <?php |
962 | - settings_fields( 'ayecode-ui-settings' ); |
|
963 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
964 | - ?> |
|
962 | + settings_fields( 'ayecode-ui-settings' ); |
|
963 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
964 | + ?> |
|
965 | 965 | |
966 | 966 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
967 | 967 | <table class="form-table wpbs-table-settings"> |
@@ -1041,489 +1041,489 @@ discard block |
||
1041 | 1041 | </table> |
1042 | 1042 | |
1043 | 1043 | <?php |
1044 | - submit_button(); |
|
1045 | - ?> |
|
1044 | + submit_button(); |
|
1045 | + ?> |
|
1046 | 1046 | </form> |
1047 | 1047 | |
1048 | 1048 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
1049 | 1049 | </div> |
1050 | 1050 | |
1051 | 1051 | <?php |
1052 | - } |
|
1053 | - |
|
1054 | - public function customizer_settings($wp_customize){ |
|
1055 | - $wp_customize->add_section('aui_settings', array( |
|
1056 | - 'title' => __('AyeCode UI','aui'), |
|
1057 | - 'priority' => 120, |
|
1058 | - )); |
|
1059 | - |
|
1060 | - // ============================= |
|
1061 | - // = Color Picker = |
|
1062 | - // ============================= |
|
1063 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1064 | - 'default' => AUI_PRIMARY_COLOR, |
|
1065 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1066 | - 'capability' => 'edit_theme_options', |
|
1067 | - 'type' => 'option', |
|
1068 | - 'transport' => 'refresh', |
|
1069 | - )); |
|
1070 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1071 | - 'label' => __('Primary Color','aui'), |
|
1072 | - 'section' => 'aui_settings', |
|
1073 | - 'settings' => 'aui_options[color_primary]', |
|
1074 | - ))); |
|
1075 | - |
|
1076 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1077 | - 'default' => '#6c757d', |
|
1078 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1079 | - 'capability' => 'edit_theme_options', |
|
1080 | - 'type' => 'option', |
|
1081 | - 'transport' => 'refresh', |
|
1082 | - )); |
|
1083 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1084 | - 'label' => __('Secondary Color','aui'), |
|
1085 | - 'section' => 'aui_settings', |
|
1086 | - 'settings' => 'aui_options[color_secondary]', |
|
1087 | - ))); |
|
1088 | - } |
|
1089 | - |
|
1090 | - |
|
1091 | - public static function custom_css($compatibility = true) { |
|
1092 | - $settings = get_option('aui_options'); |
|
1093 | - |
|
1094 | - ob_start(); |
|
1095 | - |
|
1096 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1097 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1098 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
1099 | - ?> |
|
1052 | + } |
|
1053 | + |
|
1054 | + public function customizer_settings($wp_customize){ |
|
1055 | + $wp_customize->add_section('aui_settings', array( |
|
1056 | + 'title' => __('AyeCode UI','aui'), |
|
1057 | + 'priority' => 120, |
|
1058 | + )); |
|
1059 | + |
|
1060 | + // ============================= |
|
1061 | + // = Color Picker = |
|
1062 | + // ============================= |
|
1063 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1064 | + 'default' => AUI_PRIMARY_COLOR, |
|
1065 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1066 | + 'capability' => 'edit_theme_options', |
|
1067 | + 'type' => 'option', |
|
1068 | + 'transport' => 'refresh', |
|
1069 | + )); |
|
1070 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1071 | + 'label' => __('Primary Color','aui'), |
|
1072 | + 'section' => 'aui_settings', |
|
1073 | + 'settings' => 'aui_options[color_primary]', |
|
1074 | + ))); |
|
1075 | + |
|
1076 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1077 | + 'default' => '#6c757d', |
|
1078 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1079 | + 'capability' => 'edit_theme_options', |
|
1080 | + 'type' => 'option', |
|
1081 | + 'transport' => 'refresh', |
|
1082 | + )); |
|
1083 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1084 | + 'label' => __('Secondary Color','aui'), |
|
1085 | + 'section' => 'aui_settings', |
|
1086 | + 'settings' => 'aui_options[color_secondary]', |
|
1087 | + ))); |
|
1088 | + } |
|
1089 | + |
|
1090 | + |
|
1091 | + public static function custom_css($compatibility = true) { |
|
1092 | + $settings = get_option('aui_options'); |
|
1093 | + |
|
1094 | + ob_start(); |
|
1095 | + |
|
1096 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1097 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1098 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
1099 | + ?> |
|
1100 | 1100 | <style> |
1101 | 1101 | <?php |
1102 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1103 | - echo self::css_primary($primary_color,$compatibility); |
|
1104 | - } |
|
1102 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1103 | + echo self::css_primary($primary_color,$compatibility); |
|
1104 | + } |
|
1105 | 1105 | |
1106 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1107 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1108 | - } |
|
1106 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1107 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1108 | + } |
|
1109 | 1109 | ?> |
1110 | 1110 | </style> |
1111 | 1111 | <?php |
1112 | 1112 | |
1113 | 1113 | |
1114 | - /* |
|
1114 | + /* |
|
1115 | 1115 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1116 | 1116 | */ |
1117 | - return str_replace( array( |
|
1118 | - '<style>', |
|
1119 | - '</style>' |
|
1120 | - ), '', ob_get_clean()); |
|
1121 | - } |
|
1122 | - |
|
1123 | - public static function css_primary($color_code,$compatibility){; |
|
1124 | - $color_code = sanitize_hex_color($color_code); |
|
1125 | - if(!$color_code){return '';} |
|
1126 | - /** |
|
1127 | - * c = color, b = background color, o = border-color, f = fill |
|
1128 | - */ |
|
1129 | - $selectors = array( |
|
1130 | - 'a' => array('c'), |
|
1131 | - '.btn-primary' => array('b','o'), |
|
1132 | - '.btn-primary.disabled' => array('b','o'), |
|
1133 | - '.btn-primary:disabled' => array('b','o'), |
|
1134 | - '.btn-outline-primary' => array('c','o'), |
|
1135 | - '.btn-outline-primary:hover' => array('b','o'), |
|
1136 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1137 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1138 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1139 | - '.btn-link' => array('c'), |
|
1140 | - '.dropdown-item.active' => array('b'), |
|
1141 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1142 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1117 | + return str_replace( array( |
|
1118 | + '<style>', |
|
1119 | + '</style>' |
|
1120 | + ), '', ob_get_clean()); |
|
1121 | + } |
|
1122 | + |
|
1123 | + public static function css_primary($color_code,$compatibility){; |
|
1124 | + $color_code = sanitize_hex_color($color_code); |
|
1125 | + if(!$color_code){return '';} |
|
1126 | + /** |
|
1127 | + * c = color, b = background color, o = border-color, f = fill |
|
1128 | + */ |
|
1129 | + $selectors = array( |
|
1130 | + 'a' => array('c'), |
|
1131 | + '.btn-primary' => array('b','o'), |
|
1132 | + '.btn-primary.disabled' => array('b','o'), |
|
1133 | + '.btn-primary:disabled' => array('b','o'), |
|
1134 | + '.btn-outline-primary' => array('c','o'), |
|
1135 | + '.btn-outline-primary:hover' => array('b','o'), |
|
1136 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1137 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1138 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1139 | + '.btn-link' => array('c'), |
|
1140 | + '.dropdown-item.active' => array('b'), |
|
1141 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1142 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1143 | 1143 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
1144 | 1144 | // '.custom-range::-moz-range-thumb' => array('b'), |
1145 | 1145 | // '.custom-range::-ms-thumb' => array('b'), |
1146 | - '.nav-pills .nav-link.active' => array('b'), |
|
1147 | - '.nav-pills .show>.nav-link' => array('b'), |
|
1148 | - '.page-link' => array('c'), |
|
1149 | - '.page-item.active .page-link' => array('b','o'), |
|
1150 | - '.badge-primary' => array('b'), |
|
1151 | - '.alert-primary' => array('b','o'), |
|
1152 | - '.progress-bar' => array('b'), |
|
1153 | - '.list-group-item.active' => array('b','o'), |
|
1154 | - '.bg-primary' => array('b','f'), |
|
1155 | - '.btn-link.btn-primary' => array('c'), |
|
1156 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1157 | - ); |
|
1158 | - |
|
1159 | - $important_selectors = array( |
|
1160 | - '.bg-primary' => array('b','f'), |
|
1161 | - '.border-primary' => array('o'), |
|
1162 | - '.text-primary' => array('c'), |
|
1163 | - ); |
|
1164 | - |
|
1165 | - $color = array(); |
|
1166 | - $color_i = array(); |
|
1167 | - $background = array(); |
|
1168 | - $background_i = array(); |
|
1169 | - $border = array(); |
|
1170 | - $border_i = array(); |
|
1171 | - $fill = array(); |
|
1172 | - $fill_i = array(); |
|
1173 | - |
|
1174 | - $output = ''; |
|
1175 | - |
|
1176 | - // build rules into each type |
|
1177 | - foreach($selectors as $selector => $types){ |
|
1178 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1179 | - $types = array_combine($types,$types); |
|
1180 | - if(isset($types['c'])){$color[] = $selector;} |
|
1181 | - if(isset($types['b'])){$background[] = $selector;} |
|
1182 | - if(isset($types['o'])){$border[] = $selector;} |
|
1183 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1184 | - } |
|
1185 | - |
|
1186 | - // build rules into each type |
|
1187 | - foreach($important_selectors as $selector => $types){ |
|
1188 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1189 | - $types = array_combine($types,$types); |
|
1190 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1191 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1192 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1193 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1194 | - } |
|
1195 | - |
|
1196 | - // add any color rules |
|
1197 | - if(!empty($color)){ |
|
1198 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1199 | - } |
|
1200 | - if(!empty($color_i)){ |
|
1201 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1202 | - } |
|
1203 | - |
|
1204 | - // add any background color rules |
|
1205 | - if(!empty($background)){ |
|
1206 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1207 | - } |
|
1208 | - if(!empty($background_i)){ |
|
1209 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1210 | - } |
|
1211 | - |
|
1212 | - // add any border color rules |
|
1213 | - if(!empty($border)){ |
|
1214 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1215 | - } |
|
1216 | - if(!empty($border_i)){ |
|
1217 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1218 | - } |
|
1219 | - |
|
1220 | - // add any fill color rules |
|
1221 | - if(!empty($fill)){ |
|
1222 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1223 | - } |
|
1224 | - if(!empty($fill_i)){ |
|
1225 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1226 | - } |
|
1227 | - |
|
1228 | - |
|
1229 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1230 | - |
|
1231 | - // darken |
|
1232 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1233 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1234 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1235 | - |
|
1236 | - // lighten |
|
1237 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1238 | - |
|
1239 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1240 | - $op_25 = $color_code."40"; // 25% opacity |
|
1241 | - |
|
1242 | - |
|
1243 | - // button states |
|
1244 | - $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1245 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1246 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1247 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1248 | - |
|
1249 | - |
|
1250 | - // dropdown's |
|
1251 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1252 | - |
|
1253 | - |
|
1254 | - // input states |
|
1255 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1256 | - |
|
1257 | - // page link |
|
1258 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1259 | - |
|
1260 | - return $output; |
|
1261 | - } |
|
1262 | - |
|
1263 | - public static function css_secondary($color_code,$compatibility){; |
|
1264 | - $color_code = sanitize_hex_color($color_code); |
|
1265 | - if(!$color_code){return '';} |
|
1266 | - /** |
|
1267 | - * c = color, b = background color, o = border-color, f = fill |
|
1268 | - */ |
|
1269 | - $selectors = array( |
|
1270 | - '.btn-secondary' => array('b','o'), |
|
1271 | - '.btn-secondary.disabled' => array('b','o'), |
|
1272 | - '.btn-secondary:disabled' => array('b','o'), |
|
1273 | - '.btn-outline-secondary' => array('c','o'), |
|
1274 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
1275 | - '.btn-outline-secondary.disabled' => array('c'), |
|
1276 | - '.btn-outline-secondary:disabled' => array('c'), |
|
1277 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1278 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1279 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1280 | - '.badge-secondary' => array('b'), |
|
1281 | - '.alert-secondary' => array('b','o'), |
|
1282 | - '.btn-link.btn-secondary' => array('c'), |
|
1283 | - ); |
|
1284 | - |
|
1285 | - $important_selectors = array( |
|
1286 | - '.bg-secondary' => array('b','f'), |
|
1287 | - '.border-secondary' => array('o'), |
|
1288 | - '.text-secondary' => array('c'), |
|
1289 | - ); |
|
1290 | - |
|
1291 | - $color = array(); |
|
1292 | - $color_i = array(); |
|
1293 | - $background = array(); |
|
1294 | - $background_i = array(); |
|
1295 | - $border = array(); |
|
1296 | - $border_i = array(); |
|
1297 | - $fill = array(); |
|
1298 | - $fill_i = array(); |
|
1299 | - |
|
1300 | - $output = ''; |
|
1301 | - |
|
1302 | - // build rules into each type |
|
1303 | - foreach($selectors as $selector => $types){ |
|
1304 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1305 | - $types = array_combine($types,$types); |
|
1306 | - if(isset($types['c'])){$color[] = $selector;} |
|
1307 | - if(isset($types['b'])){$background[] = $selector;} |
|
1308 | - if(isset($types['o'])){$border[] = $selector;} |
|
1309 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1310 | - } |
|
1311 | - |
|
1312 | - // build rules into each type |
|
1313 | - foreach($important_selectors as $selector => $types){ |
|
1314 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1315 | - $types = array_combine($types,$types); |
|
1316 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1317 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1318 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1319 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1320 | - } |
|
1321 | - |
|
1322 | - // add any color rules |
|
1323 | - if(!empty($color)){ |
|
1324 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1325 | - } |
|
1326 | - if(!empty($color_i)){ |
|
1327 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1328 | - } |
|
1329 | - |
|
1330 | - // add any background color rules |
|
1331 | - if(!empty($background)){ |
|
1332 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1333 | - } |
|
1334 | - if(!empty($background_i)){ |
|
1335 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1336 | - } |
|
1337 | - |
|
1338 | - // add any border color rules |
|
1339 | - if(!empty($border)){ |
|
1340 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1341 | - } |
|
1342 | - if(!empty($border_i)){ |
|
1343 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1344 | - } |
|
1345 | - |
|
1346 | - // add any fill color rules |
|
1347 | - if(!empty($fill)){ |
|
1348 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1349 | - } |
|
1350 | - if(!empty($fill_i)){ |
|
1351 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1356 | - |
|
1357 | - // darken |
|
1358 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1359 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1360 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1361 | - |
|
1362 | - // lighten |
|
1363 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1364 | - |
|
1365 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1366 | - $op_25 = $color_code."40"; // 25% opacity |
|
1367 | - |
|
1368 | - |
|
1369 | - // button states |
|
1370 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1371 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1372 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1373 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1374 | - |
|
1375 | - |
|
1376 | - return $output; |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1381 | - * |
|
1382 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1383 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1384 | - * |
|
1385 | - * @return string |
|
1386 | - */ |
|
1387 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1388 | - $hexCode = ltrim($hexCode, '#'); |
|
1389 | - |
|
1390 | - if (strlen($hexCode) == 3) { |
|
1391 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1392 | - } |
|
1393 | - |
|
1394 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1395 | - |
|
1396 | - foreach ($hexCode as & $color) { |
|
1397 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1398 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1399 | - |
|
1400 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1401 | - } |
|
1402 | - |
|
1403 | - return '#' . implode($hexCode); |
|
1404 | - } |
|
1405 | - |
|
1406 | - /** |
|
1407 | - * Check if we should display examples. |
|
1408 | - */ |
|
1409 | - public function maybe_show_examples(){ |
|
1410 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1411 | - echo "<head>"; |
|
1412 | - wp_head(); |
|
1413 | - echo "</head>"; |
|
1414 | - echo "<body>"; |
|
1415 | - echo $this->get_examples(); |
|
1416 | - echo "</body>"; |
|
1417 | - exit; |
|
1418 | - } |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Get developer examples. |
|
1423 | - * |
|
1424 | - * @return string |
|
1425 | - */ |
|
1426 | - public function get_examples(){ |
|
1427 | - $output = ''; |
|
1428 | - |
|
1429 | - |
|
1430 | - // open form |
|
1431 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1432 | - |
|
1433 | - // input example |
|
1434 | - $output .= aui()->input(array( |
|
1435 | - 'type' => 'text', |
|
1436 | - 'id' => 'text-example', |
|
1437 | - 'name' => 'text-example', |
|
1438 | - 'placeholder' => 'text placeholder', |
|
1439 | - 'title' => 'Text input example', |
|
1440 | - 'value' => '', |
|
1441 | - 'required' => false, |
|
1442 | - 'help_text' => 'help text', |
|
1443 | - 'label' => 'Text input example label' |
|
1444 | - )); |
|
1445 | - |
|
1446 | - // input example |
|
1447 | - $output .= aui()->input(array( |
|
1448 | - 'type' => 'url', |
|
1449 | - 'id' => 'text-example2', |
|
1450 | - 'name' => 'text-example', |
|
1451 | - 'placeholder' => 'url placeholder', |
|
1452 | - 'title' => 'Text input example', |
|
1453 | - 'value' => '', |
|
1454 | - 'required' => false, |
|
1455 | - 'help_text' => 'help text', |
|
1456 | - 'label' => 'Text input example label' |
|
1457 | - )); |
|
1458 | - |
|
1459 | - // checkbox example |
|
1460 | - $output .= aui()->input(array( |
|
1461 | - 'type' => 'checkbox', |
|
1462 | - 'id' => 'checkbox-example', |
|
1463 | - 'name' => 'checkbox-example', |
|
1464 | - 'placeholder' => 'checkbox-example', |
|
1465 | - 'title' => 'Checkbox example', |
|
1466 | - 'value' => '1', |
|
1467 | - 'checked' => true, |
|
1468 | - 'required' => false, |
|
1469 | - 'help_text' => 'help text', |
|
1470 | - 'label' => 'Checkbox checked' |
|
1471 | - )); |
|
1472 | - |
|
1473 | - // checkbox example |
|
1474 | - $output .= aui()->input(array( |
|
1475 | - 'type' => 'checkbox', |
|
1476 | - 'id' => 'checkbox-example2', |
|
1477 | - 'name' => 'checkbox-example2', |
|
1478 | - 'placeholder' => 'checkbox-example', |
|
1479 | - 'title' => 'Checkbox example', |
|
1480 | - 'value' => '1', |
|
1481 | - 'checked' => false, |
|
1482 | - 'required' => false, |
|
1483 | - 'help_text' => 'help text', |
|
1484 | - 'label' => 'Checkbox un-checked' |
|
1485 | - )); |
|
1486 | - |
|
1487 | - // switch example |
|
1488 | - $output .= aui()->input(array( |
|
1489 | - 'type' => 'checkbox', |
|
1490 | - 'id' => 'switch-example', |
|
1491 | - 'name' => 'switch-example', |
|
1492 | - 'placeholder' => 'checkbox-example', |
|
1493 | - 'title' => 'Switch example', |
|
1494 | - 'value' => '1', |
|
1495 | - 'checked' => true, |
|
1496 | - 'switch' => true, |
|
1497 | - 'required' => false, |
|
1498 | - 'help_text' => 'help text', |
|
1499 | - 'label' => 'Switch on' |
|
1500 | - )); |
|
1501 | - |
|
1502 | - // switch example |
|
1503 | - $output .= aui()->input(array( |
|
1504 | - 'type' => 'checkbox', |
|
1505 | - 'id' => 'switch-example2', |
|
1506 | - 'name' => 'switch-example2', |
|
1507 | - 'placeholder' => 'checkbox-example', |
|
1508 | - 'title' => 'Switch example', |
|
1509 | - 'value' => '1', |
|
1510 | - 'checked' => false, |
|
1511 | - 'switch' => true, |
|
1512 | - 'required' => false, |
|
1513 | - 'help_text' => 'help text', |
|
1514 | - 'label' => 'Switch off' |
|
1515 | - )); |
|
1516 | - |
|
1517 | - // close form |
|
1518 | - $output .= "</form>"; |
|
1519 | - |
|
1520 | - return $output; |
|
1521 | - } |
|
1522 | - |
|
1523 | - } |
|
1524 | - |
|
1525 | - /** |
|
1526 | - * Run the class if found. |
|
1527 | - */ |
|
1528 | - AyeCode_UI_Settings::instance(); |
|
1146 | + '.nav-pills .nav-link.active' => array('b'), |
|
1147 | + '.nav-pills .show>.nav-link' => array('b'), |
|
1148 | + '.page-link' => array('c'), |
|
1149 | + '.page-item.active .page-link' => array('b','o'), |
|
1150 | + '.badge-primary' => array('b'), |
|
1151 | + '.alert-primary' => array('b','o'), |
|
1152 | + '.progress-bar' => array('b'), |
|
1153 | + '.list-group-item.active' => array('b','o'), |
|
1154 | + '.bg-primary' => array('b','f'), |
|
1155 | + '.btn-link.btn-primary' => array('c'), |
|
1156 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1157 | + ); |
|
1158 | + |
|
1159 | + $important_selectors = array( |
|
1160 | + '.bg-primary' => array('b','f'), |
|
1161 | + '.border-primary' => array('o'), |
|
1162 | + '.text-primary' => array('c'), |
|
1163 | + ); |
|
1164 | + |
|
1165 | + $color = array(); |
|
1166 | + $color_i = array(); |
|
1167 | + $background = array(); |
|
1168 | + $background_i = array(); |
|
1169 | + $border = array(); |
|
1170 | + $border_i = array(); |
|
1171 | + $fill = array(); |
|
1172 | + $fill_i = array(); |
|
1173 | + |
|
1174 | + $output = ''; |
|
1175 | + |
|
1176 | + // build rules into each type |
|
1177 | + foreach($selectors as $selector => $types){ |
|
1178 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1179 | + $types = array_combine($types,$types); |
|
1180 | + if(isset($types['c'])){$color[] = $selector;} |
|
1181 | + if(isset($types['b'])){$background[] = $selector;} |
|
1182 | + if(isset($types['o'])){$border[] = $selector;} |
|
1183 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1184 | + } |
|
1185 | + |
|
1186 | + // build rules into each type |
|
1187 | + foreach($important_selectors as $selector => $types){ |
|
1188 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1189 | + $types = array_combine($types,$types); |
|
1190 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1191 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1192 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1193 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1194 | + } |
|
1195 | + |
|
1196 | + // add any color rules |
|
1197 | + if(!empty($color)){ |
|
1198 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1199 | + } |
|
1200 | + if(!empty($color_i)){ |
|
1201 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1202 | + } |
|
1203 | + |
|
1204 | + // add any background color rules |
|
1205 | + if(!empty($background)){ |
|
1206 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1207 | + } |
|
1208 | + if(!empty($background_i)){ |
|
1209 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1210 | + } |
|
1211 | + |
|
1212 | + // add any border color rules |
|
1213 | + if(!empty($border)){ |
|
1214 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1215 | + } |
|
1216 | + if(!empty($border_i)){ |
|
1217 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1218 | + } |
|
1219 | + |
|
1220 | + // add any fill color rules |
|
1221 | + if(!empty($fill)){ |
|
1222 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1223 | + } |
|
1224 | + if(!empty($fill_i)){ |
|
1225 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1226 | + } |
|
1227 | + |
|
1228 | + |
|
1229 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1230 | + |
|
1231 | + // darken |
|
1232 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1233 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1234 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1235 | + |
|
1236 | + // lighten |
|
1237 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1238 | + |
|
1239 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1240 | + $op_25 = $color_code."40"; // 25% opacity |
|
1241 | + |
|
1242 | + |
|
1243 | + // button states |
|
1244 | + $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1245 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1246 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1247 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1248 | + |
|
1249 | + |
|
1250 | + // dropdown's |
|
1251 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1252 | + |
|
1253 | + |
|
1254 | + // input states |
|
1255 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1256 | + |
|
1257 | + // page link |
|
1258 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1259 | + |
|
1260 | + return $output; |
|
1261 | + } |
|
1262 | + |
|
1263 | + public static function css_secondary($color_code,$compatibility){; |
|
1264 | + $color_code = sanitize_hex_color($color_code); |
|
1265 | + if(!$color_code){return '';} |
|
1266 | + /** |
|
1267 | + * c = color, b = background color, o = border-color, f = fill |
|
1268 | + */ |
|
1269 | + $selectors = array( |
|
1270 | + '.btn-secondary' => array('b','o'), |
|
1271 | + '.btn-secondary.disabled' => array('b','o'), |
|
1272 | + '.btn-secondary:disabled' => array('b','o'), |
|
1273 | + '.btn-outline-secondary' => array('c','o'), |
|
1274 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
1275 | + '.btn-outline-secondary.disabled' => array('c'), |
|
1276 | + '.btn-outline-secondary:disabled' => array('c'), |
|
1277 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1278 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1279 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1280 | + '.badge-secondary' => array('b'), |
|
1281 | + '.alert-secondary' => array('b','o'), |
|
1282 | + '.btn-link.btn-secondary' => array('c'), |
|
1283 | + ); |
|
1284 | + |
|
1285 | + $important_selectors = array( |
|
1286 | + '.bg-secondary' => array('b','f'), |
|
1287 | + '.border-secondary' => array('o'), |
|
1288 | + '.text-secondary' => array('c'), |
|
1289 | + ); |
|
1290 | + |
|
1291 | + $color = array(); |
|
1292 | + $color_i = array(); |
|
1293 | + $background = array(); |
|
1294 | + $background_i = array(); |
|
1295 | + $border = array(); |
|
1296 | + $border_i = array(); |
|
1297 | + $fill = array(); |
|
1298 | + $fill_i = array(); |
|
1299 | + |
|
1300 | + $output = ''; |
|
1301 | + |
|
1302 | + // build rules into each type |
|
1303 | + foreach($selectors as $selector => $types){ |
|
1304 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1305 | + $types = array_combine($types,$types); |
|
1306 | + if(isset($types['c'])){$color[] = $selector;} |
|
1307 | + if(isset($types['b'])){$background[] = $selector;} |
|
1308 | + if(isset($types['o'])){$border[] = $selector;} |
|
1309 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1310 | + } |
|
1311 | + |
|
1312 | + // build rules into each type |
|
1313 | + foreach($important_selectors as $selector => $types){ |
|
1314 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1315 | + $types = array_combine($types,$types); |
|
1316 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1317 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1318 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1319 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1320 | + } |
|
1321 | + |
|
1322 | + // add any color rules |
|
1323 | + if(!empty($color)){ |
|
1324 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1325 | + } |
|
1326 | + if(!empty($color_i)){ |
|
1327 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1328 | + } |
|
1329 | + |
|
1330 | + // add any background color rules |
|
1331 | + if(!empty($background)){ |
|
1332 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1333 | + } |
|
1334 | + if(!empty($background_i)){ |
|
1335 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1336 | + } |
|
1337 | + |
|
1338 | + // add any border color rules |
|
1339 | + if(!empty($border)){ |
|
1340 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1341 | + } |
|
1342 | + if(!empty($border_i)){ |
|
1343 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1344 | + } |
|
1345 | + |
|
1346 | + // add any fill color rules |
|
1347 | + if(!empty($fill)){ |
|
1348 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1349 | + } |
|
1350 | + if(!empty($fill_i)){ |
|
1351 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1356 | + |
|
1357 | + // darken |
|
1358 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1359 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1360 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1361 | + |
|
1362 | + // lighten |
|
1363 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1364 | + |
|
1365 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1366 | + $op_25 = $color_code."40"; // 25% opacity |
|
1367 | + |
|
1368 | + |
|
1369 | + // button states |
|
1370 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1371 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1372 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1373 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1374 | + |
|
1375 | + |
|
1376 | + return $output; |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1381 | + * |
|
1382 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1383 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1384 | + * |
|
1385 | + * @return string |
|
1386 | + */ |
|
1387 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1388 | + $hexCode = ltrim($hexCode, '#'); |
|
1389 | + |
|
1390 | + if (strlen($hexCode) == 3) { |
|
1391 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1392 | + } |
|
1393 | + |
|
1394 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1395 | + |
|
1396 | + foreach ($hexCode as & $color) { |
|
1397 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1398 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1399 | + |
|
1400 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1401 | + } |
|
1402 | + |
|
1403 | + return '#' . implode($hexCode); |
|
1404 | + } |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * Check if we should display examples. |
|
1408 | + */ |
|
1409 | + public function maybe_show_examples(){ |
|
1410 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1411 | + echo "<head>"; |
|
1412 | + wp_head(); |
|
1413 | + echo "</head>"; |
|
1414 | + echo "<body>"; |
|
1415 | + echo $this->get_examples(); |
|
1416 | + echo "</body>"; |
|
1417 | + exit; |
|
1418 | + } |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Get developer examples. |
|
1423 | + * |
|
1424 | + * @return string |
|
1425 | + */ |
|
1426 | + public function get_examples(){ |
|
1427 | + $output = ''; |
|
1428 | + |
|
1429 | + |
|
1430 | + // open form |
|
1431 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1432 | + |
|
1433 | + // input example |
|
1434 | + $output .= aui()->input(array( |
|
1435 | + 'type' => 'text', |
|
1436 | + 'id' => 'text-example', |
|
1437 | + 'name' => 'text-example', |
|
1438 | + 'placeholder' => 'text placeholder', |
|
1439 | + 'title' => 'Text input example', |
|
1440 | + 'value' => '', |
|
1441 | + 'required' => false, |
|
1442 | + 'help_text' => 'help text', |
|
1443 | + 'label' => 'Text input example label' |
|
1444 | + )); |
|
1445 | + |
|
1446 | + // input example |
|
1447 | + $output .= aui()->input(array( |
|
1448 | + 'type' => 'url', |
|
1449 | + 'id' => 'text-example2', |
|
1450 | + 'name' => 'text-example', |
|
1451 | + 'placeholder' => 'url placeholder', |
|
1452 | + 'title' => 'Text input example', |
|
1453 | + 'value' => '', |
|
1454 | + 'required' => false, |
|
1455 | + 'help_text' => 'help text', |
|
1456 | + 'label' => 'Text input example label' |
|
1457 | + )); |
|
1458 | + |
|
1459 | + // checkbox example |
|
1460 | + $output .= aui()->input(array( |
|
1461 | + 'type' => 'checkbox', |
|
1462 | + 'id' => 'checkbox-example', |
|
1463 | + 'name' => 'checkbox-example', |
|
1464 | + 'placeholder' => 'checkbox-example', |
|
1465 | + 'title' => 'Checkbox example', |
|
1466 | + 'value' => '1', |
|
1467 | + 'checked' => true, |
|
1468 | + 'required' => false, |
|
1469 | + 'help_text' => 'help text', |
|
1470 | + 'label' => 'Checkbox checked' |
|
1471 | + )); |
|
1472 | + |
|
1473 | + // checkbox example |
|
1474 | + $output .= aui()->input(array( |
|
1475 | + 'type' => 'checkbox', |
|
1476 | + 'id' => 'checkbox-example2', |
|
1477 | + 'name' => 'checkbox-example2', |
|
1478 | + 'placeholder' => 'checkbox-example', |
|
1479 | + 'title' => 'Checkbox example', |
|
1480 | + 'value' => '1', |
|
1481 | + 'checked' => false, |
|
1482 | + 'required' => false, |
|
1483 | + 'help_text' => 'help text', |
|
1484 | + 'label' => 'Checkbox un-checked' |
|
1485 | + )); |
|
1486 | + |
|
1487 | + // switch example |
|
1488 | + $output .= aui()->input(array( |
|
1489 | + 'type' => 'checkbox', |
|
1490 | + 'id' => 'switch-example', |
|
1491 | + 'name' => 'switch-example', |
|
1492 | + 'placeholder' => 'checkbox-example', |
|
1493 | + 'title' => 'Switch example', |
|
1494 | + 'value' => '1', |
|
1495 | + 'checked' => true, |
|
1496 | + 'switch' => true, |
|
1497 | + 'required' => false, |
|
1498 | + 'help_text' => 'help text', |
|
1499 | + 'label' => 'Switch on' |
|
1500 | + )); |
|
1501 | + |
|
1502 | + // switch example |
|
1503 | + $output .= aui()->input(array( |
|
1504 | + 'type' => 'checkbox', |
|
1505 | + 'id' => 'switch-example2', |
|
1506 | + 'name' => 'switch-example2', |
|
1507 | + 'placeholder' => 'checkbox-example', |
|
1508 | + 'title' => 'Switch example', |
|
1509 | + 'value' => '1', |
|
1510 | + 'checked' => false, |
|
1511 | + 'switch' => true, |
|
1512 | + 'required' => false, |
|
1513 | + 'help_text' => 'help text', |
|
1514 | + 'label' => 'Switch off' |
|
1515 | + )); |
|
1516 | + |
|
1517 | + // close form |
|
1518 | + $output .= "</form>"; |
|
1519 | + |
|
1520 | + return $output; |
|
1521 | + } |
|
1522 | + |
|
1523 | + } |
|
1524 | + |
|
1525 | + /** |
|
1526 | + * Run the class if found. |
|
1527 | + */ |
|
1528 | + AyeCode_UI_Settings::instance(); |
|
1529 | 1529 | } |
1530 | 1530 | \ 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,231 +11,231 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds the class instance. |
|
16 | - * |
|
17 | - * @since 1.0.0 |
|
18 | - * @var null |
|
19 | - */ |
|
20 | - private static $instance = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * Holds the current AUI version number. |
|
24 | - * |
|
25 | - * @var string $ver The current version number. |
|
26 | - */ |
|
27 | - public static $ver = '0.1.33'; |
|
28 | - |
|
29 | - public static $options = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * There can be only one. |
|
33 | - * |
|
34 | - * @since 1.0.0 |
|
35 | - * @return AUI|null |
|
36 | - */ |
|
37 | - public static function instance() { |
|
38 | - if ( self::$instance == null ) { |
|
39 | - self::$instance = new AUI(); |
|
40 | - } |
|
41 | - |
|
42 | - return self::$instance; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * AUI constructor. |
|
47 | - * |
|
48 | - * @since 1.0.0 |
|
49 | - */ |
|
50 | - private function __construct() { |
|
51 | - if ( function_exists( "__autoload" ) ) { |
|
52 | - spl_autoload_register( "__autoload" ); |
|
53 | - } |
|
54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | - |
|
56 | - // load options |
|
57 | - self::$options = get_option('aui_options'); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Autoload any components on the fly. |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * |
|
65 | - * @param $classname |
|
66 | - */ |
|
67 | - private function autoload( $classname ) { |
|
68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
71 | - include_once( $file_path ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Get the AUI options. |
|
77 | - * |
|
78 | - * @param $option |
|
79 | - * |
|
80 | - * @return string|void |
|
81 | - */ |
|
82 | - public function get_option( $option ){ |
|
83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | - |
|
85 | - if ( ! $result && $option) { |
|
86 | - if( $option == 'color_primary' ){ |
|
87 | - $result = AUI_PRIMARY_COLOR; |
|
88 | - }elseif( $option == 'color_secondary' ){ |
|
89 | - $result = AUI_SECONDARY_COLOR; |
|
90 | - } |
|
91 | - } |
|
92 | - return $result; |
|
93 | - } |
|
94 | - |
|
95 | - public function render( $items = array() ) { |
|
96 | - $output = ''; |
|
97 | - |
|
98 | - if ( ! empty( $items ) ) { |
|
99 | - foreach ( $items as $args ) { |
|
100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | - $output .= $this->$render( $args ); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - return $output; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Render and return a bootstrap alert component. |
|
112 | - * |
|
113 | - * @since 1.0.0 |
|
114 | - * |
|
115 | - * @param array $args |
|
116 | - * |
|
117 | - * @return string The rendered component. |
|
118 | - */ |
|
119 | - public function alert( $args = array() ) { |
|
120 | - return AUI_Component_Alert::get( $args ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Render and return a bootstrap input component. |
|
125 | - * |
|
126 | - * @since 1.0.0 |
|
127 | - * |
|
128 | - * @param array $args |
|
129 | - * |
|
130 | - * @return string The rendered component. |
|
131 | - */ |
|
132 | - public function input( $args = array() ) { |
|
133 | - return AUI_Component_Input::input( $args ); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Render and return a bootstrap textarea component. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - * |
|
141 | - * @param array $args |
|
142 | - * |
|
143 | - * @return string The rendered component. |
|
144 | - */ |
|
145 | - public function textarea( $args = array() ) { |
|
146 | - return AUI_Component_Input::textarea( $args ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Render and return a bootstrap button component. |
|
151 | - * |
|
152 | - * @since 1.0.0 |
|
153 | - * |
|
154 | - * @param array $args |
|
155 | - * |
|
156 | - * @return string The rendered component. |
|
157 | - */ |
|
158 | - public function button( $args = array() ) { |
|
159 | - return AUI_Component_Button::get( $args ); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Render and return a bootstrap button component. |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - * |
|
167 | - * @param array $args |
|
168 | - * |
|
169 | - * @return string The rendered component. |
|
170 | - */ |
|
171 | - public function badge( $args = array() ) { |
|
172 | - $defaults = array( |
|
173 | - 'class' => 'badge badge-primary align-middle', |
|
174 | - ); |
|
175 | - |
|
176 | - // maybe set type |
|
177 | - if ( empty( $args['href'] ) ) { |
|
178 | - $defaults['type'] = 'badge'; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Parse incoming $args into an array and merge it with $defaults |
|
183 | - */ |
|
184 | - $args = wp_parse_args( $args, $defaults ); |
|
185 | - |
|
186 | - return AUI_Component_Button::get( $args ); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Render and return a bootstrap dropdown component. |
|
191 | - * |
|
192 | - * @since 1.0.0 |
|
193 | - * |
|
194 | - * @param array $args |
|
195 | - * |
|
196 | - * @return string The rendered component. |
|
197 | - */ |
|
198 | - public function dropdown( $args = array() ) { |
|
199 | - return AUI_Component_Dropdown::get( $args ); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Render and return a bootstrap select component. |
|
204 | - * |
|
205 | - * @since 1.0.0 |
|
206 | - * |
|
207 | - * @param array $args |
|
208 | - * |
|
209 | - * @return string The rendered component. |
|
210 | - */ |
|
211 | - public function select( $args = array() ) { |
|
212 | - return AUI_Component_Input::select( $args ); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Render and return a bootstrap radio component. |
|
217 | - * |
|
218 | - * @since 1.0.0 |
|
219 | - * |
|
220 | - * @param array $args |
|
221 | - * |
|
222 | - * @return string The rendered component. |
|
223 | - */ |
|
224 | - public function radio( $args = array() ) { |
|
225 | - return AUI_Component_Input::radio( $args ); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Render and return a bootstrap pagination component. |
|
230 | - * |
|
231 | - * @since 1.0.0 |
|
232 | - * |
|
233 | - * @param array $args |
|
234 | - * |
|
235 | - * @return string The rendered component. |
|
236 | - */ |
|
237 | - public function pagination( $args = array() ) { |
|
238 | - return AUI_Component_Pagination::get( $args ); |
|
239 | - } |
|
14 | + /** |
|
15 | + * Holds the class instance. |
|
16 | + * |
|
17 | + * @since 1.0.0 |
|
18 | + * @var null |
|
19 | + */ |
|
20 | + private static $instance = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * Holds the current AUI version number. |
|
24 | + * |
|
25 | + * @var string $ver The current version number. |
|
26 | + */ |
|
27 | + public static $ver = '0.1.33'; |
|
28 | + |
|
29 | + public static $options = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * There can be only one. |
|
33 | + * |
|
34 | + * @since 1.0.0 |
|
35 | + * @return AUI|null |
|
36 | + */ |
|
37 | + public static function instance() { |
|
38 | + if ( self::$instance == null ) { |
|
39 | + self::$instance = new AUI(); |
|
40 | + } |
|
41 | + |
|
42 | + return self::$instance; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * AUI constructor. |
|
47 | + * |
|
48 | + * @since 1.0.0 |
|
49 | + */ |
|
50 | + private function __construct() { |
|
51 | + if ( function_exists( "__autoload" ) ) { |
|
52 | + spl_autoload_register( "__autoload" ); |
|
53 | + } |
|
54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | + |
|
56 | + // load options |
|
57 | + self::$options = get_option('aui_options'); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Autoload any components on the fly. |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * |
|
65 | + * @param $classname |
|
66 | + */ |
|
67 | + private function autoload( $classname ) { |
|
68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
71 | + include_once( $file_path ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Get the AUI options. |
|
77 | + * |
|
78 | + * @param $option |
|
79 | + * |
|
80 | + * @return string|void |
|
81 | + */ |
|
82 | + public function get_option( $option ){ |
|
83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | + |
|
85 | + if ( ! $result && $option) { |
|
86 | + if( $option == 'color_primary' ){ |
|
87 | + $result = AUI_PRIMARY_COLOR; |
|
88 | + }elseif( $option == 'color_secondary' ){ |
|
89 | + $result = AUI_SECONDARY_COLOR; |
|
90 | + } |
|
91 | + } |
|
92 | + return $result; |
|
93 | + } |
|
94 | + |
|
95 | + public function render( $items = array() ) { |
|
96 | + $output = ''; |
|
97 | + |
|
98 | + if ( ! empty( $items ) ) { |
|
99 | + foreach ( $items as $args ) { |
|
100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | + $output .= $this->$render( $args ); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + return $output; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Render and return a bootstrap alert component. |
|
112 | + * |
|
113 | + * @since 1.0.0 |
|
114 | + * |
|
115 | + * @param array $args |
|
116 | + * |
|
117 | + * @return string The rendered component. |
|
118 | + */ |
|
119 | + public function alert( $args = array() ) { |
|
120 | + return AUI_Component_Alert::get( $args ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Render and return a bootstrap input component. |
|
125 | + * |
|
126 | + * @since 1.0.0 |
|
127 | + * |
|
128 | + * @param array $args |
|
129 | + * |
|
130 | + * @return string The rendered component. |
|
131 | + */ |
|
132 | + public function input( $args = array() ) { |
|
133 | + return AUI_Component_Input::input( $args ); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Render and return a bootstrap textarea component. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + * |
|
141 | + * @param array $args |
|
142 | + * |
|
143 | + * @return string The rendered component. |
|
144 | + */ |
|
145 | + public function textarea( $args = array() ) { |
|
146 | + return AUI_Component_Input::textarea( $args ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Render and return a bootstrap button component. |
|
151 | + * |
|
152 | + * @since 1.0.0 |
|
153 | + * |
|
154 | + * @param array $args |
|
155 | + * |
|
156 | + * @return string The rendered component. |
|
157 | + */ |
|
158 | + public function button( $args = array() ) { |
|
159 | + return AUI_Component_Button::get( $args ); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Render and return a bootstrap button component. |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + * |
|
167 | + * @param array $args |
|
168 | + * |
|
169 | + * @return string The rendered component. |
|
170 | + */ |
|
171 | + public function badge( $args = array() ) { |
|
172 | + $defaults = array( |
|
173 | + 'class' => 'badge badge-primary align-middle', |
|
174 | + ); |
|
175 | + |
|
176 | + // maybe set type |
|
177 | + if ( empty( $args['href'] ) ) { |
|
178 | + $defaults['type'] = 'badge'; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Parse incoming $args into an array and merge it with $defaults |
|
183 | + */ |
|
184 | + $args = wp_parse_args( $args, $defaults ); |
|
185 | + |
|
186 | + return AUI_Component_Button::get( $args ); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Render and return a bootstrap dropdown component. |
|
191 | + * |
|
192 | + * @since 1.0.0 |
|
193 | + * |
|
194 | + * @param array $args |
|
195 | + * |
|
196 | + * @return string The rendered component. |
|
197 | + */ |
|
198 | + public function dropdown( $args = array() ) { |
|
199 | + return AUI_Component_Dropdown::get( $args ); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Render and return a bootstrap select component. |
|
204 | + * |
|
205 | + * @since 1.0.0 |
|
206 | + * |
|
207 | + * @param array $args |
|
208 | + * |
|
209 | + * @return string The rendered component. |
|
210 | + */ |
|
211 | + public function select( $args = array() ) { |
|
212 | + return AUI_Component_Input::select( $args ); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Render and return a bootstrap radio component. |
|
217 | + * |
|
218 | + * @since 1.0.0 |
|
219 | + * |
|
220 | + * @param array $args |
|
221 | + * |
|
222 | + * @return string The rendered component. |
|
223 | + */ |
|
224 | + public function radio( $args = array() ) { |
|
225 | + return AUI_Component_Input::radio( $args ); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Render and return a bootstrap pagination component. |
|
230 | + * |
|
231 | + * @since 1.0.0 |
|
232 | + * |
|
233 | + * @param array $args |
|
234 | + * |
|
235 | + * @return string The rendered component. |
|
236 | + */ |
|
237 | + public function pagination( $args = array() ) { |
|
238 | + return AUI_Component_Pagination::get( $args ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | \ No newline at end of file |