@@ -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,395 +11,395 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Helper { |
13 | 13 | |
14 | - /** |
|
15 | - * A component helper for generating a input name. |
|
16 | - * |
|
17 | - * @param $text |
|
18 | - * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | - * |
|
20 | - * @return string |
|
21 | - */ |
|
22 | - public static function name( $text, $multiple = false ) { |
|
23 | - $output = ''; |
|
24 | - |
|
25 | - if ( $text ) { |
|
26 | - $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | - $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | - } |
|
29 | - |
|
30 | - return $output; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * A component helper for generating a item id. |
|
35 | - * |
|
36 | - * @param $text string The text to be used as the value. |
|
37 | - * |
|
38 | - * @return string The sanitized item. |
|
39 | - */ |
|
40 | - public static function id( $text ) { |
|
41 | - $output = ''; |
|
42 | - |
|
43 | - if ( $text ) { |
|
44 | - $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | - } |
|
46 | - |
|
47 | - return $output; |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * A component helper for generating a item title. |
|
52 | - * |
|
53 | - * @param $text string The text to be used as the value. |
|
54 | - * |
|
55 | - * @return string The sanitized item. |
|
56 | - */ |
|
57 | - public static function title( $text ) { |
|
58 | - $output = ''; |
|
59 | - |
|
60 | - if ( $text ) { |
|
61 | - $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | - } |
|
63 | - |
|
64 | - return $output; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * A component helper for generating a item value. |
|
69 | - * |
|
70 | - * @param $text string The text to be used as the value. |
|
71 | - * |
|
72 | - * @return string The sanitized item. |
|
73 | - */ |
|
74 | - public static function value( $text ) { |
|
75 | - $output = ''; |
|
76 | - |
|
77 | - if ( $text !== null && $text !== false ) { |
|
78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | - } |
|
80 | - |
|
81 | - return $output; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * A component helper for generating a item class attribute. |
|
86 | - * |
|
87 | - * @param $text string The text to be used as the value. |
|
88 | - * |
|
89 | - * @return string The sanitized item. |
|
90 | - */ |
|
91 | - public static function class_attr( $text ) { |
|
92 | - $output = ''; |
|
93 | - |
|
94 | - if ( $text ) { |
|
95 | - $classes = self::esc_classes( $text ); |
|
96 | - if ( ! empty( $classes ) ) { |
|
97 | - $output = ' class="' . $classes . '" '; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - return $output; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Escape a string of classes. |
|
106 | - * |
|
107 | - * @param $text |
|
108 | - * |
|
109 | - * @return string |
|
110 | - */ |
|
111 | - public static function esc_classes( $text ) { |
|
112 | - $output = ''; |
|
113 | - |
|
114 | - if ( $text ) { |
|
115 | - $classes = explode( " ", $text ); |
|
116 | - $classes = array_map( "trim", $classes ); |
|
117 | - $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | - if ( ! empty( $classes ) ) { |
|
119 | - $output = implode( " ", $classes ); |
|
120 | - } |
|
121 | - } |
|
122 | - |
|
123 | - return $output; |
|
124 | - |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * @param $args |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public static function data_attributes( $args ) { |
|
133 | - $output = ''; |
|
134 | - |
|
135 | - if ( ! empty( $args ) ) { |
|
136 | - |
|
137 | - foreach ( $args as $key => $val ) { |
|
138 | - if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
143 | - |
|
144 | - return $output; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @param $args |
|
149 | - * |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public static function aria_attributes( $args ) { |
|
153 | - $output = ''; |
|
154 | - |
|
155 | - if ( ! empty( $args ) ) { |
|
156 | - |
|
157 | - foreach ( $args as $key => $val ) { |
|
158 | - if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return $output; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Build a font awesome icon from a class. |
|
169 | - * |
|
170 | - * @param $class |
|
171 | - * @param bool $space_after |
|
172 | - * @param array $extra_attributes An array of extra attributes. |
|
173 | - * |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
177 | - $output = ''; |
|
178 | - |
|
179 | - if ( $class ) { |
|
180 | - $classes = self::esc_classes( $class ); |
|
181 | - if ( ! empty( $classes ) ) { |
|
182 | - $output = '<i class="' . $classes . '" '; |
|
183 | - // extra attributes |
|
184 | - if ( ! empty( $extra_attributes ) ) { |
|
185 | - $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
186 | - } |
|
187 | - $output .= '></i>'; |
|
188 | - if ( $space_after ) { |
|
189 | - $output .= " "; |
|
190 | - } |
|
191 | - } |
|
192 | - } |
|
193 | - |
|
194 | - return $output; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * @param $args |
|
199 | - * |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - public static function extra_attributes( $args ) { |
|
203 | - $output = ''; |
|
204 | - |
|
205 | - if ( ! empty( $args ) ) { |
|
206 | - |
|
207 | - if ( is_array( $args ) ) { |
|
208 | - foreach ( $args as $key => $val ) { |
|
209 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
210 | - } |
|
211 | - } else { |
|
212 | - $output .= ' ' . $args . ' '; |
|
213 | - } |
|
214 | - |
|
215 | - } |
|
216 | - |
|
217 | - return $output; |
|
218 | - } |
|
219 | - |
|
220 | - /** |
|
221 | - * @param $args |
|
222 | - * |
|
223 | - * @return string |
|
224 | - */ |
|
225 | - public static function help_text( $text ) { |
|
226 | - $output = ''; |
|
227 | - |
|
228 | - if ( $text ) { |
|
229 | - $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - return $output; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Replace element require context with JS. |
|
238 | - * |
|
239 | - * @param $input |
|
240 | - * |
|
241 | - * @return string|void |
|
242 | - */ |
|
243 | - public static function element_require( $input ) { |
|
244 | - |
|
245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | - |
|
247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | - "jQuery(form).find('[data-argument=\"", |
|
249 | - "\"]').find('input,select,textarea').val()", |
|
250 | - "\"]').find('input:checked').val()", |
|
251 | - ), $input ) ); |
|
252 | - |
|
253 | - if ( $output ) { |
|
254 | - $output = ' data-element-require="' . $output . '" '; |
|
255 | - } |
|
256 | - |
|
257 | - return $output; |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
262 | - * |
|
263 | - * @since 0.1.41 |
|
264 | - * |
|
265 | - * @param mixed $value The value to be stripped. |
|
266 | - * @param array $input Input Field. |
|
267 | - * |
|
268 | - * @return mixed Stripped value. |
|
269 | - */ |
|
270 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
271 | - $original = $value; |
|
272 | - |
|
273 | - if ( is_array( $value ) ) { |
|
274 | - foreach ( $value as $index => $item ) { |
|
275 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
276 | - } |
|
277 | - } elseif ( is_object( $value ) ) { |
|
278 | - $object_vars = get_object_vars( $value ); |
|
279 | - |
|
280 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
282 | - } |
|
283 | - } else { |
|
284 | - $value = self::_sanitize_html_field( $value, $input ); |
|
285 | - } |
|
286 | - |
|
287 | - /** |
|
288 | - * Filters content and keeps only allowable HTML elements. |
|
289 | - * |
|
290 | - * @since 0.1.41 |
|
291 | - * |
|
292 | - * @param string|array $value Content to filter through kses. |
|
293 | - * @param string|array $value Original content without filter. |
|
294 | - * @param array $input Input Field. |
|
295 | - */ |
|
296 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Filters content and keeps only allowable HTML elements. |
|
301 | - * |
|
302 | - * This function makes sure that only the allowed HTML element names, attribute |
|
303 | - * names and attribute values plus only sane HTML entities will occur in |
|
304 | - * $string. You have to remove any slashes from PHP's magic quotes before you |
|
305 | - * call this function. |
|
306 | - * |
|
307 | - * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
308 | - * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
309 | - * covers all common link protocols, except for 'javascript' which should not |
|
310 | - * be allowed for untrusted users. |
|
311 | - * |
|
312 | - * @since 0.1.41 |
|
313 | - * |
|
314 | - * @param string|array $value Content to filter through kses. |
|
315 | - * @param array $input Input Field. |
|
316 | - * |
|
317 | - * @return string Filtered content with only allowed HTML elements. |
|
318 | - */ |
|
319 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | - if ( $value === '' ) { |
|
321 | - return $value; |
|
322 | - } |
|
323 | - |
|
324 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
325 | - |
|
326 | - if ( ! is_array( $allowed_html ) ) { |
|
327 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
328 | - } |
|
329 | - |
|
330 | - $filtered = trim( wp_unslash( $value ) ); |
|
331 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
333 | - |
|
334 | - return $filtered; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Returns an array of allowed HTML tags and attributes for a given context. |
|
339 | - * |
|
340 | - * @since 0.1.41 |
|
341 | - * |
|
342 | - * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
343 | - * 'strip', 'data', 'entities', or the name of a field filter such as |
|
344 | - * 'pre_user_description'. |
|
345 | - * @param array $input Input. |
|
346 | - * |
|
347 | - * @return array Array of allowed HTML tags and their allowed attributes. |
|
348 | - */ |
|
349 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
351 | - |
|
352 | - if ( is_array( $allowed_html ) ) { |
|
353 | - // <iframe> |
|
354 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
355 | - $allowed_html['iframe'] = array( |
|
356 | - 'class' => true, |
|
357 | - 'id' => true, |
|
358 | - 'src' => true, |
|
359 | - 'width' => true, |
|
360 | - 'height' => true, |
|
361 | - 'frameborder' => true, |
|
362 | - 'marginwidth' => true, |
|
363 | - 'marginheight' => true, |
|
364 | - 'scrolling' => true, |
|
365 | - 'style' => true, |
|
366 | - 'title' => true, |
|
367 | - 'allow' => true, |
|
368 | - 'allowfullscreen' => true, |
|
369 | - 'data-*' => true, |
|
370 | - ); |
|
371 | - } |
|
372 | - } |
|
373 | - |
|
374 | - /** |
|
375 | - * Filters the allowed html tags. |
|
376 | - * |
|
377 | - * @since 0.1.41 |
|
378 | - * |
|
379 | - * @param array[]|string $allowed_html Allowed html tags. |
|
380 | - * @param @param string|array $context The context for which to retrieve tags. |
|
381 | - * @param array $input Input field. |
|
382 | - */ |
|
383 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
384 | - } |
|
385 | - |
|
386 | - public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
387 | - |
|
388 | - $class = ''; |
|
389 | - |
|
390 | - // set default if empty |
|
391 | - if( $label_number === '' ){ |
|
392 | - $label_number = 2; |
|
393 | - } |
|
394 | - |
|
395 | - if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | - if ( $type == 'label' ) { |
|
397 | - $class = 'col-sm-' . absint( $label_number ); |
|
398 | - } elseif ( $type == 'input' ) { |
|
399 | - $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
400 | - } |
|
401 | - } |
|
402 | - |
|
403 | - return $class; |
|
404 | - } |
|
14 | + /** |
|
15 | + * A component helper for generating a input name. |
|
16 | + * |
|
17 | + * @param $text |
|
18 | + * @param $multiple bool If the name is set to be multiple but no brackets found then we add some. |
|
19 | + * |
|
20 | + * @return string |
|
21 | + */ |
|
22 | + public static function name( $text, $multiple = false ) { |
|
23 | + $output = ''; |
|
24 | + |
|
25 | + if ( $text ) { |
|
26 | + $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | + $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | + } |
|
29 | + |
|
30 | + return $output; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * A component helper for generating a item id. |
|
35 | + * |
|
36 | + * @param $text string The text to be used as the value. |
|
37 | + * |
|
38 | + * @return string The sanitized item. |
|
39 | + */ |
|
40 | + public static function id( $text ) { |
|
41 | + $output = ''; |
|
42 | + |
|
43 | + if ( $text ) { |
|
44 | + $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | + } |
|
46 | + |
|
47 | + return $output; |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * A component helper for generating a item title. |
|
52 | + * |
|
53 | + * @param $text string The text to be used as the value. |
|
54 | + * |
|
55 | + * @return string The sanitized item. |
|
56 | + */ |
|
57 | + public static function title( $text ) { |
|
58 | + $output = ''; |
|
59 | + |
|
60 | + if ( $text ) { |
|
61 | + $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | + } |
|
63 | + |
|
64 | + return $output; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * A component helper for generating a item value. |
|
69 | + * |
|
70 | + * @param $text string The text to be used as the value. |
|
71 | + * |
|
72 | + * @return string The sanitized item. |
|
73 | + */ |
|
74 | + public static function value( $text ) { |
|
75 | + $output = ''; |
|
76 | + |
|
77 | + if ( $text !== null && $text !== false ) { |
|
78 | + $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | + } |
|
80 | + |
|
81 | + return $output; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * A component helper for generating a item class attribute. |
|
86 | + * |
|
87 | + * @param $text string The text to be used as the value. |
|
88 | + * |
|
89 | + * @return string The sanitized item. |
|
90 | + */ |
|
91 | + public static function class_attr( $text ) { |
|
92 | + $output = ''; |
|
93 | + |
|
94 | + if ( $text ) { |
|
95 | + $classes = self::esc_classes( $text ); |
|
96 | + if ( ! empty( $classes ) ) { |
|
97 | + $output = ' class="' . $classes . '" '; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + return $output; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Escape a string of classes. |
|
106 | + * |
|
107 | + * @param $text |
|
108 | + * |
|
109 | + * @return string |
|
110 | + */ |
|
111 | + public static function esc_classes( $text ) { |
|
112 | + $output = ''; |
|
113 | + |
|
114 | + if ( $text ) { |
|
115 | + $classes = explode( " ", $text ); |
|
116 | + $classes = array_map( "trim", $classes ); |
|
117 | + $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | + if ( ! empty( $classes ) ) { |
|
119 | + $output = implode( " ", $classes ); |
|
120 | + } |
|
121 | + } |
|
122 | + |
|
123 | + return $output; |
|
124 | + |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * @param $args |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public static function data_attributes( $args ) { |
|
133 | + $output = ''; |
|
134 | + |
|
135 | + if ( ! empty( $args ) ) { |
|
136 | + |
|
137 | + foreach ( $args as $key => $val ) { |
|
138 | + if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
140 | + } |
|
141 | + } |
|
142 | + } |
|
143 | + |
|
144 | + return $output; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @param $args |
|
149 | + * |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public static function aria_attributes( $args ) { |
|
153 | + $output = ''; |
|
154 | + |
|
155 | + if ( ! empty( $args ) ) { |
|
156 | + |
|
157 | + foreach ( $args as $key => $val ) { |
|
158 | + if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
160 | + } |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return $output; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Build a font awesome icon from a class. |
|
169 | + * |
|
170 | + * @param $class |
|
171 | + * @param bool $space_after |
|
172 | + * @param array $extra_attributes An array of extra attributes. |
|
173 | + * |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
177 | + $output = ''; |
|
178 | + |
|
179 | + if ( $class ) { |
|
180 | + $classes = self::esc_classes( $class ); |
|
181 | + if ( ! empty( $classes ) ) { |
|
182 | + $output = '<i class="' . $classes . '" '; |
|
183 | + // extra attributes |
|
184 | + if ( ! empty( $extra_attributes ) ) { |
|
185 | + $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
186 | + } |
|
187 | + $output .= '></i>'; |
|
188 | + if ( $space_after ) { |
|
189 | + $output .= " "; |
|
190 | + } |
|
191 | + } |
|
192 | + } |
|
193 | + |
|
194 | + return $output; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * @param $args |
|
199 | + * |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + public static function extra_attributes( $args ) { |
|
203 | + $output = ''; |
|
204 | + |
|
205 | + if ( ! empty( $args ) ) { |
|
206 | + |
|
207 | + if ( is_array( $args ) ) { |
|
208 | + foreach ( $args as $key => $val ) { |
|
209 | + $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
210 | + } |
|
211 | + } else { |
|
212 | + $output .= ' ' . $args . ' '; |
|
213 | + } |
|
214 | + |
|
215 | + } |
|
216 | + |
|
217 | + return $output; |
|
218 | + } |
|
219 | + |
|
220 | + /** |
|
221 | + * @param $args |
|
222 | + * |
|
223 | + * @return string |
|
224 | + */ |
|
225 | + public static function help_text( $text ) { |
|
226 | + $output = ''; |
|
227 | + |
|
228 | + if ( $text ) { |
|
229 | + $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + return $output; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Replace element require context with JS. |
|
238 | + * |
|
239 | + * @param $input |
|
240 | + * |
|
241 | + * @return string|void |
|
242 | + */ |
|
243 | + public static function element_require( $input ) { |
|
244 | + |
|
245 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
246 | + |
|
247 | + $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
248 | + "jQuery(form).find('[data-argument=\"", |
|
249 | + "\"]').find('input,select,textarea').val()", |
|
250 | + "\"]').find('input:checked').val()", |
|
251 | + ), $input ) ); |
|
252 | + |
|
253 | + if ( $output ) { |
|
254 | + $output = ' data-element-require="' . $output . '" '; |
|
255 | + } |
|
256 | + |
|
257 | + return $output; |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Navigates through an array, object, or scalar, and removes slashes from the values. |
|
262 | + * |
|
263 | + * @since 0.1.41 |
|
264 | + * |
|
265 | + * @param mixed $value The value to be stripped. |
|
266 | + * @param array $input Input Field. |
|
267 | + * |
|
268 | + * @return mixed Stripped value. |
|
269 | + */ |
|
270 | + public static function sanitize_html_field( $value, $input = array() ) { |
|
271 | + $original = $value; |
|
272 | + |
|
273 | + if ( is_array( $value ) ) { |
|
274 | + foreach ( $value as $index => $item ) { |
|
275 | + $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
276 | + } |
|
277 | + } elseif ( is_object( $value ) ) { |
|
278 | + $object_vars = get_object_vars( $value ); |
|
279 | + |
|
280 | + foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | + $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
282 | + } |
|
283 | + } else { |
|
284 | + $value = self::_sanitize_html_field( $value, $input ); |
|
285 | + } |
|
286 | + |
|
287 | + /** |
|
288 | + * Filters content and keeps only allowable HTML elements. |
|
289 | + * |
|
290 | + * @since 0.1.41 |
|
291 | + * |
|
292 | + * @param string|array $value Content to filter through kses. |
|
293 | + * @param string|array $value Original content without filter. |
|
294 | + * @param array $input Input Field. |
|
295 | + */ |
|
296 | + return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Filters content and keeps only allowable HTML elements. |
|
301 | + * |
|
302 | + * This function makes sure that only the allowed HTML element names, attribute |
|
303 | + * names and attribute values plus only sane HTML entities will occur in |
|
304 | + * $string. You have to remove any slashes from PHP's magic quotes before you |
|
305 | + * call this function. |
|
306 | + * |
|
307 | + * The default allowed protocols are 'http', 'https', 'ftp', 'mailto', 'news', |
|
308 | + * 'irc', 'gopher', 'nntp', 'feed', 'telnet, 'mms', 'rtsp' and 'svn'. This |
|
309 | + * covers all common link protocols, except for 'javascript' which should not |
|
310 | + * be allowed for untrusted users. |
|
311 | + * |
|
312 | + * @since 0.1.41 |
|
313 | + * |
|
314 | + * @param string|array $value Content to filter through kses. |
|
315 | + * @param array $input Input Field. |
|
316 | + * |
|
317 | + * @return string Filtered content with only allowed HTML elements. |
|
318 | + */ |
|
319 | + public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | + if ( $value === '' ) { |
|
321 | + return $value; |
|
322 | + } |
|
323 | + |
|
324 | + $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
325 | + |
|
326 | + if ( ! is_array( $allowed_html ) ) { |
|
327 | + $allowed_html = wp_kses_allowed_html( 'post' ); |
|
328 | + } |
|
329 | + |
|
330 | + $filtered = trim( wp_unslash( $value ) ); |
|
331 | + $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | + $filtered = balanceTags( $filtered ); // Balances tags |
|
333 | + |
|
334 | + return $filtered; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Returns an array of allowed HTML tags and attributes for a given context. |
|
339 | + * |
|
340 | + * @since 0.1.41 |
|
341 | + * |
|
342 | + * @param string|array $context The context for which to retrieve tags. Allowed values are 'post', |
|
343 | + * 'strip', 'data', 'entities', or the name of a field filter such as |
|
344 | + * 'pre_user_description'. |
|
345 | + * @param array $input Input. |
|
346 | + * |
|
347 | + * @return array Array of allowed HTML tags and their allowed attributes. |
|
348 | + */ |
|
349 | + public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | + $allowed_html = wp_kses_allowed_html( $context ); |
|
351 | + |
|
352 | + if ( is_array( $allowed_html ) ) { |
|
353 | + // <iframe> |
|
354 | + if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
355 | + $allowed_html['iframe'] = array( |
|
356 | + 'class' => true, |
|
357 | + 'id' => true, |
|
358 | + 'src' => true, |
|
359 | + 'width' => true, |
|
360 | + 'height' => true, |
|
361 | + 'frameborder' => true, |
|
362 | + 'marginwidth' => true, |
|
363 | + 'marginheight' => true, |
|
364 | + 'scrolling' => true, |
|
365 | + 'style' => true, |
|
366 | + 'title' => true, |
|
367 | + 'allow' => true, |
|
368 | + 'allowfullscreen' => true, |
|
369 | + 'data-*' => true, |
|
370 | + ); |
|
371 | + } |
|
372 | + } |
|
373 | + |
|
374 | + /** |
|
375 | + * Filters the allowed html tags. |
|
376 | + * |
|
377 | + * @since 0.1.41 |
|
378 | + * |
|
379 | + * @param array[]|string $allowed_html Allowed html tags. |
|
380 | + * @param @param string|array $context The context for which to retrieve tags. |
|
381 | + * @param array $input Input field. |
|
382 | + */ |
|
383 | + return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
384 | + } |
|
385 | + |
|
386 | + public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
387 | + |
|
388 | + $class = ''; |
|
389 | + |
|
390 | + // set default if empty |
|
391 | + if( $label_number === '' ){ |
|
392 | + $label_number = 2; |
|
393 | + } |
|
394 | + |
|
395 | + if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | + if ( $type == 'label' ) { |
|
397 | + $class = 'col-sm-' . absint( $label_number ); |
|
398 | + } elseif ( $type == 'input' ) { |
|
399 | + $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
400 | + } |
|
401 | + } |
|
402 | + |
|
403 | + return $class; |
|
404 | + } |
|
405 | 405 | } |
406 | 406 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -19,12 +19,12 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public static function name( $text, $multiple = false ) { |
|
22 | + public static function name($text, $multiple = false) { |
|
23 | 23 | $output = ''; |
24 | 24 | |
25 | - if ( $text ) { |
|
26 | - $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | - $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
25 | + if ($text) { |
|
26 | + $is_multiple = strpos($text, '[') === false && $multiple ? '[]' : ''; |
|
27 | + $output = ' name="' . esc_attr($text) . $is_multiple . '" '; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | return $output; |
@@ -37,11 +37,11 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return string The sanitized item. |
39 | 39 | */ |
40 | - public static function id( $text ) { |
|
40 | + public static function id($text) { |
|
41 | 41 | $output = ''; |
42 | 42 | |
43 | - if ( $text ) { |
|
44 | - $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
43 | + if ($text) { |
|
44 | + $output = ' id="' . sanitize_html_class($text) . '" '; |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | return $output; |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string The sanitized item. |
56 | 56 | */ |
57 | - public static function title( $text ) { |
|
57 | + public static function title($text) { |
|
58 | 58 | $output = ''; |
59 | 59 | |
60 | - if ( $text ) { |
|
61 | - $output = ' title="' . esc_attr( $text ) . '" '; |
|
60 | + if ($text) { |
|
61 | + $output = ' title="' . esc_attr($text) . '" '; |
|
62 | 62 | } |
63 | 63 | |
64 | 64 | return $output; |
@@ -71,11 +71,11 @@ discard block |
||
71 | 71 | * |
72 | 72 | * @return string The sanitized item. |
73 | 73 | */ |
74 | - public static function value( $text ) { |
|
74 | + public static function value($text) { |
|
75 | 75 | $output = ''; |
76 | 76 | |
77 | - if ( $text !== null && $text !== false ) { |
|
78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
77 | + if ($text !== null && $text !== false) { |
|
78 | + $output = ' value="' . esc_attr(wp_unslash($text)) . '" '; |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | return $output; |
@@ -88,12 +88,12 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string The sanitized item. |
90 | 90 | */ |
91 | - public static function class_attr( $text ) { |
|
91 | + public static function class_attr($text) { |
|
92 | 92 | $output = ''; |
93 | 93 | |
94 | - if ( $text ) { |
|
95 | - $classes = self::esc_classes( $text ); |
|
96 | - if ( ! empty( $classes ) ) { |
|
94 | + if ($text) { |
|
95 | + $classes = self::esc_classes($text); |
|
96 | + if (!empty($classes)) { |
|
97 | 97 | $output = ' class="' . $classes . '" '; |
98 | 98 | } |
99 | 99 | } |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | * |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - public static function esc_classes( $text ) { |
|
111 | + public static function esc_classes($text) { |
|
112 | 112 | $output = ''; |
113 | 113 | |
114 | - if ( $text ) { |
|
115 | - $classes = explode( " ", $text ); |
|
116 | - $classes = array_map( "trim", $classes ); |
|
117 | - $classes = array_map( "sanitize_html_class", $classes ); |
|
118 | - if ( ! empty( $classes ) ) { |
|
119 | - $output = implode( " ", $classes ); |
|
114 | + if ($text) { |
|
115 | + $classes = explode(" ", $text); |
|
116 | + $classes = array_map("trim", $classes); |
|
117 | + $classes = array_map("sanitize_html_class", $classes); |
|
118 | + if (!empty($classes)) { |
|
119 | + $output = implode(" ", $classes); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | |
@@ -129,14 +129,14 @@ discard block |
||
129 | 129 | * |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function data_attributes( $args ) { |
|
132 | + public static function data_attributes($args) { |
|
133 | 133 | $output = ''; |
134 | 134 | |
135 | - if ( ! empty( $args ) ) { |
|
135 | + if (!empty($args)) { |
|
136 | 136 | |
137 | - foreach ( $args as $key => $val ) { |
|
138 | - if ( substr( $key, 0, 5 ) === "data-" ) { |
|
139 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
137 | + foreach ($args as $key => $val) { |
|
138 | + if (substr($key, 0, 5) === "data-") { |
|
139 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | } |
@@ -149,14 +149,14 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return string |
151 | 151 | */ |
152 | - public static function aria_attributes( $args ) { |
|
152 | + public static function aria_attributes($args) { |
|
153 | 153 | $output = ''; |
154 | 154 | |
155 | - if ( ! empty( $args ) ) { |
|
155 | + if (!empty($args)) { |
|
156 | 156 | |
157 | - foreach ( $args as $key => $val ) { |
|
158 | - if ( substr( $key, 0, 5 ) === "aria-" ) { |
|
159 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
157 | + foreach ($args as $key => $val) { |
|
158 | + if (substr($key, 0, 5) === "aria-") { |
|
159 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
@@ -173,19 +173,19 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return string |
175 | 175 | */ |
176 | - public static function icon( $class, $space_after = false, $extra_attributes = array() ) { |
|
176 | + public static function icon($class, $space_after = false, $extra_attributes = array()) { |
|
177 | 177 | $output = ''; |
178 | 178 | |
179 | - if ( $class ) { |
|
180 | - $classes = self::esc_classes( $class ); |
|
181 | - if ( ! empty( $classes ) ) { |
|
179 | + if ($class) { |
|
180 | + $classes = self::esc_classes($class); |
|
181 | + if (!empty($classes)) { |
|
182 | 182 | $output = '<i class="' . $classes . '" '; |
183 | 183 | // extra attributes |
184 | - if ( ! empty( $extra_attributes ) ) { |
|
185 | - $output .= AUI_Component_Helper::extra_attributes( $extra_attributes ); |
|
184 | + if (!empty($extra_attributes)) { |
|
185 | + $output .= AUI_Component_Helper::extra_attributes($extra_attributes); |
|
186 | 186 | } |
187 | 187 | $output .= '></i>'; |
188 | - if ( $space_after ) { |
|
188 | + if ($space_after) { |
|
189 | 189 | $output .= " "; |
190 | 190 | } |
191 | 191 | } |
@@ -199,14 +199,14 @@ discard block |
||
199 | 199 | * |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public static function extra_attributes( $args ) { |
|
202 | + public static function extra_attributes($args) { |
|
203 | 203 | $output = ''; |
204 | 204 | |
205 | - if ( ! empty( $args ) ) { |
|
205 | + if (!empty($args)) { |
|
206 | 206 | |
207 | - if ( is_array( $args ) ) { |
|
208 | - foreach ( $args as $key => $val ) { |
|
209 | - $output .= ' ' . sanitize_html_class( $key ) . '="' . esc_attr( $val ) . '" '; |
|
207 | + if (is_array($args)) { |
|
208 | + foreach ($args as $key => $val) { |
|
209 | + $output .= ' ' . sanitize_html_class($key) . '="' . esc_attr($val) . '" '; |
|
210 | 210 | } |
211 | 211 | } else { |
212 | 212 | $output .= ' ' . $args . ' '; |
@@ -222,11 +222,11 @@ discard block |
||
222 | 222 | * |
223 | 223 | * @return string |
224 | 224 | */ |
225 | - public static function help_text( $text ) { |
|
225 | + public static function help_text($text) { |
|
226 | 226 | $output = ''; |
227 | 227 | |
228 | - if ( $text ) { |
|
229 | - $output .= '<small class="form-text text-muted">' . wp_kses_post( $text ) . '</small>'; |
|
228 | + if ($text) { |
|
229 | + $output .= '<small class="form-text text-muted">' . wp_kses_post($text) . '</small>'; |
|
230 | 230 | } |
231 | 231 | |
232 | 232 | |
@@ -240,17 +240,17 @@ discard block |
||
240 | 240 | * |
241 | 241 | * @return string|void |
242 | 242 | */ |
243 | - public static function element_require( $input ) { |
|
243 | + public static function element_require($input) { |
|
244 | 244 | |
245 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
245 | + $input = str_replace("'", '"', $input); // we only want double quotes |
|
246 | 246 | |
247 | - $output = esc_attr( str_replace( array( "[%", "%]", "%:checked]" ), array( |
|
247 | + $output = esc_attr(str_replace(array("[%", "%]", "%:checked]"), array( |
|
248 | 248 | "jQuery(form).find('[data-argument=\"", |
249 | 249 | "\"]').find('input,select,textarea').val()", |
250 | 250 | "\"]').find('input:checked').val()", |
251 | - ), $input ) ); |
|
251 | + ), $input)); |
|
252 | 252 | |
253 | - if ( $output ) { |
|
253 | + if ($output) { |
|
254 | 254 | $output = ' data-element-require="' . $output . '" '; |
255 | 255 | } |
256 | 256 | |
@@ -267,21 +267,21 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @return mixed Stripped value. |
269 | 269 | */ |
270 | - public static function sanitize_html_field( $value, $input = array() ) { |
|
270 | + public static function sanitize_html_field($value, $input = array()) { |
|
271 | 271 | $original = $value; |
272 | 272 | |
273 | - if ( is_array( $value ) ) { |
|
274 | - foreach ( $value as $index => $item ) { |
|
275 | - $value[ $index ] = self::_sanitize_html_field( $value, $input ); |
|
273 | + if (is_array($value)) { |
|
274 | + foreach ($value as $index => $item) { |
|
275 | + $value[$index] = self::_sanitize_html_field($value, $input); |
|
276 | 276 | } |
277 | - } elseif ( is_object( $value ) ) { |
|
278 | - $object_vars = get_object_vars( $value ); |
|
277 | + } elseif (is_object($value)) { |
|
278 | + $object_vars = get_object_vars($value); |
|
279 | 279 | |
280 | - foreach ( $object_vars as $property_name => $property_value ) { |
|
281 | - $value->$property_name = self::_sanitize_html_field( $property_value, $input ); |
|
280 | + foreach ($object_vars as $property_name => $property_value) { |
|
281 | + $value->$property_name = self::_sanitize_html_field($property_value, $input); |
|
282 | 282 | } |
283 | 283 | } else { |
284 | - $value = self::_sanitize_html_field( $value, $input ); |
|
284 | + $value = self::_sanitize_html_field($value, $input); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | /** |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | * @param string|array $value Original content without filter. |
294 | 294 | * @param array $input Input Field. |
295 | 295 | */ |
296 | - return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
296 | + return apply_filters('ayecode_ui_sanitize_html_field', $value, $original, $input); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | /** |
@@ -316,20 +316,20 @@ discard block |
||
316 | 316 | * |
317 | 317 | * @return string Filtered content with only allowed HTML elements. |
318 | 318 | */ |
319 | - public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | - if ( $value === '' ) { |
|
319 | + public static function _sanitize_html_field($value, $input = array()) { |
|
320 | + if ($value === '') { |
|
321 | 321 | return $value; |
322 | 322 | } |
323 | 323 | |
324 | - $allowed_html = self::kses_allowed_html( 'post', $input ); |
|
324 | + $allowed_html = self::kses_allowed_html('post', $input); |
|
325 | 325 | |
326 | - if ( ! is_array( $allowed_html ) ) { |
|
327 | - $allowed_html = wp_kses_allowed_html( 'post' ); |
|
326 | + if (!is_array($allowed_html)) { |
|
327 | + $allowed_html = wp_kses_allowed_html('post'); |
|
328 | 328 | } |
329 | 329 | |
330 | - $filtered = trim( wp_unslash( $value ) ); |
|
331 | - $filtered = wp_kses( $filtered, $allowed_html ); |
|
332 | - $filtered = balanceTags( $filtered ); // Balances tags |
|
330 | + $filtered = trim(wp_unslash($value)); |
|
331 | + $filtered = wp_kses($filtered, $allowed_html); |
|
332 | + $filtered = balanceTags($filtered); // Balances tags |
|
333 | 333 | |
334 | 334 | return $filtered; |
335 | 335 | } |
@@ -346,12 +346,12 @@ discard block |
||
346 | 346 | * |
347 | 347 | * @return array Array of allowed HTML tags and their allowed attributes. |
348 | 348 | */ |
349 | - public static function kses_allowed_html( $context = 'post', $input = array() ) { |
|
350 | - $allowed_html = wp_kses_allowed_html( $context ); |
|
349 | + public static function kses_allowed_html($context = 'post', $input = array()) { |
|
350 | + $allowed_html = wp_kses_allowed_html($context); |
|
351 | 351 | |
352 | - if ( is_array( $allowed_html ) ) { |
|
352 | + if (is_array($allowed_html)) { |
|
353 | 353 | // <iframe> |
354 | - if ( ! isset( $allowed_html['iframe'] ) && $context == 'post' ) { |
|
354 | + if (!isset($allowed_html['iframe']) && $context == 'post') { |
|
355 | 355 | $allowed_html['iframe'] = array( |
356 | 356 | 'class' => true, |
357 | 357 | 'id' => true, |
@@ -380,23 +380,23 @@ discard block |
||
380 | 380 | * @param @param string|array $context The context for which to retrieve tags. |
381 | 381 | * @param array $input Input field. |
382 | 382 | */ |
383 | - return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
383 | + return apply_filters('ayecode_ui_kses_allowed_html', $allowed_html, $context, $input); |
|
384 | 384 | } |
385 | 385 | |
386 | - public static function get_column_class( $label_number = 2, $type = 'label' ) { |
|
386 | + public static function get_column_class($label_number = 2, $type = 'label') { |
|
387 | 387 | |
388 | 388 | $class = ''; |
389 | 389 | |
390 | 390 | // set default if empty |
391 | - if( $label_number === '' ){ |
|
391 | + if ($label_number === '') { |
|
392 | 392 | $label_number = 2; |
393 | 393 | } |
394 | 394 | |
395 | - if ( $label_number && $label_number < 12 && $label_number > 0 ) { |
|
396 | - if ( $type == 'label' ) { |
|
397 | - $class = 'col-sm-' . absint( $label_number ); |
|
398 | - } elseif ( $type == 'input' ) { |
|
399 | - $class = 'col-sm-' . ( 12 - absint( $label_number ) ); |
|
395 | + if ($label_number && $label_number < 12 && $label_number > 0) { |
|
396 | + if ($type == 'label') { |
|
397 | + $class = 'col-sm-' . absint($label_number); |
|
398 | + } elseif ($type == 'input') { |
|
399 | + $class = 'col-sm-' . (12 - absint($label_number)); |
|
400 | 400 | } |
401 | 401 | } |
402 | 402 |
@@ -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,1179 +11,1179 @@ 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_col' => '2', |
|
36 | - 'label_type' => '', |
|
37 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
38 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
39 | - 'help_text' => '', |
|
40 | - 'validation_text' => '', |
|
41 | - 'validation_pattern' => '', |
|
42 | - 'no_wrap' => false, |
|
43 | - 'input_group_right' => '', |
|
44 | - 'input_group_left' => '', |
|
45 | - 'input_group_right_inside' => false, |
|
46 | - // forces the input group inside the input |
|
47 | - 'input_group_left_inside' => false, |
|
48 | - // forces the input group inside the input |
|
49 | - 'step' => '', |
|
50 | - 'switch' => false, |
|
51 | - // to show checkbox as a switch |
|
52 | - 'checked' => false, |
|
53 | - // set a checkbox or radio as selected |
|
54 | - 'password_toggle' => true, |
|
55 | - // toggle view/hide password |
|
56 | - 'element_require' => '', |
|
57 | - // [%element_id%] == "1" |
|
58 | - 'extra_attributes' => array(), |
|
59 | - // an array of extra attributes |
|
60 | - 'wrap_attributes' => array() |
|
61 | - ); |
|
62 | - |
|
63 | - /** |
|
64 | - * Parse incoming $args into an array and merge it with $defaults |
|
65 | - */ |
|
66 | - $args = wp_parse_args( $args, $defaults ); |
|
67 | - $output = ''; |
|
68 | - if ( ! empty( $args['type'] ) ) { |
|
69 | - // hidden label option needs to be empty |
|
70 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
71 | - |
|
72 | - $type = sanitize_html_class( $args['type'] ); |
|
73 | - |
|
74 | - $help_text = ''; |
|
75 | - $label = ''; |
|
76 | - $label_after = $args['label_after']; |
|
77 | - $label_args = array( |
|
78 | - 'title' => $args['label'], |
|
79 | - 'for' => $args['id'], |
|
80 | - 'class' => $args['label_class'] . " ", |
|
81 | - 'label_type' => $args['label_type'], |
|
82 | - 'label_col' => $args['label_col'] |
|
83 | - ); |
|
84 | - |
|
85 | - // floating labels need label after |
|
86 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
87 | - $label_after = true; |
|
88 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
89 | - } |
|
90 | - |
|
91 | - // Some special sauce for files |
|
92 | - if ( $type == 'file' ) { |
|
93 | - $label_after = true; // if type file we need the label after |
|
94 | - $args['class'] .= ' custom-file-input '; |
|
95 | - } elseif ( $type == 'checkbox' ) { |
|
96 | - $label_after = true; // if type file we need the label after |
|
97 | - $args['class'] .= ' custom-control-input '; |
|
98 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
99 | - $type = 'text'; |
|
100 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
101 | - $args['class'] .= ' bg-initial '; |
|
102 | - |
|
103 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
104 | - // enqueue the script |
|
105 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
106 | - $aui_settings->enqueue_flatpickr(); |
|
107 | - } elseif ( $type == 'iconpicker' ) { |
|
108 | - $type = 'text'; |
|
109 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
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_col' => '2', |
|
36 | + 'label_type' => '', |
|
37 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
38 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
39 | + 'help_text' => '', |
|
40 | + 'validation_text' => '', |
|
41 | + 'validation_pattern' => '', |
|
42 | + 'no_wrap' => false, |
|
43 | + 'input_group_right' => '', |
|
44 | + 'input_group_left' => '', |
|
45 | + 'input_group_right_inside' => false, |
|
46 | + // forces the input group inside the input |
|
47 | + 'input_group_left_inside' => false, |
|
48 | + // forces the input group inside the input |
|
49 | + 'step' => '', |
|
50 | + 'switch' => false, |
|
51 | + // to show checkbox as a switch |
|
52 | + 'checked' => false, |
|
53 | + // set a checkbox or radio as selected |
|
54 | + 'password_toggle' => true, |
|
55 | + // toggle view/hide password |
|
56 | + 'element_require' => '', |
|
57 | + // [%element_id%] == "1" |
|
58 | + 'extra_attributes' => array(), |
|
59 | + // an array of extra attributes |
|
60 | + 'wrap_attributes' => array() |
|
61 | + ); |
|
62 | + |
|
63 | + /** |
|
64 | + * Parse incoming $args into an array and merge it with $defaults |
|
65 | + */ |
|
66 | + $args = wp_parse_args( $args, $defaults ); |
|
67 | + $output = ''; |
|
68 | + if ( ! empty( $args['type'] ) ) { |
|
69 | + // hidden label option needs to be empty |
|
70 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
71 | + |
|
72 | + $type = sanitize_html_class( $args['type'] ); |
|
73 | + |
|
74 | + $help_text = ''; |
|
75 | + $label = ''; |
|
76 | + $label_after = $args['label_after']; |
|
77 | + $label_args = array( |
|
78 | + 'title' => $args['label'], |
|
79 | + 'for' => $args['id'], |
|
80 | + 'class' => $args['label_class'] . " ", |
|
81 | + 'label_type' => $args['label_type'], |
|
82 | + 'label_col' => $args['label_col'] |
|
83 | + ); |
|
84 | + |
|
85 | + // floating labels need label after |
|
86 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
87 | + $label_after = true; |
|
88 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
89 | + } |
|
90 | + |
|
91 | + // Some special sauce for files |
|
92 | + if ( $type == 'file' ) { |
|
93 | + $label_after = true; // if type file we need the label after |
|
94 | + $args['class'] .= ' custom-file-input '; |
|
95 | + } elseif ( $type == 'checkbox' ) { |
|
96 | + $label_after = true; // if type file we need the label after |
|
97 | + $args['class'] .= ' custom-control-input '; |
|
98 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
99 | + $type = 'text'; |
|
100 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
101 | + $args['class'] .= ' bg-initial '; |
|
102 | + |
|
103 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
104 | + // enqueue the script |
|
105 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
106 | + $aui_settings->enqueue_flatpickr(); |
|
107 | + } elseif ( $type == 'iconpicker' ) { |
|
108 | + $type = 'text'; |
|
109 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
110 | 110 | // $args['class'] .= ' bg-initial '; |
111 | 111 | |
112 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
113 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
112 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
113 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
114 | 114 | |
115 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
115 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
116 | 116 | // $args['input_group_right_inside'] = true; |
117 | - // enqueue the script |
|
118 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
119 | - $aui_settings->enqueue_iconpicker(); |
|
120 | - } |
|
121 | - |
|
122 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
123 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - // open/type |
|
128 | - $output .= '<input type="' . $type . '" '; |
|
129 | - |
|
130 | - // name |
|
131 | - if ( ! empty( $args['name'] ) ) { |
|
132 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
133 | - } |
|
134 | - |
|
135 | - // id |
|
136 | - if ( ! empty( $args['id'] ) ) { |
|
137 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
138 | - } |
|
139 | - |
|
140 | - // placeholder |
|
141 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
142 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
143 | - } |
|
144 | - |
|
145 | - // title |
|
146 | - if ( ! empty( $args['title'] ) ) { |
|
147 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
148 | - } |
|
149 | - |
|
150 | - // value |
|
151 | - if ( ! empty( $args['value'] ) ) { |
|
152 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
153 | - } |
|
154 | - |
|
155 | - // checked, for radio and checkboxes |
|
156 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
157 | - $output .= ' checked '; |
|
158 | - } |
|
159 | - |
|
160 | - // validation text |
|
161 | - if ( ! empty( $args['validation_text'] ) ) { |
|
162 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
163 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
164 | - } |
|
165 | - |
|
166 | - // validation_pattern |
|
167 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
168 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
169 | - } |
|
170 | - |
|
171 | - // step (for numbers) |
|
172 | - if ( ! empty( $args['step'] ) ) { |
|
173 | - $output .= ' step="' . $args['step'] . '" '; |
|
174 | - } |
|
175 | - |
|
176 | - // required |
|
177 | - if ( ! empty( $args['required'] ) ) { |
|
178 | - $output .= ' required '; |
|
179 | - } |
|
180 | - |
|
181 | - // class |
|
182 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
183 | - $output .= ' class="form-control ' . $class . '" '; |
|
184 | - |
|
185 | - // data-attributes |
|
186 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
187 | - |
|
188 | - // extra attributes |
|
189 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
190 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
191 | - } |
|
192 | - |
|
193 | - // close |
|
194 | - $output .= ' >'; |
|
195 | - |
|
196 | - // help text |
|
197 | - if ( ! empty( $args['help_text'] ) ) { |
|
198 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
199 | - } |
|
200 | - |
|
201 | - // label |
|
202 | - if ( ! empty( $args['label'] ) ) { |
|
203 | - $label_base_class = ''; |
|
204 | - if ( $type == 'file' ) { |
|
205 | - $label_base_class = ' custom-file-label'; |
|
206 | - } elseif ( $type == 'checkbox' ) { |
|
207 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
208 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
209 | - $help_text = ''; |
|
210 | - //$label_args['class'] .= ' d-inline '; |
|
211 | - $args['wrap_class'] .= ' align-items-center '; |
|
212 | - }else{ |
|
213 | - |
|
214 | - } |
|
215 | - |
|
216 | - $label_base_class = ' custom-control-label'; |
|
217 | - } |
|
218 | - $label_args['class'] .= $label_base_class; |
|
219 | - $temp_label_args = $label_args; |
|
220 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
221 | - $label = self::label( $temp_label_args, $type ); |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - |
|
226 | - |
|
227 | - // set help text in the correct position |
|
228 | - if ( $label_after ) { |
|
229 | - $output .= $label . $help_text; |
|
230 | - } |
|
231 | - |
|
232 | - // some input types need a separate wrap |
|
233 | - if ( $type == 'file' ) { |
|
234 | - $output = self::wrap( array( |
|
235 | - 'content' => $output, |
|
236 | - 'class' => 'form-group custom-file' |
|
237 | - ) ); |
|
238 | - } elseif ( $type == 'checkbox' ) { |
|
239 | - |
|
240 | - $label_args['title'] = $args['label']; |
|
241 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
242 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
243 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
244 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
245 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
246 | - $wrap_class .= ' d-flex align-content-center'; |
|
247 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
248 | - } |
|
249 | - $output = self::wrap( array( |
|
250 | - 'content' => $output, |
|
251 | - 'class' => 'custom-control ' . $wrap_class |
|
252 | - ) ); |
|
253 | - |
|
254 | - if ( $args['label_type'] == 'horizontal' ) { |
|
255 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
256 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
257 | - } |
|
258 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
259 | - |
|
260 | - |
|
261 | - // allow password field to toggle view |
|
262 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
117 | + // enqueue the script |
|
118 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
119 | + $aui_settings->enqueue_iconpicker(); |
|
120 | + } |
|
121 | + |
|
122 | + if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
123 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + // open/type |
|
128 | + $output .= '<input type="' . $type . '" '; |
|
129 | + |
|
130 | + // name |
|
131 | + if ( ! empty( $args['name'] ) ) { |
|
132 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
133 | + } |
|
134 | + |
|
135 | + // id |
|
136 | + if ( ! empty( $args['id'] ) ) { |
|
137 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
138 | + } |
|
139 | + |
|
140 | + // placeholder |
|
141 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
142 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
143 | + } |
|
144 | + |
|
145 | + // title |
|
146 | + if ( ! empty( $args['title'] ) ) { |
|
147 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
148 | + } |
|
149 | + |
|
150 | + // value |
|
151 | + if ( ! empty( $args['value'] ) ) { |
|
152 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
153 | + } |
|
154 | + |
|
155 | + // checked, for radio and checkboxes |
|
156 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
157 | + $output .= ' checked '; |
|
158 | + } |
|
159 | + |
|
160 | + // validation text |
|
161 | + if ( ! empty( $args['validation_text'] ) ) { |
|
162 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
163 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
164 | + } |
|
165 | + |
|
166 | + // validation_pattern |
|
167 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
168 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
169 | + } |
|
170 | + |
|
171 | + // step (for numbers) |
|
172 | + if ( ! empty( $args['step'] ) ) { |
|
173 | + $output .= ' step="' . $args['step'] . '" '; |
|
174 | + } |
|
175 | + |
|
176 | + // required |
|
177 | + if ( ! empty( $args['required'] ) ) { |
|
178 | + $output .= ' required '; |
|
179 | + } |
|
180 | + |
|
181 | + // class |
|
182 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
183 | + $output .= ' class="form-control ' . $class . '" '; |
|
184 | + |
|
185 | + // data-attributes |
|
186 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
187 | + |
|
188 | + // extra attributes |
|
189 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
190 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
191 | + } |
|
192 | + |
|
193 | + // close |
|
194 | + $output .= ' >'; |
|
195 | + |
|
196 | + // help text |
|
197 | + if ( ! empty( $args['help_text'] ) ) { |
|
198 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
199 | + } |
|
200 | + |
|
201 | + // label |
|
202 | + if ( ! empty( $args['label'] ) ) { |
|
203 | + $label_base_class = ''; |
|
204 | + if ( $type == 'file' ) { |
|
205 | + $label_base_class = ' custom-file-label'; |
|
206 | + } elseif ( $type == 'checkbox' ) { |
|
207 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
208 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
209 | + $help_text = ''; |
|
210 | + //$label_args['class'] .= ' d-inline '; |
|
211 | + $args['wrap_class'] .= ' align-items-center '; |
|
212 | + }else{ |
|
213 | + |
|
214 | + } |
|
215 | + |
|
216 | + $label_base_class = ' custom-control-label'; |
|
217 | + } |
|
218 | + $label_args['class'] .= $label_base_class; |
|
219 | + $temp_label_args = $label_args; |
|
220 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
221 | + $label = self::label( $temp_label_args, $type ); |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + |
|
226 | + |
|
227 | + // set help text in the correct position |
|
228 | + if ( $label_after ) { |
|
229 | + $output .= $label . $help_text; |
|
230 | + } |
|
231 | + |
|
232 | + // some input types need a separate wrap |
|
233 | + if ( $type == 'file' ) { |
|
234 | + $output = self::wrap( array( |
|
235 | + 'content' => $output, |
|
236 | + 'class' => 'form-group custom-file' |
|
237 | + ) ); |
|
238 | + } elseif ( $type == 'checkbox' ) { |
|
239 | + |
|
240 | + $label_args['title'] = $args['label']; |
|
241 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
242 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
243 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
244 | + $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
245 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
246 | + $wrap_class .= ' d-flex align-content-center'; |
|
247 | + $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
248 | + } |
|
249 | + $output = self::wrap( array( |
|
250 | + 'content' => $output, |
|
251 | + 'class' => 'custom-control ' . $wrap_class |
|
252 | + ) ); |
|
253 | + |
|
254 | + if ( $args['label_type'] == 'horizontal' ) { |
|
255 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
256 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
257 | + } |
|
258 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
259 | + |
|
260 | + |
|
261 | + // allow password field to toggle view |
|
262 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
263 | 263 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
264 | 264 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
265 | 265 | if($el.hasClass(\'fa-eye\')) |
266 | 266 | {$eli.attr(\'type\',\'text\');} |
267 | 267 | else{$eli.attr(\'type\',\'password\');}" |
268 | 268 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
269 | - } |
|
270 | - |
|
271 | - // input group wraps |
|
272 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
273 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
274 | - if ( $args['input_group_left'] ) { |
|
275 | - $output = self::wrap( array( |
|
276 | - 'content' => $output, |
|
277 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
278 | - 'input_group_left' => $args['input_group_left'], |
|
279 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
280 | - ) ); |
|
281 | - } |
|
282 | - if ( $args['input_group_right'] ) { |
|
283 | - $output = self::wrap( array( |
|
284 | - 'content' => $output, |
|
285 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
286 | - 'input_group_right' => $args['input_group_right'], |
|
287 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
288 | - ) ); |
|
289 | - } |
|
290 | - |
|
291 | - } |
|
292 | - |
|
293 | - if ( ! $label_after ) { |
|
294 | - $output .= $help_text; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
299 | - $output = self::wrap( array( |
|
300 | - 'content' => $output, |
|
301 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
302 | - ) ); |
|
303 | - } |
|
304 | - |
|
305 | - if ( ! $label_after ) { |
|
306 | - $output = $label . $output; |
|
307 | - } |
|
308 | - |
|
309 | - // wrap |
|
310 | - if ( ! $args['no_wrap'] ) { |
|
311 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
312 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
313 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
314 | - $output = self::wrap( array( |
|
315 | - 'content' => $output, |
|
316 | - 'class' => $wrap_class, |
|
317 | - 'element_require' => $args['element_require'], |
|
318 | - 'argument_id' => $args['id'], |
|
319 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
320 | - ) ); |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - return $output; |
|
325 | - } |
|
326 | - |
|
327 | - public static function label( $args = array(), $type = '' ) { |
|
328 | - //<label for="exampleInputEmail1">Email address</label> |
|
329 | - $defaults = array( |
|
330 | - 'title' => 'div', |
|
331 | - 'for' => '', |
|
332 | - 'class' => '', |
|
333 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
334 | - 'label_col' => '', |
|
335 | - ); |
|
336 | - |
|
337 | - /** |
|
338 | - * Parse incoming $args into an array and merge it with $defaults |
|
339 | - */ |
|
340 | - $args = wp_parse_args( $args, $defaults ); |
|
341 | - $output = ''; |
|
342 | - |
|
343 | - if ( $args['title'] ) { |
|
344 | - |
|
345 | - // maybe hide labels //@todo set a global option for visibility class |
|
346 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
347 | - $class = $args['class']; |
|
348 | - } else { |
|
349 | - $class = 'sr-only ' . $args['class']; |
|
350 | - } |
|
351 | - |
|
352 | - // maybe horizontal |
|
353 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
354 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
355 | - } |
|
356 | - |
|
357 | - // open |
|
358 | - $output .= '<label '; |
|
359 | - |
|
360 | - // for |
|
361 | - if ( ! empty( $args['for'] ) ) { |
|
362 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
363 | - } |
|
364 | - |
|
365 | - // class |
|
366 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
367 | - $output .= ' class="' . $class . '" '; |
|
368 | - |
|
369 | - // close |
|
370 | - $output .= '>'; |
|
371 | - |
|
372 | - |
|
373 | - // title, don't escape fully as can contain html |
|
374 | - if ( ! empty( $args['title'] ) ) { |
|
375 | - $output .= wp_kses_post( $args['title'] ); |
|
376 | - } |
|
377 | - |
|
378 | - // close wrap |
|
379 | - $output .= '</label>'; |
|
380 | - |
|
381 | - |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - return $output; |
|
386 | - } |
|
387 | - |
|
388 | - /** |
|
389 | - * Wrap some content in a HTML wrapper. |
|
390 | - * |
|
391 | - * @param array $args |
|
392 | - * |
|
393 | - * @return string |
|
394 | - */ |
|
395 | - public static function wrap( $args = array() ) { |
|
396 | - $defaults = array( |
|
397 | - 'type' => 'div', |
|
398 | - 'class' => 'form-group', |
|
399 | - 'content' => '', |
|
400 | - 'input_group_left' => '', |
|
401 | - 'input_group_right' => '', |
|
402 | - 'input_group_left_inside' => false, |
|
403 | - 'input_group_right_inside' => false, |
|
404 | - 'element_require' => '', |
|
405 | - 'argument_id' => '', |
|
406 | - 'wrap_attributes' => array() |
|
407 | - ); |
|
408 | - |
|
409 | - /** |
|
410 | - * Parse incoming $args into an array and merge it with $defaults |
|
411 | - */ |
|
412 | - $args = wp_parse_args( $args, $defaults ); |
|
413 | - $output = ''; |
|
414 | - if ( $args['type'] ) { |
|
415 | - |
|
416 | - // open |
|
417 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
418 | - |
|
419 | - // element require |
|
420 | - if ( ! empty( $args['element_require'] ) ) { |
|
421 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
422 | - $args['class'] .= " aui-conditional-field"; |
|
423 | - } |
|
424 | - |
|
425 | - // argument_id |
|
426 | - if ( ! empty( $args['argument_id'] ) ) { |
|
427 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
428 | - } |
|
429 | - |
|
430 | - // class |
|
431 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
432 | - $output .= ' class="' . $class . '" '; |
|
433 | - |
|
434 | - // Attributes |
|
435 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
436 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
437 | - } |
|
438 | - |
|
439 | - // close wrap |
|
440 | - $output .= ' >'; |
|
441 | - |
|
442 | - |
|
443 | - // Input group left |
|
444 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
445 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
446 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
447 | - $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
448 | - } |
|
449 | - |
|
450 | - // content |
|
451 | - $output .= $args['content']; |
|
452 | - |
|
453 | - // Input group right |
|
454 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
455 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
456 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
457 | - $output .= '<div class="input-group-append ' . $position_class . '">' . $input_group_right . '</div>'; |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - // close wrap |
|
462 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
463 | - |
|
464 | - |
|
465 | - } else { |
|
466 | - $output = $args['content']; |
|
467 | - } |
|
468 | - |
|
469 | - return $output; |
|
470 | - } |
|
471 | - |
|
472 | - /** |
|
473 | - * Build the component. |
|
474 | - * |
|
475 | - * @param array $args |
|
476 | - * |
|
477 | - * @return string The rendered component. |
|
478 | - */ |
|
479 | - public static function textarea( $args = array() ) { |
|
480 | - $defaults = array( |
|
481 | - 'name' => '', |
|
482 | - 'class' => '', |
|
483 | - 'wrap_class' => '', |
|
484 | - 'id' => '', |
|
485 | - 'placeholder' => '', |
|
486 | - 'title' => '', |
|
487 | - 'value' => '', |
|
488 | - 'required' => false, |
|
489 | - 'label' => '', |
|
490 | - 'label_after' => false, |
|
491 | - 'label_class' => '', |
|
492 | - 'label_type' => '', |
|
493 | - 'label_col' => '', |
|
494 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
495 | - 'help_text' => '', |
|
496 | - 'validation_text' => '', |
|
497 | - 'validation_pattern' => '', |
|
498 | - 'no_wrap' => false, |
|
499 | - 'rows' => '', |
|
500 | - 'wysiwyg' => false, |
|
501 | - 'allow_tags' => false, |
|
502 | - // Allow HTML tags |
|
503 | - 'element_require' => '', |
|
504 | - // [%element_id%] == "1" |
|
505 | - 'extra_attributes' => array(), |
|
506 | - // an array of extra attributes |
|
507 | - 'wrap_attributes' => array(), |
|
508 | - ); |
|
509 | - |
|
510 | - /** |
|
511 | - * Parse incoming $args into an array and merge it with $defaults |
|
512 | - */ |
|
513 | - $args = wp_parse_args( $args, $defaults ); |
|
514 | - $output = ''; |
|
515 | - |
|
516 | - // hidden label option needs to be empty |
|
517 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
518 | - |
|
519 | - // floating labels don't work with wysiwyg so set it as top |
|
520 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
521 | - $args['label_type'] = 'top'; |
|
522 | - } |
|
523 | - |
|
524 | - $label_after = $args['label_after']; |
|
525 | - |
|
526 | - // floating labels need label after |
|
527 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
528 | - $label_after = true; |
|
529 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
530 | - } |
|
531 | - |
|
532 | - // label |
|
533 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
534 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
535 | - $label_args = array( |
|
536 | - 'title' => $args['label'], |
|
537 | - 'for' => $args['id'], |
|
538 | - 'class' => $args['label_class'] . " ", |
|
539 | - 'label_type' => $args['label_type'], |
|
540 | - 'label_col' => $args['label_col'] |
|
541 | - ); |
|
542 | - $output .= self::label( $label_args ); |
|
543 | - } |
|
544 | - |
|
545 | - // maybe horizontal label |
|
546 | - if ( $args['label_type'] == 'horizontal' ) { |
|
547 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
548 | - $output .= '<div class="' . $input_col . '">'; |
|
549 | - } |
|
550 | - |
|
551 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
552 | - ob_start(); |
|
553 | - $content = $args['value']; |
|
554 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
555 | - $settings = array( |
|
556 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
557 | - 'quicktags' => false, |
|
558 | - 'media_buttons' => false, |
|
559 | - 'editor_class' => 'form-control', |
|
560 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
561 | - 'teeny' => true, |
|
562 | - ); |
|
563 | - |
|
564 | - // maybe set settings if array |
|
565 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
566 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
567 | - } |
|
568 | - |
|
569 | - wp_editor( $content, $editor_id, $settings ); |
|
570 | - $output .= ob_get_clean(); |
|
571 | - } else { |
|
572 | - |
|
573 | - // open |
|
574 | - $output .= '<textarea '; |
|
575 | - |
|
576 | - // name |
|
577 | - if ( ! empty( $args['name'] ) ) { |
|
578 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
579 | - } |
|
580 | - |
|
581 | - // id |
|
582 | - if ( ! empty( $args['id'] ) ) { |
|
583 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
584 | - } |
|
585 | - |
|
586 | - // placeholder |
|
587 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
588 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
589 | - } |
|
590 | - |
|
591 | - // title |
|
592 | - if ( ! empty( $args['title'] ) ) { |
|
593 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
594 | - } |
|
595 | - |
|
596 | - // validation text |
|
597 | - if ( ! empty( $args['validation_text'] ) ) { |
|
598 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
599 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
600 | - } |
|
601 | - |
|
602 | - // validation_pattern |
|
603 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
604 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
605 | - } |
|
606 | - |
|
607 | - // required |
|
608 | - if ( ! empty( $args['required'] ) ) { |
|
609 | - $output .= ' required '; |
|
610 | - } |
|
611 | - |
|
612 | - // rows |
|
613 | - if ( ! empty( $args['rows'] ) ) { |
|
614 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - // class |
|
619 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
620 | - $output .= ' class="form-control ' . $class . '" '; |
|
621 | - |
|
622 | - // extra attributes |
|
623 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
624 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
625 | - } |
|
626 | - |
|
627 | - // close tag |
|
628 | - $output .= ' >'; |
|
629 | - |
|
630 | - // value |
|
631 | - if ( ! empty( $args['value'] ) ) { |
|
632 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
633 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
634 | - } else { |
|
635 | - $output .= sanitize_textarea_field( $args['value'] ); |
|
636 | - } |
|
637 | - } |
|
638 | - |
|
639 | - // closing tag |
|
640 | - $output .= '</textarea>'; |
|
641 | - |
|
642 | - } |
|
643 | - |
|
644 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
645 | - $label_args = array( |
|
646 | - 'title' => $args['label'], |
|
647 | - 'for' => $args['id'], |
|
648 | - 'class' => $args['label_class'] . " ", |
|
649 | - 'label_type' => $args['label_type'], |
|
650 | - 'label_col' => $args['label_col'] |
|
651 | - ); |
|
652 | - $output .= self::label( $label_args ); |
|
653 | - } |
|
654 | - |
|
655 | - // help text |
|
656 | - if ( ! empty( $args['help_text'] ) ) { |
|
657 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
658 | - } |
|
659 | - |
|
660 | - // maybe horizontal label |
|
661 | - if ( $args['label_type'] == 'horizontal' ) { |
|
662 | - $output .= '</div>'; |
|
663 | - } |
|
664 | - |
|
665 | - |
|
666 | - // wrap |
|
667 | - if ( ! $args['no_wrap'] ) { |
|
668 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
669 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
670 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
671 | - $output = self::wrap( array( |
|
672 | - 'content' => $output, |
|
673 | - 'class' => $wrap_class, |
|
674 | - 'element_require' => $args['element_require'], |
|
675 | - 'argument_id' => $args['id'], |
|
676 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
677 | - ) ); |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - return $output; |
|
682 | - } |
|
683 | - |
|
684 | - /** |
|
685 | - * Build the component. |
|
686 | - * |
|
687 | - * @param array $args |
|
688 | - * |
|
689 | - * @return string The rendered component. |
|
690 | - */ |
|
691 | - public static function select( $args = array() ) { |
|
692 | - $defaults = array( |
|
693 | - 'class' => '', |
|
694 | - 'wrap_class' => '', |
|
695 | - 'id' => '', |
|
696 | - 'title' => '', |
|
697 | - 'value' => '', |
|
698 | - // can be an array or a string |
|
699 | - 'required' => false, |
|
700 | - 'label' => '', |
|
701 | - 'label_after' => false, |
|
702 | - 'label_type' => '', |
|
703 | - 'label_col' => '', |
|
704 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
705 | - 'label_class' => '', |
|
706 | - 'help_text' => '', |
|
707 | - 'placeholder' => '', |
|
708 | - 'options' => array(), |
|
709 | - // array or string |
|
710 | - 'icon' => '', |
|
711 | - 'multiple' => false, |
|
712 | - 'select2' => false, |
|
713 | - 'no_wrap' => false, |
|
714 | - 'input_group_right' => '', |
|
715 | - 'input_group_left' => '', |
|
716 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
717 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
718 | - 'element_require' => '', |
|
719 | - // [%element_id%] == "1" |
|
720 | - 'extra_attributes' => array(), |
|
721 | - // an array of extra attributes |
|
722 | - 'wrap_attributes' => array(), |
|
723 | - ); |
|
724 | - |
|
725 | - /** |
|
726 | - * Parse incoming $args into an array and merge it with $defaults |
|
727 | - */ |
|
728 | - $args = wp_parse_args( $args, $defaults ); |
|
729 | - $output = ''; |
|
730 | - |
|
731 | - // for now lets hide floating labels |
|
732 | - if ( $args['label_type'] == 'floating' ) { |
|
733 | - $args['label_type'] = 'hidden'; |
|
734 | - } |
|
735 | - |
|
736 | - // hidden label option needs to be empty |
|
737 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
738 | - |
|
739 | - |
|
740 | - $label_after = $args['label_after']; |
|
741 | - |
|
742 | - // floating labels need label after |
|
743 | - if ( $args['label_type'] == 'floating' ) { |
|
744 | - $label_after = true; |
|
745 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
746 | - } |
|
747 | - |
|
748 | - // Maybe setup select2 |
|
749 | - $is_select2 = false; |
|
750 | - if ( ! empty( $args['select2'] ) ) { |
|
751 | - $args['class'] .= ' aui-select2'; |
|
752 | - $is_select2 = true; |
|
753 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
754 | - $is_select2 = true; |
|
755 | - } |
|
756 | - |
|
757 | - // select2 tags |
|
758 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
759 | - $args['data-tags'] = 'true'; |
|
760 | - $args['data-token-separators'] = "[',']"; |
|
761 | - $args['multiple'] = true; |
|
762 | - } |
|
763 | - |
|
764 | - // select2 placeholder |
|
765 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
766 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
767 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - |
|
772 | - // maybe horizontal label |
|
269 | + } |
|
270 | + |
|
271 | + // input group wraps |
|
272 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
273 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
274 | + if ( $args['input_group_left'] ) { |
|
275 | + $output = self::wrap( array( |
|
276 | + 'content' => $output, |
|
277 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
278 | + 'input_group_left' => $args['input_group_left'], |
|
279 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
280 | + ) ); |
|
281 | + } |
|
282 | + if ( $args['input_group_right'] ) { |
|
283 | + $output = self::wrap( array( |
|
284 | + 'content' => $output, |
|
285 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
286 | + 'input_group_right' => $args['input_group_right'], |
|
287 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
288 | + ) ); |
|
289 | + } |
|
290 | + |
|
291 | + } |
|
292 | + |
|
293 | + if ( ! $label_after ) { |
|
294 | + $output .= $help_text; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
299 | + $output = self::wrap( array( |
|
300 | + 'content' => $output, |
|
301 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
302 | + ) ); |
|
303 | + } |
|
304 | + |
|
305 | + if ( ! $label_after ) { |
|
306 | + $output = $label . $output; |
|
307 | + } |
|
308 | + |
|
309 | + // wrap |
|
310 | + if ( ! $args['no_wrap'] ) { |
|
311 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
312 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
313 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
314 | + $output = self::wrap( array( |
|
315 | + 'content' => $output, |
|
316 | + 'class' => $wrap_class, |
|
317 | + 'element_require' => $args['element_require'], |
|
318 | + 'argument_id' => $args['id'], |
|
319 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
320 | + ) ); |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + return $output; |
|
325 | + } |
|
326 | + |
|
327 | + public static function label( $args = array(), $type = '' ) { |
|
328 | + //<label for="exampleInputEmail1">Email address</label> |
|
329 | + $defaults = array( |
|
330 | + 'title' => 'div', |
|
331 | + 'for' => '', |
|
332 | + 'class' => '', |
|
333 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
334 | + 'label_col' => '', |
|
335 | + ); |
|
336 | + |
|
337 | + /** |
|
338 | + * Parse incoming $args into an array and merge it with $defaults |
|
339 | + */ |
|
340 | + $args = wp_parse_args( $args, $defaults ); |
|
341 | + $output = ''; |
|
342 | + |
|
343 | + if ( $args['title'] ) { |
|
344 | + |
|
345 | + // maybe hide labels //@todo set a global option for visibility class |
|
346 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
347 | + $class = $args['class']; |
|
348 | + } else { |
|
349 | + $class = 'sr-only ' . $args['class']; |
|
350 | + } |
|
351 | + |
|
352 | + // maybe horizontal |
|
353 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
354 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
355 | + } |
|
356 | + |
|
357 | + // open |
|
358 | + $output .= '<label '; |
|
359 | + |
|
360 | + // for |
|
361 | + if ( ! empty( $args['for'] ) ) { |
|
362 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
363 | + } |
|
364 | + |
|
365 | + // class |
|
366 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
367 | + $output .= ' class="' . $class . '" '; |
|
368 | + |
|
369 | + // close |
|
370 | + $output .= '>'; |
|
371 | + |
|
372 | + |
|
373 | + // title, don't escape fully as can contain html |
|
374 | + if ( ! empty( $args['title'] ) ) { |
|
375 | + $output .= wp_kses_post( $args['title'] ); |
|
376 | + } |
|
377 | + |
|
378 | + // close wrap |
|
379 | + $output .= '</label>'; |
|
380 | + |
|
381 | + |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + return $output; |
|
386 | + } |
|
387 | + |
|
388 | + /** |
|
389 | + * Wrap some content in a HTML wrapper. |
|
390 | + * |
|
391 | + * @param array $args |
|
392 | + * |
|
393 | + * @return string |
|
394 | + */ |
|
395 | + public static function wrap( $args = array() ) { |
|
396 | + $defaults = array( |
|
397 | + 'type' => 'div', |
|
398 | + 'class' => 'form-group', |
|
399 | + 'content' => '', |
|
400 | + 'input_group_left' => '', |
|
401 | + 'input_group_right' => '', |
|
402 | + 'input_group_left_inside' => false, |
|
403 | + 'input_group_right_inside' => false, |
|
404 | + 'element_require' => '', |
|
405 | + 'argument_id' => '', |
|
406 | + 'wrap_attributes' => array() |
|
407 | + ); |
|
408 | + |
|
409 | + /** |
|
410 | + * Parse incoming $args into an array and merge it with $defaults |
|
411 | + */ |
|
412 | + $args = wp_parse_args( $args, $defaults ); |
|
413 | + $output = ''; |
|
414 | + if ( $args['type'] ) { |
|
415 | + |
|
416 | + // open |
|
417 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
418 | + |
|
419 | + // element require |
|
420 | + if ( ! empty( $args['element_require'] ) ) { |
|
421 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
422 | + $args['class'] .= " aui-conditional-field"; |
|
423 | + } |
|
424 | + |
|
425 | + // argument_id |
|
426 | + if ( ! empty( $args['argument_id'] ) ) { |
|
427 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
428 | + } |
|
429 | + |
|
430 | + // class |
|
431 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
432 | + $output .= ' class="' . $class . '" '; |
|
433 | + |
|
434 | + // Attributes |
|
435 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
436 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
437 | + } |
|
438 | + |
|
439 | + // close wrap |
|
440 | + $output .= ' >'; |
|
441 | + |
|
442 | + |
|
443 | + // Input group left |
|
444 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
445 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
446 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
447 | + $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
448 | + } |
|
449 | + |
|
450 | + // content |
|
451 | + $output .= $args['content']; |
|
452 | + |
|
453 | + // Input group right |
|
454 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
455 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
456 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
457 | + $output .= '<div class="input-group-append ' . $position_class . '">' . $input_group_right . '</div>'; |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + // close wrap |
|
462 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
463 | + |
|
464 | + |
|
465 | + } else { |
|
466 | + $output = $args['content']; |
|
467 | + } |
|
468 | + |
|
469 | + return $output; |
|
470 | + } |
|
471 | + |
|
472 | + /** |
|
473 | + * Build the component. |
|
474 | + * |
|
475 | + * @param array $args |
|
476 | + * |
|
477 | + * @return string The rendered component. |
|
478 | + */ |
|
479 | + public static function textarea( $args = array() ) { |
|
480 | + $defaults = array( |
|
481 | + 'name' => '', |
|
482 | + 'class' => '', |
|
483 | + 'wrap_class' => '', |
|
484 | + 'id' => '', |
|
485 | + 'placeholder' => '', |
|
486 | + 'title' => '', |
|
487 | + 'value' => '', |
|
488 | + 'required' => false, |
|
489 | + 'label' => '', |
|
490 | + 'label_after' => false, |
|
491 | + 'label_class' => '', |
|
492 | + 'label_type' => '', |
|
493 | + 'label_col' => '', |
|
494 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
495 | + 'help_text' => '', |
|
496 | + 'validation_text' => '', |
|
497 | + 'validation_pattern' => '', |
|
498 | + 'no_wrap' => false, |
|
499 | + 'rows' => '', |
|
500 | + 'wysiwyg' => false, |
|
501 | + 'allow_tags' => false, |
|
502 | + // Allow HTML tags |
|
503 | + 'element_require' => '', |
|
504 | + // [%element_id%] == "1" |
|
505 | + 'extra_attributes' => array(), |
|
506 | + // an array of extra attributes |
|
507 | + 'wrap_attributes' => array(), |
|
508 | + ); |
|
509 | + |
|
510 | + /** |
|
511 | + * Parse incoming $args into an array and merge it with $defaults |
|
512 | + */ |
|
513 | + $args = wp_parse_args( $args, $defaults ); |
|
514 | + $output = ''; |
|
515 | + |
|
516 | + // hidden label option needs to be empty |
|
517 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
518 | + |
|
519 | + // floating labels don't work with wysiwyg so set it as top |
|
520 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
521 | + $args['label_type'] = 'top'; |
|
522 | + } |
|
523 | + |
|
524 | + $label_after = $args['label_after']; |
|
525 | + |
|
526 | + // floating labels need label after |
|
527 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
528 | + $label_after = true; |
|
529 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
530 | + } |
|
531 | + |
|
532 | + // label |
|
533 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
534 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
535 | + $label_args = array( |
|
536 | + 'title' => $args['label'], |
|
537 | + 'for' => $args['id'], |
|
538 | + 'class' => $args['label_class'] . " ", |
|
539 | + 'label_type' => $args['label_type'], |
|
540 | + 'label_col' => $args['label_col'] |
|
541 | + ); |
|
542 | + $output .= self::label( $label_args ); |
|
543 | + } |
|
544 | + |
|
545 | + // maybe horizontal label |
|
546 | + if ( $args['label_type'] == 'horizontal' ) { |
|
547 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
548 | + $output .= '<div class="' . $input_col . '">'; |
|
549 | + } |
|
550 | + |
|
551 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
552 | + ob_start(); |
|
553 | + $content = $args['value']; |
|
554 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
555 | + $settings = array( |
|
556 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
557 | + 'quicktags' => false, |
|
558 | + 'media_buttons' => false, |
|
559 | + 'editor_class' => 'form-control', |
|
560 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
561 | + 'teeny' => true, |
|
562 | + ); |
|
563 | + |
|
564 | + // maybe set settings if array |
|
565 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
566 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
567 | + } |
|
568 | + |
|
569 | + wp_editor( $content, $editor_id, $settings ); |
|
570 | + $output .= ob_get_clean(); |
|
571 | + } else { |
|
572 | + |
|
573 | + // open |
|
574 | + $output .= '<textarea '; |
|
575 | + |
|
576 | + // name |
|
577 | + if ( ! empty( $args['name'] ) ) { |
|
578 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
579 | + } |
|
580 | + |
|
581 | + // id |
|
582 | + if ( ! empty( $args['id'] ) ) { |
|
583 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
584 | + } |
|
585 | + |
|
586 | + // placeholder |
|
587 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
588 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
589 | + } |
|
590 | + |
|
591 | + // title |
|
592 | + if ( ! empty( $args['title'] ) ) { |
|
593 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
594 | + } |
|
595 | + |
|
596 | + // validation text |
|
597 | + if ( ! empty( $args['validation_text'] ) ) { |
|
598 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
599 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
600 | + } |
|
601 | + |
|
602 | + // validation_pattern |
|
603 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
604 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
605 | + } |
|
606 | + |
|
607 | + // required |
|
608 | + if ( ! empty( $args['required'] ) ) { |
|
609 | + $output .= ' required '; |
|
610 | + } |
|
611 | + |
|
612 | + // rows |
|
613 | + if ( ! empty( $args['rows'] ) ) { |
|
614 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + // class |
|
619 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
620 | + $output .= ' class="form-control ' . $class . '" '; |
|
621 | + |
|
622 | + // extra attributes |
|
623 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
624 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
625 | + } |
|
626 | + |
|
627 | + // close tag |
|
628 | + $output .= ' >'; |
|
629 | + |
|
630 | + // value |
|
631 | + if ( ! empty( $args['value'] ) ) { |
|
632 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
633 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
634 | + } else { |
|
635 | + $output .= sanitize_textarea_field( $args['value'] ); |
|
636 | + } |
|
637 | + } |
|
638 | + |
|
639 | + // closing tag |
|
640 | + $output .= '</textarea>'; |
|
641 | + |
|
642 | + } |
|
643 | + |
|
644 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
645 | + $label_args = array( |
|
646 | + 'title' => $args['label'], |
|
647 | + 'for' => $args['id'], |
|
648 | + 'class' => $args['label_class'] . " ", |
|
649 | + 'label_type' => $args['label_type'], |
|
650 | + 'label_col' => $args['label_col'] |
|
651 | + ); |
|
652 | + $output .= self::label( $label_args ); |
|
653 | + } |
|
654 | + |
|
655 | + // help text |
|
656 | + if ( ! empty( $args['help_text'] ) ) { |
|
657 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
658 | + } |
|
659 | + |
|
660 | + // maybe horizontal label |
|
661 | + if ( $args['label_type'] == 'horizontal' ) { |
|
662 | + $output .= '</div>'; |
|
663 | + } |
|
664 | + |
|
665 | + |
|
666 | + // wrap |
|
667 | + if ( ! $args['no_wrap'] ) { |
|
668 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
669 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
670 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
671 | + $output = self::wrap( array( |
|
672 | + 'content' => $output, |
|
673 | + 'class' => $wrap_class, |
|
674 | + 'element_require' => $args['element_require'], |
|
675 | + 'argument_id' => $args['id'], |
|
676 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
677 | + ) ); |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + return $output; |
|
682 | + } |
|
683 | + |
|
684 | + /** |
|
685 | + * Build the component. |
|
686 | + * |
|
687 | + * @param array $args |
|
688 | + * |
|
689 | + * @return string The rendered component. |
|
690 | + */ |
|
691 | + public static function select( $args = array() ) { |
|
692 | + $defaults = array( |
|
693 | + 'class' => '', |
|
694 | + 'wrap_class' => '', |
|
695 | + 'id' => '', |
|
696 | + 'title' => '', |
|
697 | + 'value' => '', |
|
698 | + // can be an array or a string |
|
699 | + 'required' => false, |
|
700 | + 'label' => '', |
|
701 | + 'label_after' => false, |
|
702 | + 'label_type' => '', |
|
703 | + 'label_col' => '', |
|
704 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
705 | + 'label_class' => '', |
|
706 | + 'help_text' => '', |
|
707 | + 'placeholder' => '', |
|
708 | + 'options' => array(), |
|
709 | + // array or string |
|
710 | + 'icon' => '', |
|
711 | + 'multiple' => false, |
|
712 | + 'select2' => false, |
|
713 | + 'no_wrap' => false, |
|
714 | + 'input_group_right' => '', |
|
715 | + 'input_group_left' => '', |
|
716 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
717 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
718 | + 'element_require' => '', |
|
719 | + // [%element_id%] == "1" |
|
720 | + 'extra_attributes' => array(), |
|
721 | + // an array of extra attributes |
|
722 | + 'wrap_attributes' => array(), |
|
723 | + ); |
|
724 | + |
|
725 | + /** |
|
726 | + * Parse incoming $args into an array and merge it with $defaults |
|
727 | + */ |
|
728 | + $args = wp_parse_args( $args, $defaults ); |
|
729 | + $output = ''; |
|
730 | + |
|
731 | + // for now lets hide floating labels |
|
732 | + if ( $args['label_type'] == 'floating' ) { |
|
733 | + $args['label_type'] = 'hidden'; |
|
734 | + } |
|
735 | + |
|
736 | + // hidden label option needs to be empty |
|
737 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
738 | + |
|
739 | + |
|
740 | + $label_after = $args['label_after']; |
|
741 | + |
|
742 | + // floating labels need label after |
|
743 | + if ( $args['label_type'] == 'floating' ) { |
|
744 | + $label_after = true; |
|
745 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
746 | + } |
|
747 | + |
|
748 | + // Maybe setup select2 |
|
749 | + $is_select2 = false; |
|
750 | + if ( ! empty( $args['select2'] ) ) { |
|
751 | + $args['class'] .= ' aui-select2'; |
|
752 | + $is_select2 = true; |
|
753 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
754 | + $is_select2 = true; |
|
755 | + } |
|
756 | + |
|
757 | + // select2 tags |
|
758 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
759 | + $args['data-tags'] = 'true'; |
|
760 | + $args['data-token-separators'] = "[',']"; |
|
761 | + $args['multiple'] = true; |
|
762 | + } |
|
763 | + |
|
764 | + // select2 placeholder |
|
765 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
766 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
767 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + |
|
772 | + // maybe horizontal label |
|
773 | 773 | // if ( $args['label_type'] == 'horizontal' ) { |
774 | 774 | // $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
775 | 775 | // $output .= '<div class="' . $input_col . '">'; |
776 | 776 | // } |
777 | 777 | |
778 | - // Set hidden input to save empty value for multiselect. |
|
779 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
780 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
781 | - } |
|
782 | - |
|
783 | - // open/type |
|
784 | - $output .= '<select '; |
|
785 | - |
|
786 | - // style |
|
787 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
788 | - $output .= " style='width:100%;' "; |
|
789 | - } |
|
790 | - |
|
791 | - // element require |
|
792 | - if ( ! empty( $args['element_require'] ) ) { |
|
793 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
794 | - $args['class'] .= " aui-conditional-field"; |
|
795 | - } |
|
796 | - |
|
797 | - // class |
|
798 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
799 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
800 | - |
|
801 | - // name |
|
802 | - if ( ! empty( $args['name'] ) ) { |
|
803 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
804 | - } |
|
805 | - |
|
806 | - // id |
|
807 | - if ( ! empty( $args['id'] ) ) { |
|
808 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
809 | - } |
|
810 | - |
|
811 | - // title |
|
812 | - if ( ! empty( $args['title'] ) ) { |
|
813 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
814 | - } |
|
815 | - |
|
816 | - // data-attributes |
|
817 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
818 | - |
|
819 | - // aria-attributes |
|
820 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
821 | - |
|
822 | - // extra attributes |
|
823 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
824 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
825 | - } |
|
826 | - |
|
827 | - // required |
|
828 | - if ( ! empty( $args['required'] ) ) { |
|
829 | - $output .= ' required '; |
|
830 | - } |
|
831 | - |
|
832 | - // multiple |
|
833 | - if ( ! empty( $args['multiple'] ) ) { |
|
834 | - $output .= ' multiple '; |
|
835 | - } |
|
836 | - |
|
837 | - // close opening tag |
|
838 | - $output .= ' >'; |
|
839 | - |
|
840 | - // placeholder |
|
841 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
842 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
843 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
844 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
845 | - } |
|
846 | - |
|
847 | - // Options |
|
848 | - if ( ! empty( $args['options'] ) ) { |
|
849 | - |
|
850 | - if ( ! is_array( $args['options'] ) ) { |
|
851 | - $output .= $args['options']; // not the preferred way but an option |
|
852 | - } else { |
|
853 | - foreach ( $args['options'] as $val => $name ) { |
|
854 | - $selected = ''; |
|
855 | - if ( is_array( $name ) ) { |
|
856 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
857 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
858 | - |
|
859 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
860 | - } else { |
|
861 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
862 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
863 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
864 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
865 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
866 | - } elseif ( ! empty( $args['value'] ) ) { |
|
867 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
868 | - } |
|
869 | - |
|
870 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
871 | - } |
|
872 | - } else { |
|
873 | - if ( ! empty( $args['value'] ) ) { |
|
874 | - if ( is_array( $args['value'] ) ) { |
|
875 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
876 | - } elseif ( ! empty( $args['value'] ) ) { |
|
877 | - $selected = selected( $args['value'], $val, false ); |
|
878 | - } |
|
879 | - } |
|
880 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
881 | - } |
|
882 | - } |
|
883 | - } |
|
884 | - |
|
885 | - } |
|
886 | - |
|
887 | - // closing tag |
|
888 | - $output .= '</select>'; |
|
889 | - |
|
890 | - $label = ''; |
|
891 | - $help_text = ''; |
|
892 | - // label |
|
893 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
894 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
895 | - $label_args = array( |
|
896 | - 'title' => $args['label'], |
|
897 | - 'for' => $args['id'], |
|
898 | - 'class' => $args['label_class'] . " ", |
|
899 | - 'label_type' => $args['label_type'], |
|
900 | - 'label_col' => $args['label_col'] |
|
901 | - ); |
|
902 | - $label = self::label( $label_args ); |
|
903 | - } |
|
904 | - |
|
905 | - // help text |
|
906 | - if ( ! empty( $args['help_text'] ) ) { |
|
907 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
908 | - } |
|
909 | - |
|
910 | - // input group wraps |
|
911 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
912 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
913 | - if ( $args['input_group_left'] ) { |
|
914 | - $output = self::wrap( array( |
|
915 | - 'content' => $output, |
|
916 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
917 | - 'input_group_left' => $args['input_group_left'], |
|
918 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
919 | - ) ); |
|
920 | - } |
|
921 | - if ( $args['input_group_right'] ) { |
|
922 | - $output = self::wrap( array( |
|
923 | - 'content' => $output, |
|
924 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
925 | - 'input_group_right' => $args['input_group_right'], |
|
926 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
927 | - ) ); |
|
928 | - } |
|
929 | - |
|
930 | - } |
|
931 | - |
|
932 | - if ( ! $label_after ) { |
|
933 | - $output .= $help_text; |
|
934 | - } |
|
935 | - |
|
936 | - |
|
937 | - if ( $args['label_type'] == 'horizontal' ) { |
|
938 | - $output = self::wrap( array( |
|
939 | - 'content' => $output, |
|
940 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
941 | - ) ); |
|
942 | - } |
|
943 | - |
|
944 | - if ( ! $label_after ) { |
|
945 | - $output = $label . $output; |
|
946 | - } |
|
947 | - |
|
948 | - // maybe horizontal label |
|
778 | + // Set hidden input to save empty value for multiselect. |
|
779 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
780 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
781 | + } |
|
782 | + |
|
783 | + // open/type |
|
784 | + $output .= '<select '; |
|
785 | + |
|
786 | + // style |
|
787 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
788 | + $output .= " style='width:100%;' "; |
|
789 | + } |
|
790 | + |
|
791 | + // element require |
|
792 | + if ( ! empty( $args['element_require'] ) ) { |
|
793 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
794 | + $args['class'] .= " aui-conditional-field"; |
|
795 | + } |
|
796 | + |
|
797 | + // class |
|
798 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
799 | + $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
800 | + |
|
801 | + // name |
|
802 | + if ( ! empty( $args['name'] ) ) { |
|
803 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
804 | + } |
|
805 | + |
|
806 | + // id |
|
807 | + if ( ! empty( $args['id'] ) ) { |
|
808 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
809 | + } |
|
810 | + |
|
811 | + // title |
|
812 | + if ( ! empty( $args['title'] ) ) { |
|
813 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
814 | + } |
|
815 | + |
|
816 | + // data-attributes |
|
817 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
818 | + |
|
819 | + // aria-attributes |
|
820 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
821 | + |
|
822 | + // extra attributes |
|
823 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
824 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
825 | + } |
|
826 | + |
|
827 | + // required |
|
828 | + if ( ! empty( $args['required'] ) ) { |
|
829 | + $output .= ' required '; |
|
830 | + } |
|
831 | + |
|
832 | + // multiple |
|
833 | + if ( ! empty( $args['multiple'] ) ) { |
|
834 | + $output .= ' multiple '; |
|
835 | + } |
|
836 | + |
|
837 | + // close opening tag |
|
838 | + $output .= ' >'; |
|
839 | + |
|
840 | + // placeholder |
|
841 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
842 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
843 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
844 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
845 | + } |
|
846 | + |
|
847 | + // Options |
|
848 | + if ( ! empty( $args['options'] ) ) { |
|
849 | + |
|
850 | + if ( ! is_array( $args['options'] ) ) { |
|
851 | + $output .= $args['options']; // not the preferred way but an option |
|
852 | + } else { |
|
853 | + foreach ( $args['options'] as $val => $name ) { |
|
854 | + $selected = ''; |
|
855 | + if ( is_array( $name ) ) { |
|
856 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
857 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
858 | + |
|
859 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
860 | + } else { |
|
861 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
862 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
863 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
864 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
865 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
866 | + } elseif ( ! empty( $args['value'] ) ) { |
|
867 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
868 | + } |
|
869 | + |
|
870 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
871 | + } |
|
872 | + } else { |
|
873 | + if ( ! empty( $args['value'] ) ) { |
|
874 | + if ( is_array( $args['value'] ) ) { |
|
875 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
876 | + } elseif ( ! empty( $args['value'] ) ) { |
|
877 | + $selected = selected( $args['value'], $val, false ); |
|
878 | + } |
|
879 | + } |
|
880 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
881 | + } |
|
882 | + } |
|
883 | + } |
|
884 | + |
|
885 | + } |
|
886 | + |
|
887 | + // closing tag |
|
888 | + $output .= '</select>'; |
|
889 | + |
|
890 | + $label = ''; |
|
891 | + $help_text = ''; |
|
892 | + // label |
|
893 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
894 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
895 | + $label_args = array( |
|
896 | + 'title' => $args['label'], |
|
897 | + 'for' => $args['id'], |
|
898 | + 'class' => $args['label_class'] . " ", |
|
899 | + 'label_type' => $args['label_type'], |
|
900 | + 'label_col' => $args['label_col'] |
|
901 | + ); |
|
902 | + $label = self::label( $label_args ); |
|
903 | + } |
|
904 | + |
|
905 | + // help text |
|
906 | + if ( ! empty( $args['help_text'] ) ) { |
|
907 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
908 | + } |
|
909 | + |
|
910 | + // input group wraps |
|
911 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
912 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
913 | + if ( $args['input_group_left'] ) { |
|
914 | + $output = self::wrap( array( |
|
915 | + 'content' => $output, |
|
916 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
917 | + 'input_group_left' => $args['input_group_left'], |
|
918 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
919 | + ) ); |
|
920 | + } |
|
921 | + if ( $args['input_group_right'] ) { |
|
922 | + $output = self::wrap( array( |
|
923 | + 'content' => $output, |
|
924 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
925 | + 'input_group_right' => $args['input_group_right'], |
|
926 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
927 | + ) ); |
|
928 | + } |
|
929 | + |
|
930 | + } |
|
931 | + |
|
932 | + if ( ! $label_after ) { |
|
933 | + $output .= $help_text; |
|
934 | + } |
|
935 | + |
|
936 | + |
|
937 | + if ( $args['label_type'] == 'horizontal' ) { |
|
938 | + $output = self::wrap( array( |
|
939 | + 'content' => $output, |
|
940 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
941 | + ) ); |
|
942 | + } |
|
943 | + |
|
944 | + if ( ! $label_after ) { |
|
945 | + $output = $label . $output; |
|
946 | + } |
|
947 | + |
|
948 | + // maybe horizontal label |
|
949 | 949 | // if ( $args['label_type'] == 'horizontal' ) { |
950 | 950 | // $output .= '</div>'; |
951 | 951 | // } |
952 | 952 | |
953 | 953 | |
954 | - // wrap |
|
955 | - if ( ! $args['no_wrap'] ) { |
|
956 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
957 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
958 | - $output = self::wrap( array( |
|
959 | - 'content' => $output, |
|
960 | - 'class' => $wrap_class, |
|
961 | - 'element_require' => $args['element_require'], |
|
962 | - 'argument_id' => $args['id'], |
|
963 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
964 | - ) ); |
|
965 | - } |
|
966 | - |
|
967 | - |
|
968 | - return $output; |
|
969 | - } |
|
970 | - |
|
971 | - /** |
|
972 | - * Build the component. |
|
973 | - * |
|
974 | - * @param array $args |
|
975 | - * |
|
976 | - * @return string The rendered component. |
|
977 | - */ |
|
978 | - public static function radio( $args = array() ) { |
|
979 | - $defaults = array( |
|
980 | - 'class' => '', |
|
981 | - 'wrap_class' => '', |
|
982 | - 'id' => '', |
|
983 | - 'title' => '', |
|
984 | - 'horizontal' => false, |
|
985 | - // sets the lable horizontal |
|
986 | - 'value' => '', |
|
987 | - 'label' => '', |
|
988 | - 'label_class' => '', |
|
989 | - 'label_type' => '', |
|
990 | - 'label_col' => '', |
|
991 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
992 | - 'help_text' => '', |
|
993 | - 'inline' => true, |
|
994 | - 'required' => false, |
|
995 | - 'options' => array(), |
|
996 | - 'icon' => '', |
|
997 | - 'no_wrap' => false, |
|
998 | - 'element_require' => '', |
|
999 | - // [%element_id%] == "1" |
|
1000 | - 'extra_attributes' => array(), |
|
1001 | - // an array of extra attributes |
|
1002 | - 'wrap_attributes' => array() |
|
1003 | - ); |
|
1004 | - |
|
1005 | - /** |
|
1006 | - * Parse incoming $args into an array and merge it with $defaults |
|
1007 | - */ |
|
1008 | - $args = wp_parse_args( $args, $defaults ); |
|
1009 | - |
|
1010 | - // for now lets use horizontal for floating |
|
1011 | - if ( $args['label_type'] == 'floating' ) { |
|
1012 | - $args['label_type'] = 'horizontal'; |
|
1013 | - } |
|
1014 | - |
|
1015 | - $label_args = array( |
|
1016 | - 'title' => $args['label'], |
|
1017 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1018 | - 'label_type' => $args['label_type'], |
|
1019 | - 'label_col' => $args['label_col'] |
|
1020 | - ); |
|
1021 | - |
|
1022 | - $output = ''; |
|
1023 | - |
|
1024 | - |
|
1025 | - // label before |
|
1026 | - if ( ! empty( $args['label'] ) ) { |
|
1027 | - $output .= self::label( $label_args, 'radio' ); |
|
1028 | - } |
|
1029 | - |
|
1030 | - // maybe horizontal label |
|
1031 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1032 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1033 | - $output .= '<div class="' . $input_col . '">'; |
|
1034 | - } |
|
1035 | - |
|
1036 | - if ( ! empty( $args['options'] ) ) { |
|
1037 | - $count = 0; |
|
1038 | - foreach ( $args['options'] as $value => $label ) { |
|
1039 | - $option_args = $args; |
|
1040 | - $option_args['value'] = $value; |
|
1041 | - $option_args['label'] = $label; |
|
1042 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1043 | - $output .= self::radio_option( $option_args, $count ); |
|
1044 | - $count ++; |
|
1045 | - } |
|
1046 | - } |
|
1047 | - |
|
1048 | - // help text |
|
1049 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1050 | - $output .= $help_text; |
|
1051 | - |
|
1052 | - // maybe horizontal label |
|
1053 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1054 | - $output .= '</div>'; |
|
1055 | - } |
|
1056 | - |
|
1057 | - // wrap |
|
1058 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1059 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1060 | - $output = self::wrap( array( |
|
1061 | - 'content' => $output, |
|
1062 | - 'class' => $wrap_class, |
|
1063 | - 'element_require' => $args['element_require'], |
|
1064 | - 'argument_id' => $args['id'], |
|
1065 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1066 | - ) ); |
|
1067 | - |
|
1068 | - |
|
1069 | - return $output; |
|
1070 | - } |
|
1071 | - |
|
1072 | - /** |
|
1073 | - * Build the component. |
|
1074 | - * |
|
1075 | - * @param array $args |
|
1076 | - * |
|
1077 | - * @return string The rendered component. |
|
1078 | - */ |
|
1079 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1080 | - $defaults = array( |
|
1081 | - 'class' => '', |
|
1082 | - 'id' => '', |
|
1083 | - 'title' => '', |
|
1084 | - 'value' => '', |
|
1085 | - 'required' => false, |
|
1086 | - 'inline' => true, |
|
1087 | - 'label' => '', |
|
1088 | - 'options' => array(), |
|
1089 | - 'icon' => '', |
|
1090 | - 'no_wrap' => false, |
|
1091 | - 'extra_attributes' => array() // an array of extra attributes |
|
1092 | - ); |
|
1093 | - |
|
1094 | - /** |
|
1095 | - * Parse incoming $args into an array and merge it with $defaults |
|
1096 | - */ |
|
1097 | - $args = wp_parse_args( $args, $defaults ); |
|
1098 | - |
|
1099 | - $output = ''; |
|
1100 | - |
|
1101 | - // open/type |
|
1102 | - $output .= '<input type="radio"'; |
|
1103 | - |
|
1104 | - // class |
|
1105 | - $output .= ' class="form-check-input" '; |
|
1106 | - |
|
1107 | - // name |
|
1108 | - if ( ! empty( $args['name'] ) ) { |
|
1109 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1110 | - } |
|
1111 | - |
|
1112 | - // id |
|
1113 | - if ( ! empty( $args['id'] ) ) { |
|
1114 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1115 | - } |
|
1116 | - |
|
1117 | - // title |
|
1118 | - if ( ! empty( $args['title'] ) ) { |
|
1119 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1120 | - } |
|
1121 | - |
|
1122 | - // value |
|
1123 | - if ( isset( $args['value'] ) ) { |
|
1124 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1125 | - } |
|
1126 | - |
|
1127 | - // checked, for radio and checkboxes |
|
1128 | - if ( $args['checked'] ) { |
|
1129 | - $output .= ' checked '; |
|
1130 | - } |
|
1131 | - |
|
1132 | - // data-attributes |
|
1133 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1134 | - |
|
1135 | - // aria-attributes |
|
1136 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1137 | - |
|
1138 | - // extra attributes |
|
1139 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1140 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1141 | - } |
|
1142 | - |
|
1143 | - // required |
|
1144 | - if ( ! empty( $args['required'] ) ) { |
|
1145 | - $output .= ' required '; |
|
1146 | - } |
|
1147 | - |
|
1148 | - // close opening tag |
|
1149 | - $output .= ' >'; |
|
1150 | - |
|
1151 | - // label |
|
1152 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1153 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1154 | - $output .= self::label( array( |
|
1155 | - 'title' => $args['label'], |
|
1156 | - 'for' => $args['id'] . $count, |
|
1157 | - 'class' => 'form-check-label' |
|
1158 | - ), 'radio' ); |
|
1159 | - } |
|
1160 | - |
|
1161 | - // wrap |
|
1162 | - if ( ! $args['no_wrap'] ) { |
|
1163 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1164 | - |
|
1165 | - // Unique wrap class |
|
1166 | - $uniq_class = 'fwrap'; |
|
1167 | - if ( ! empty( $args['name'] ) ) { |
|
1168 | - $uniq_class .= '-' . $args['name']; |
|
1169 | - } else if ( ! empty( $args['id'] ) ) { |
|
1170 | - $uniq_class .= '-' . $args['id']; |
|
1171 | - } |
|
1172 | - |
|
1173 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1174 | - $uniq_class .= '-' . $args['value']; |
|
1175 | - } else { |
|
1176 | - $uniq_class .= '-' . $count; |
|
1177 | - } |
|
1178 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1179 | - |
|
1180 | - $output = self::wrap( array( |
|
1181 | - 'content' => $output, |
|
1182 | - 'class' => $wrap_class |
|
1183 | - ) ); |
|
1184 | - } |
|
1185 | - |
|
1186 | - return $output; |
|
1187 | - } |
|
954 | + // wrap |
|
955 | + if ( ! $args['no_wrap'] ) { |
|
956 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
957 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
958 | + $output = self::wrap( array( |
|
959 | + 'content' => $output, |
|
960 | + 'class' => $wrap_class, |
|
961 | + 'element_require' => $args['element_require'], |
|
962 | + 'argument_id' => $args['id'], |
|
963 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
964 | + ) ); |
|
965 | + } |
|
966 | + |
|
967 | + |
|
968 | + return $output; |
|
969 | + } |
|
970 | + |
|
971 | + /** |
|
972 | + * Build the component. |
|
973 | + * |
|
974 | + * @param array $args |
|
975 | + * |
|
976 | + * @return string The rendered component. |
|
977 | + */ |
|
978 | + public static function radio( $args = array() ) { |
|
979 | + $defaults = array( |
|
980 | + 'class' => '', |
|
981 | + 'wrap_class' => '', |
|
982 | + 'id' => '', |
|
983 | + 'title' => '', |
|
984 | + 'horizontal' => false, |
|
985 | + // sets the lable horizontal |
|
986 | + 'value' => '', |
|
987 | + 'label' => '', |
|
988 | + 'label_class' => '', |
|
989 | + 'label_type' => '', |
|
990 | + 'label_col' => '', |
|
991 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
992 | + 'help_text' => '', |
|
993 | + 'inline' => true, |
|
994 | + 'required' => false, |
|
995 | + 'options' => array(), |
|
996 | + 'icon' => '', |
|
997 | + 'no_wrap' => false, |
|
998 | + 'element_require' => '', |
|
999 | + // [%element_id%] == "1" |
|
1000 | + 'extra_attributes' => array(), |
|
1001 | + // an array of extra attributes |
|
1002 | + 'wrap_attributes' => array() |
|
1003 | + ); |
|
1004 | + |
|
1005 | + /** |
|
1006 | + * Parse incoming $args into an array and merge it with $defaults |
|
1007 | + */ |
|
1008 | + $args = wp_parse_args( $args, $defaults ); |
|
1009 | + |
|
1010 | + // for now lets use horizontal for floating |
|
1011 | + if ( $args['label_type'] == 'floating' ) { |
|
1012 | + $args['label_type'] = 'horizontal'; |
|
1013 | + } |
|
1014 | + |
|
1015 | + $label_args = array( |
|
1016 | + 'title' => $args['label'], |
|
1017 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1018 | + 'label_type' => $args['label_type'], |
|
1019 | + 'label_col' => $args['label_col'] |
|
1020 | + ); |
|
1021 | + |
|
1022 | + $output = ''; |
|
1023 | + |
|
1024 | + |
|
1025 | + // label before |
|
1026 | + if ( ! empty( $args['label'] ) ) { |
|
1027 | + $output .= self::label( $label_args, 'radio' ); |
|
1028 | + } |
|
1029 | + |
|
1030 | + // maybe horizontal label |
|
1031 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1032 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1033 | + $output .= '<div class="' . $input_col . '">'; |
|
1034 | + } |
|
1035 | + |
|
1036 | + if ( ! empty( $args['options'] ) ) { |
|
1037 | + $count = 0; |
|
1038 | + foreach ( $args['options'] as $value => $label ) { |
|
1039 | + $option_args = $args; |
|
1040 | + $option_args['value'] = $value; |
|
1041 | + $option_args['label'] = $label; |
|
1042 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1043 | + $output .= self::radio_option( $option_args, $count ); |
|
1044 | + $count ++; |
|
1045 | + } |
|
1046 | + } |
|
1047 | + |
|
1048 | + // help text |
|
1049 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1050 | + $output .= $help_text; |
|
1051 | + |
|
1052 | + // maybe horizontal label |
|
1053 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1054 | + $output .= '</div>'; |
|
1055 | + } |
|
1056 | + |
|
1057 | + // wrap |
|
1058 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1059 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1060 | + $output = self::wrap( array( |
|
1061 | + 'content' => $output, |
|
1062 | + 'class' => $wrap_class, |
|
1063 | + 'element_require' => $args['element_require'], |
|
1064 | + 'argument_id' => $args['id'], |
|
1065 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1066 | + ) ); |
|
1067 | + |
|
1068 | + |
|
1069 | + return $output; |
|
1070 | + } |
|
1071 | + |
|
1072 | + /** |
|
1073 | + * Build the component. |
|
1074 | + * |
|
1075 | + * @param array $args |
|
1076 | + * |
|
1077 | + * @return string The rendered component. |
|
1078 | + */ |
|
1079 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1080 | + $defaults = array( |
|
1081 | + 'class' => '', |
|
1082 | + 'id' => '', |
|
1083 | + 'title' => '', |
|
1084 | + 'value' => '', |
|
1085 | + 'required' => false, |
|
1086 | + 'inline' => true, |
|
1087 | + 'label' => '', |
|
1088 | + 'options' => array(), |
|
1089 | + 'icon' => '', |
|
1090 | + 'no_wrap' => false, |
|
1091 | + 'extra_attributes' => array() // an array of extra attributes |
|
1092 | + ); |
|
1093 | + |
|
1094 | + /** |
|
1095 | + * Parse incoming $args into an array and merge it with $defaults |
|
1096 | + */ |
|
1097 | + $args = wp_parse_args( $args, $defaults ); |
|
1098 | + |
|
1099 | + $output = ''; |
|
1100 | + |
|
1101 | + // open/type |
|
1102 | + $output .= '<input type="radio"'; |
|
1103 | + |
|
1104 | + // class |
|
1105 | + $output .= ' class="form-check-input" '; |
|
1106 | + |
|
1107 | + // name |
|
1108 | + if ( ! empty( $args['name'] ) ) { |
|
1109 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1110 | + } |
|
1111 | + |
|
1112 | + // id |
|
1113 | + if ( ! empty( $args['id'] ) ) { |
|
1114 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1115 | + } |
|
1116 | + |
|
1117 | + // title |
|
1118 | + if ( ! empty( $args['title'] ) ) { |
|
1119 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1120 | + } |
|
1121 | + |
|
1122 | + // value |
|
1123 | + if ( isset( $args['value'] ) ) { |
|
1124 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1125 | + } |
|
1126 | + |
|
1127 | + // checked, for radio and checkboxes |
|
1128 | + if ( $args['checked'] ) { |
|
1129 | + $output .= ' checked '; |
|
1130 | + } |
|
1131 | + |
|
1132 | + // data-attributes |
|
1133 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1134 | + |
|
1135 | + // aria-attributes |
|
1136 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1137 | + |
|
1138 | + // extra attributes |
|
1139 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1140 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1141 | + } |
|
1142 | + |
|
1143 | + // required |
|
1144 | + if ( ! empty( $args['required'] ) ) { |
|
1145 | + $output .= ' required '; |
|
1146 | + } |
|
1147 | + |
|
1148 | + // close opening tag |
|
1149 | + $output .= ' >'; |
|
1150 | + |
|
1151 | + // label |
|
1152 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1153 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1154 | + $output .= self::label( array( |
|
1155 | + 'title' => $args['label'], |
|
1156 | + 'for' => $args['id'] . $count, |
|
1157 | + 'class' => 'form-check-label' |
|
1158 | + ), 'radio' ); |
|
1159 | + } |
|
1160 | + |
|
1161 | + // wrap |
|
1162 | + if ( ! $args['no_wrap'] ) { |
|
1163 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1164 | + |
|
1165 | + // Unique wrap class |
|
1166 | + $uniq_class = 'fwrap'; |
|
1167 | + if ( ! empty( $args['name'] ) ) { |
|
1168 | + $uniq_class .= '-' . $args['name']; |
|
1169 | + } else if ( ! empty( $args['id'] ) ) { |
|
1170 | + $uniq_class .= '-' . $args['id']; |
|
1171 | + } |
|
1172 | + |
|
1173 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1174 | + $uniq_class .= '-' . $args['value']; |
|
1175 | + } else { |
|
1176 | + $uniq_class .= '-' . $count; |
|
1177 | + } |
|
1178 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1179 | + |
|
1180 | + $output = self::wrap( array( |
|
1181 | + 'content' => $output, |
|
1182 | + 'class' => $wrap_class |
|
1183 | + ) ); |
|
1184 | + } |
|
1185 | + |
|
1186 | + return $output; |
|
1187 | + } |
|
1188 | 1188 | |
1189 | 1189 | } |
1190 | 1190 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
3 | +if (!defined('ABSPATH')) { |
|
4 | 4 | exit; // Exit if accessed directly |
5 | 5 | } |
6 | 6 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function input( $args = array() ) { |
|
21 | + public static function input($args = array()) { |
|
22 | 22 | $defaults = array( |
23 | 23 | 'type' => 'text', |
24 | 24 | 'name' => '', |
@@ -63,13 +63,13 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Parse incoming $args into an array and merge it with $defaults |
65 | 65 | */ |
66 | - $args = wp_parse_args( $args, $defaults ); |
|
66 | + $args = wp_parse_args($args, $defaults); |
|
67 | 67 | $output = ''; |
68 | - if ( ! empty( $args['type'] ) ) { |
|
68 | + if (!empty($args['type'])) { |
|
69 | 69 | // hidden label option needs to be empty |
70 | 70 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
71 | 71 | |
72 | - $type = sanitize_html_class( $args['type'] ); |
|
72 | + $type = sanitize_html_class($args['type']); |
|
73 | 73 | |
74 | 74 | $help_text = ''; |
75 | 75 | $label = ''; |
@@ -83,19 +83,19 @@ discard block |
||
83 | 83 | ); |
84 | 84 | |
85 | 85 | // floating labels need label after |
86 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
86 | + if ($args['label_type'] == 'floating' && $type != 'checkbox') { |
|
87 | 87 | $label_after = true; |
88 | 88 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
89 | 89 | } |
90 | 90 | |
91 | 91 | // Some special sauce for files |
92 | - if ( $type == 'file' ) { |
|
92 | + if ($type == 'file') { |
|
93 | 93 | $label_after = true; // if type file we need the label after |
94 | 94 | $args['class'] .= ' custom-file-input '; |
95 | - } elseif ( $type == 'checkbox' ) { |
|
95 | + } elseif ($type == 'checkbox') { |
|
96 | 96 | $label_after = true; // if type file we need the label after |
97 | 97 | $args['class'] .= ' custom-control-input '; |
98 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
98 | + } elseif ($type == 'datepicker' || $type == 'timepicker') { |
|
99 | 99 | $type = 'text'; |
100 | 100 | //$args['class'] .= ' aui-flatpickr bg-initial '; |
101 | 101 | $args['class'] .= ' bg-initial '; |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | // enqueue the script |
105 | 105 | $aui_settings = AyeCode_UI_Settings::instance(); |
106 | 106 | $aui_settings->enqueue_flatpickr(); |
107 | - } elseif ( $type == 'iconpicker' ) { |
|
107 | + } elseif ($type == 'iconpicker') { |
|
108 | 108 | $type = 'text'; |
109 | 109 | //$args['class'] .= ' aui-flatpickr bg-initial '; |
110 | 110 | // $args['class'] .= ' bg-initial '; |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | $aui_settings->enqueue_iconpicker(); |
120 | 120 | } |
121 | 121 | |
122 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
123 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
122 | + if ($type == 'checkbox' && !empty($args['name']) && strpos($args['name'], '[') === false) { |
|
123 | + $output .= '<input type="hidden" name="' . esc_attr($args['name']) . '" value="0" />'; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | |
@@ -128,88 +128,88 @@ discard block |
||
128 | 128 | $output .= '<input type="' . $type . '" '; |
129 | 129 | |
130 | 130 | // name |
131 | - if ( ! empty( $args['name'] ) ) { |
|
132 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
131 | + if (!empty($args['name'])) { |
|
132 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | // id |
136 | - if ( ! empty( $args['id'] ) ) { |
|
137 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
136 | + if (!empty($args['id'])) { |
|
137 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | // placeholder |
141 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
142 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
141 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
142 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // title |
146 | - if ( ! empty( $args['title'] ) ) { |
|
147 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
146 | + if (!empty($args['title'])) { |
|
147 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | // value |
151 | - if ( ! empty( $args['value'] ) ) { |
|
152 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
151 | + if (!empty($args['value'])) { |
|
152 | + $output .= AUI_Component_Helper::value($args['value']); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | // checked, for radio and checkboxes |
156 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
156 | + if (($type == 'checkbox' || $type == 'radio') && $args['checked']) { |
|
157 | 157 | $output .= ' checked '; |
158 | 158 | } |
159 | 159 | |
160 | 160 | // validation text |
161 | - if ( ! empty( $args['validation_text'] ) ) { |
|
162 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
161 | + if (!empty($args['validation_text'])) { |
|
162 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
163 | 163 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
164 | 164 | } |
165 | 165 | |
166 | 166 | // validation_pattern |
167 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
168 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
167 | + if (!empty($args['validation_pattern'])) { |
|
168 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | // step (for numbers) |
172 | - if ( ! empty( $args['step'] ) ) { |
|
172 | + if (!empty($args['step'])) { |
|
173 | 173 | $output .= ' step="' . $args['step'] . '" '; |
174 | 174 | } |
175 | 175 | |
176 | 176 | // required |
177 | - if ( ! empty( $args['required'] ) ) { |
|
177 | + if (!empty($args['required'])) { |
|
178 | 178 | $output .= ' required '; |
179 | 179 | } |
180 | 180 | |
181 | 181 | // class |
182 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
182 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
183 | 183 | $output .= ' class="form-control ' . $class . '" '; |
184 | 184 | |
185 | 185 | // data-attributes |
186 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
186 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
187 | 187 | |
188 | 188 | // extra attributes |
189 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
190 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
189 | + if (!empty($args['extra_attributes'])) { |
|
190 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
191 | 191 | } |
192 | 192 | |
193 | 193 | // close |
194 | 194 | $output .= ' >'; |
195 | 195 | |
196 | 196 | // help text |
197 | - if ( ! empty( $args['help_text'] ) ) { |
|
198 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
197 | + if (!empty($args['help_text'])) { |
|
198 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | // label |
202 | - if ( ! empty( $args['label'] ) ) { |
|
202 | + if (!empty($args['label'])) { |
|
203 | 203 | $label_base_class = ''; |
204 | - if ( $type == 'file' ) { |
|
204 | + if ($type == 'file') { |
|
205 | 205 | $label_base_class = ' custom-file-label'; |
206 | - } elseif ( $type == 'checkbox' ) { |
|
207 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
208 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
206 | + } elseif ($type == 'checkbox') { |
|
207 | + if (!empty($args['label_force_left'])) { |
|
208 | + $label_args['title'] = wp_kses_post($args['help_text']); |
|
209 | 209 | $help_text = ''; |
210 | 210 | //$label_args['class'] .= ' d-inline '; |
211 | 211 | $args['wrap_class'] .= ' align-items-center '; |
212 | - }else{ |
|
212 | + } else { |
|
213 | 213 | |
214 | 214 | } |
215 | 215 | |
@@ -217,45 +217,45 @@ discard block |
||
217 | 217 | } |
218 | 218 | $label_args['class'] .= $label_base_class; |
219 | 219 | $temp_label_args = $label_args; |
220 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
221 | - $label = self::label( $temp_label_args, $type ); |
|
220 | + if (!empty($args['label_force_left'])) {$temp_label_args['class'] = $label_base_class . " text-muted"; } |
|
221 | + $label = self::label($temp_label_args, $type); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | |
225 | 225 | |
226 | 226 | |
227 | 227 | // set help text in the correct position |
228 | - if ( $label_after ) { |
|
228 | + if ($label_after) { |
|
229 | 229 | $output .= $label . $help_text; |
230 | 230 | } |
231 | 231 | |
232 | 232 | // some input types need a separate wrap |
233 | - if ( $type == 'file' ) { |
|
234 | - $output = self::wrap( array( |
|
233 | + if ($type == 'file') { |
|
234 | + $output = self::wrap(array( |
|
235 | 235 | 'content' => $output, |
236 | 236 | 'class' => 'form-group custom-file' |
237 | - ) ); |
|
238 | - } elseif ( $type == 'checkbox' ) { |
|
237 | + )); |
|
238 | + } elseif ($type == 'checkbox') { |
|
239 | 239 | |
240 | 240 | $label_args['title'] = $args['label']; |
241 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
242 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
243 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
244 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
245 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
241 | + $label_col = AUI_Component_Helper::get_column_class($args['label_col'], 'label'); |
|
242 | + $label = !empty($args['label_force_left']) ? self::label($label_args, 'cb') : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
243 | + $switch_size_class = $args['switch'] && !is_bool($args['switch']) ? ' custom-switch-' . esc_attr($args['switch']) : ''; |
|
244 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox'; |
|
245 | + if (!empty($args['label_force_left'])) { |
|
246 | 246 | $wrap_class .= ' d-flex align-content-center'; |
247 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
247 | + $label = str_replace("custom-control-label", "", self::label($label_args, 'cb')); |
|
248 | 248 | } |
249 | - $output = self::wrap( array( |
|
249 | + $output = self::wrap(array( |
|
250 | 250 | 'content' => $output, |
251 | 251 | 'class' => 'custom-control ' . $wrap_class |
252 | - ) ); |
|
252 | + )); |
|
253 | 253 | |
254 | - if ( $args['label_type'] == 'horizontal' ) { |
|
255 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
254 | + if ($args['label_type'] == 'horizontal') { |
|
255 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
256 | 256 | $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
257 | 257 | } |
258 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
258 | + } elseif ($type == 'password' && $args['password_toggle'] && !$args['input_group_right']) { |
|
259 | 259 | |
260 | 260 | |
261 | 261 | // allow password field to toggle view |
@@ -269,62 +269,62 @@ discard block |
||
269 | 269 | } |
270 | 270 | |
271 | 271 | // input group wraps |
272 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
273 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
274 | - if ( $args['input_group_left'] ) { |
|
275 | - $output = self::wrap( array( |
|
272 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
273 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
274 | + if ($args['input_group_left']) { |
|
275 | + $output = self::wrap(array( |
|
276 | 276 | 'content' => $output, |
277 | 277 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
278 | 278 | 'input_group_left' => $args['input_group_left'], |
279 | 279 | 'input_group_left_inside' => $args['input_group_left_inside'] |
280 | - ) ); |
|
280 | + )); |
|
281 | 281 | } |
282 | - if ( $args['input_group_right'] ) { |
|
283 | - $output = self::wrap( array( |
|
282 | + if ($args['input_group_right']) { |
|
283 | + $output = self::wrap(array( |
|
284 | 284 | 'content' => $output, |
285 | 285 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
286 | 286 | 'input_group_right' => $args['input_group_right'], |
287 | 287 | 'input_group_right_inside' => $args['input_group_right_inside'] |
288 | - ) ); |
|
288 | + )); |
|
289 | 289 | } |
290 | 290 | |
291 | 291 | } |
292 | 292 | |
293 | - if ( ! $label_after ) { |
|
293 | + if (!$label_after) { |
|
294 | 294 | $output .= $help_text; |
295 | 295 | } |
296 | 296 | |
297 | 297 | |
298 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
299 | - $output = self::wrap( array( |
|
298 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
299 | + $output = self::wrap(array( |
|
300 | 300 | 'content' => $output, |
301 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
302 | - ) ); |
|
301 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
302 | + )); |
|
303 | 303 | } |
304 | 304 | |
305 | - if ( ! $label_after ) { |
|
305 | + if (!$label_after) { |
|
306 | 306 | $output = $label . $output; |
307 | 307 | } |
308 | 308 | |
309 | 309 | // wrap |
310 | - if ( ! $args['no_wrap'] ) { |
|
310 | + if (!$args['no_wrap']) { |
|
311 | 311 | $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
312 | 312 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
313 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
314 | - $output = self::wrap( array( |
|
313 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
314 | + $output = self::wrap(array( |
|
315 | 315 | 'content' => $output, |
316 | 316 | 'class' => $wrap_class, |
317 | 317 | 'element_require' => $args['element_require'], |
318 | 318 | 'argument_id' => $args['id'], |
319 | 319 | 'wrap_attributes' => $args['wrap_attributes'], |
320 | - ) ); |
|
320 | + )); |
|
321 | 321 | } |
322 | 322 | } |
323 | 323 | |
324 | 324 | return $output; |
325 | 325 | } |
326 | 326 | |
327 | - public static function label( $args = array(), $type = '' ) { |
|
327 | + public static function label($args = array(), $type = '') { |
|
328 | 328 | //<label for="exampleInputEmail1">Email address</label> |
329 | 329 | $defaults = array( |
330 | 330 | 'title' => 'div', |
@@ -337,33 +337,33 @@ discard block |
||
337 | 337 | /** |
338 | 338 | * Parse incoming $args into an array and merge it with $defaults |
339 | 339 | */ |
340 | - $args = wp_parse_args( $args, $defaults ); |
|
340 | + $args = wp_parse_args($args, $defaults); |
|
341 | 341 | $output = ''; |
342 | 342 | |
343 | - if ( $args['title'] ) { |
|
343 | + if ($args['title']) { |
|
344 | 344 | |
345 | 345 | // maybe hide labels //@todo set a global option for visibility class |
346 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
346 | + if ($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type'])) { |
|
347 | 347 | $class = $args['class']; |
348 | 348 | } else { |
349 | 349 | $class = 'sr-only ' . $args['class']; |
350 | 350 | } |
351 | 351 | |
352 | 352 | // maybe horizontal |
353 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
354 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
353 | + if ($args['label_type'] == 'horizontal' && $type != 'checkbox') { |
|
354 | + $class .= ' ' . AUI_Component_Helper::get_column_class($args['label_col'], 'label') . ' col-form-label'; |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | // open |
358 | 358 | $output .= '<label '; |
359 | 359 | |
360 | 360 | // for |
361 | - if ( ! empty( $args['for'] ) ) { |
|
362 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
361 | + if (!empty($args['for'])) { |
|
362 | + $output .= ' for="' . esc_attr($args['for']) . '" '; |
|
363 | 363 | } |
364 | 364 | |
365 | 365 | // class |
366 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
366 | + $class = $class ? AUI_Component_Helper::esc_classes($class) : ''; |
|
367 | 367 | $output .= ' class="' . $class . '" '; |
368 | 368 | |
369 | 369 | // close |
@@ -371,8 +371,8 @@ discard block |
||
371 | 371 | |
372 | 372 | |
373 | 373 | // title, don't escape fully as can contain html |
374 | - if ( ! empty( $args['title'] ) ) { |
|
375 | - $output .= wp_kses_post( $args['title'] ); |
|
374 | + if (!empty($args['title'])) { |
|
375 | + $output .= wp_kses_post($args['title']); |
|
376 | 376 | } |
377 | 377 | |
378 | 378 | // close wrap |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | * |
393 | 393 | * @return string |
394 | 394 | */ |
395 | - public static function wrap( $args = array() ) { |
|
395 | + public static function wrap($args = array()) { |
|
396 | 396 | $defaults = array( |
397 | 397 | 'type' => 'div', |
398 | 398 | 'class' => 'form-group', |
@@ -409,31 +409,31 @@ discard block |
||
409 | 409 | /** |
410 | 410 | * Parse incoming $args into an array and merge it with $defaults |
411 | 411 | */ |
412 | - $args = wp_parse_args( $args, $defaults ); |
|
412 | + $args = wp_parse_args($args, $defaults); |
|
413 | 413 | $output = ''; |
414 | - if ( $args['type'] ) { |
|
414 | + if ($args['type']) { |
|
415 | 415 | |
416 | 416 | // open |
417 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
417 | + $output .= '<' . sanitize_html_class($args['type']); |
|
418 | 418 | |
419 | 419 | // element require |
420 | - if ( ! empty( $args['element_require'] ) ) { |
|
421 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
420 | + if (!empty($args['element_require'])) { |
|
421 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
422 | 422 | $args['class'] .= " aui-conditional-field"; |
423 | 423 | } |
424 | 424 | |
425 | 425 | // argument_id |
426 | - if ( ! empty( $args['argument_id'] ) ) { |
|
427 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
426 | + if (!empty($args['argument_id'])) { |
|
427 | + $output .= ' data-argument="' . esc_attr($args['argument_id']) . '"'; |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | // class |
431 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
431 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes($args['class']) : ''; |
|
432 | 432 | $output .= ' class="' . $class . '" '; |
433 | 433 | |
434 | 434 | // Attributes |
435 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
436 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
435 | + if (!empty($args['wrap_attributes'])) { |
|
436 | + $output .= AUI_Component_Helper::extra_attributes($args['wrap_attributes']); |
|
437 | 437 | } |
438 | 438 | |
439 | 439 | // close wrap |
@@ -441,9 +441,9 @@ discard block |
||
441 | 441 | |
442 | 442 | |
443 | 443 | // Input group left |
444 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
445 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
446 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
444 | + if (!empty($args['input_group_left'])) { |
|
445 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
446 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
447 | 447 | $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
448 | 448 | } |
449 | 449 | |
@@ -451,15 +451,15 @@ discard block |
||
451 | 451 | $output .= $args['content']; |
452 | 452 | |
453 | 453 | // Input group right |
454 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
455 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
456 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
454 | + if (!empty($args['input_group_right'])) { |
|
455 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
456 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
457 | 457 | $output .= '<div class="input-group-append ' . $position_class . '">' . $input_group_right . '</div>'; |
458 | 458 | } |
459 | 459 | |
460 | 460 | |
461 | 461 | // close wrap |
462 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
462 | + $output .= '</' . sanitize_html_class($args['type']) . '>'; |
|
463 | 463 | |
464 | 464 | |
465 | 465 | } else { |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | * |
477 | 477 | * @return string The rendered component. |
478 | 478 | */ |
479 | - public static function textarea( $args = array() ) { |
|
479 | + public static function textarea($args = array()) { |
|
480 | 480 | $defaults = array( |
481 | 481 | 'name' => '', |
482 | 482 | 'class' => '', |
@@ -510,28 +510,28 @@ discard block |
||
510 | 510 | /** |
511 | 511 | * Parse incoming $args into an array and merge it with $defaults |
512 | 512 | */ |
513 | - $args = wp_parse_args( $args, $defaults ); |
|
513 | + $args = wp_parse_args($args, $defaults); |
|
514 | 514 | $output = ''; |
515 | 515 | |
516 | 516 | // hidden label option needs to be empty |
517 | 517 | $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
518 | 518 | |
519 | 519 | // floating labels don't work with wysiwyg so set it as top |
520 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
520 | + if ($args['label_type'] == 'floating' && !empty($args['wysiwyg'])) { |
|
521 | 521 | $args['label_type'] = 'top'; |
522 | 522 | } |
523 | 523 | |
524 | 524 | $label_after = $args['label_after']; |
525 | 525 | |
526 | 526 | // floating labels need label after |
527 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
527 | + if ($args['label_type'] == 'floating' && empty($args['wysiwyg'])) { |
|
528 | 528 | $label_after = true; |
529 | 529 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
530 | 530 | } |
531 | 531 | |
532 | 532 | // label |
533 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
534 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
533 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
534 | + } elseif (!empty($args['label']) && !$label_after) { |
|
535 | 535 | $label_args = array( |
536 | 536 | 'title' => $args['label'], |
537 | 537 | 'for' => $args['id'], |
@@ -539,34 +539,34 @@ discard block |
||
539 | 539 | 'label_type' => $args['label_type'], |
540 | 540 | 'label_col' => $args['label_col'] |
541 | 541 | ); |
542 | - $output .= self::label( $label_args ); |
|
542 | + $output .= self::label($label_args); |
|
543 | 543 | } |
544 | 544 | |
545 | 545 | // maybe horizontal label |
546 | - if ( $args['label_type'] == 'horizontal' ) { |
|
547 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
546 | + if ($args['label_type'] == 'horizontal') { |
|
547 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
548 | 548 | $output .= '<div class="' . $input_col . '">'; |
549 | 549 | } |
550 | 550 | |
551 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
551 | + if (!empty($args['wysiwyg'])) { |
|
552 | 552 | ob_start(); |
553 | 553 | $content = $args['value']; |
554 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
554 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
555 | 555 | $settings = array( |
556 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
556 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
557 | 557 | 'quicktags' => false, |
558 | 558 | 'media_buttons' => false, |
559 | 559 | 'editor_class' => 'form-control', |
560 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
560 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
561 | 561 | 'teeny' => true, |
562 | 562 | ); |
563 | 563 | |
564 | 564 | // maybe set settings if array |
565 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
566 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
565 | + if (is_array($args['wysiwyg'])) { |
|
566 | + $settings = wp_parse_args($args['wysiwyg'], $settings); |
|
567 | 567 | } |
568 | 568 | |
569 | - wp_editor( $content, $editor_id, $settings ); |
|
569 | + wp_editor($content, $editor_id, $settings); |
|
570 | 570 | $output .= ob_get_clean(); |
571 | 571 | } else { |
572 | 572 | |
@@ -574,65 +574,65 @@ discard block |
||
574 | 574 | $output .= '<textarea '; |
575 | 575 | |
576 | 576 | // name |
577 | - if ( ! empty( $args['name'] ) ) { |
|
578 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
577 | + if (!empty($args['name'])) { |
|
578 | + $output .= ' name="' . esc_attr($args['name']) . '" '; |
|
579 | 579 | } |
580 | 580 | |
581 | 581 | // id |
582 | - if ( ! empty( $args['id'] ) ) { |
|
583 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
582 | + if (!empty($args['id'])) { |
|
583 | + $output .= ' id="' . sanitize_html_class($args['id']) . '" '; |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | // placeholder |
587 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
588 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
587 | + if (isset($args['placeholder']) && '' != $args['placeholder']) { |
|
588 | + $output .= ' placeholder="' . esc_attr($args['placeholder']) . '" '; |
|
589 | 589 | } |
590 | 590 | |
591 | 591 | // title |
592 | - if ( ! empty( $args['title'] ) ) { |
|
593 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
592 | + if (!empty($args['title'])) { |
|
593 | + $output .= ' title="' . esc_attr($args['title']) . '" '; |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | // validation text |
597 | - if ( ! empty( $args['validation_text'] ) ) { |
|
598 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
597 | + if (!empty($args['validation_text'])) { |
|
598 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr($args['validation_text']) . '\')" '; |
|
599 | 599 | $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
600 | 600 | } |
601 | 601 | |
602 | 602 | // validation_pattern |
603 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
604 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
603 | + if (!empty($args['validation_pattern'])) { |
|
604 | + $output .= ' pattern="' . esc_attr($args['validation_pattern']) . '" '; |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | // required |
608 | - if ( ! empty( $args['required'] ) ) { |
|
608 | + if (!empty($args['required'])) { |
|
609 | 609 | $output .= ' required '; |
610 | 610 | } |
611 | 611 | |
612 | 612 | // rows |
613 | - if ( ! empty( $args['rows'] ) ) { |
|
614 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
613 | + if (!empty($args['rows'])) { |
|
614 | + $output .= ' rows="' . absint($args['rows']) . '" '; |
|
615 | 615 | } |
616 | 616 | |
617 | 617 | |
618 | 618 | // class |
619 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
619 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
620 | 620 | $output .= ' class="form-control ' . $class . '" '; |
621 | 621 | |
622 | 622 | // extra attributes |
623 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
624 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
623 | + if (!empty($args['extra_attributes'])) { |
|
624 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | // close tag |
628 | 628 | $output .= ' >'; |
629 | 629 | |
630 | 630 | // value |
631 | - if ( ! empty( $args['value'] ) ) { |
|
632 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
633 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
631 | + if (!empty($args['value'])) { |
|
632 | + if (!empty($args['allow_tags'])) { |
|
633 | + $output .= AUI_Component_Helper::sanitize_html_field($args['value'], $args); // Sanitize HTML. |
|
634 | 634 | } else { |
635 | - $output .= sanitize_textarea_field( $args['value'] ); |
|
635 | + $output .= sanitize_textarea_field($args['value']); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | |
642 | 642 | } |
643 | 643 | |
644 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
644 | + if (!empty($args['label']) && $label_after) { |
|
645 | 645 | $label_args = array( |
646 | 646 | 'title' => $args['label'], |
647 | 647 | 'for' => $args['id'], |
@@ -649,32 +649,32 @@ discard block |
||
649 | 649 | 'label_type' => $args['label_type'], |
650 | 650 | 'label_col' => $args['label_col'] |
651 | 651 | ); |
652 | - $output .= self::label( $label_args ); |
|
652 | + $output .= self::label($label_args); |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | // help text |
656 | - if ( ! empty( $args['help_text'] ) ) { |
|
657 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
656 | + if (!empty($args['help_text'])) { |
|
657 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | // maybe horizontal label |
661 | - if ( $args['label_type'] == 'horizontal' ) { |
|
661 | + if ($args['label_type'] == 'horizontal') { |
|
662 | 662 | $output .= '</div>'; |
663 | 663 | } |
664 | 664 | |
665 | 665 | |
666 | 666 | // wrap |
667 | - if ( ! $args['no_wrap'] ) { |
|
667 | + if (!$args['no_wrap']) { |
|
668 | 668 | $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
669 | 669 | $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
670 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
671 | - $output = self::wrap( array( |
|
670 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
671 | + $output = self::wrap(array( |
|
672 | 672 | 'content' => $output, |
673 | 673 | 'class' => $wrap_class, |
674 | 674 | 'element_require' => $args['element_require'], |
675 | 675 | 'argument_id' => $args['id'], |
676 | 676 | 'wrap_attributes' => $args['wrap_attributes'], |
677 | - ) ); |
|
677 | + )); |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | * |
689 | 689 | * @return string The rendered component. |
690 | 690 | */ |
691 | - public static function select( $args = array() ) { |
|
691 | + public static function select($args = array()) { |
|
692 | 692 | $defaults = array( |
693 | 693 | 'class' => '', |
694 | 694 | 'wrap_class' => '', |
@@ -725,11 +725,11 @@ discard block |
||
725 | 725 | /** |
726 | 726 | * Parse incoming $args into an array and merge it with $defaults |
727 | 727 | */ |
728 | - $args = wp_parse_args( $args, $defaults ); |
|
728 | + $args = wp_parse_args($args, $defaults); |
|
729 | 729 | $output = ''; |
730 | 730 | |
731 | 731 | // for now lets hide floating labels |
732 | - if ( $args['label_type'] == 'floating' ) { |
|
732 | + if ($args['label_type'] == 'floating') { |
|
733 | 733 | $args['label_type'] = 'hidden'; |
734 | 734 | } |
735 | 735 | |
@@ -740,31 +740,31 @@ discard block |
||
740 | 740 | $label_after = $args['label_after']; |
741 | 741 | |
742 | 742 | // floating labels need label after |
743 | - if ( $args['label_type'] == 'floating' ) { |
|
743 | + if ($args['label_type'] == 'floating') { |
|
744 | 744 | $label_after = true; |
745 | 745 | $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
746 | 746 | } |
747 | 747 | |
748 | 748 | // Maybe setup select2 |
749 | 749 | $is_select2 = false; |
750 | - if ( ! empty( $args['select2'] ) ) { |
|
750 | + if (!empty($args['select2'])) { |
|
751 | 751 | $args['class'] .= ' aui-select2'; |
752 | 752 | $is_select2 = true; |
753 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
753 | + } elseif (strpos($args['class'], 'aui-select2') !== false) { |
|
754 | 754 | $is_select2 = true; |
755 | 755 | } |
756 | 756 | |
757 | 757 | // select2 tags |
758 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
758 | + if (!empty($args['select2']) && $args['select2'] === 'tags') { // triple equals needed here for some reason |
|
759 | 759 | $args['data-tags'] = 'true'; |
760 | 760 | $args['data-token-separators'] = "[',']"; |
761 | 761 | $args['multiple'] = true; |
762 | 762 | } |
763 | 763 | |
764 | 764 | // select2 placeholder |
765 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
766 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
767 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
765 | + if ($is_select2 && isset($args['placeholder']) && '' != $args['placeholder'] && empty($args['data-placeholder'])) { |
|
766 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
767 | + $args['data-allow-clear'] = isset($args['data-allow-clear']) ? (bool) $args['data-allow-clear'] : true; |
|
768 | 768 | } |
769 | 769 | |
770 | 770 | |
@@ -776,61 +776,61 @@ discard block |
||
776 | 776 | // } |
777 | 777 | |
778 | 778 | // Set hidden input to save empty value for multiselect. |
779 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
780 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value=""/>'; |
|
779 | + if (!empty($args['multiple']) && !empty($args['name'])) { |
|
780 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name($args['name']) . ' value=""/>'; |
|
781 | 781 | } |
782 | 782 | |
783 | 783 | // open/type |
784 | 784 | $output .= '<select '; |
785 | 785 | |
786 | 786 | // style |
787 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
787 | + if ($is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
788 | 788 | $output .= " style='width:100%;' "; |
789 | 789 | } |
790 | 790 | |
791 | 791 | // element require |
792 | - if ( ! empty( $args['element_require'] ) ) { |
|
793 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
792 | + if (!empty($args['element_require'])) { |
|
793 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
794 | 794 | $args['class'] .= " aui-conditional-field"; |
795 | 795 | } |
796 | 796 | |
797 | 797 | // class |
798 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
799 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
798 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
799 | + $output .= AUI_Component_Helper::class_attr('custom-select ' . $class); |
|
800 | 800 | |
801 | 801 | // name |
802 | - if ( ! empty( $args['name'] ) ) { |
|
803 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
802 | + if (!empty($args['name'])) { |
|
803 | + $output .= AUI_Component_Helper::name($args['name'], $args['multiple']); |
|
804 | 804 | } |
805 | 805 | |
806 | 806 | // id |
807 | - if ( ! empty( $args['id'] ) ) { |
|
808 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
807 | + if (!empty($args['id'])) { |
|
808 | + $output .= AUI_Component_Helper::id($args['id']); |
|
809 | 809 | } |
810 | 810 | |
811 | 811 | // title |
812 | - if ( ! empty( $args['title'] ) ) { |
|
813 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
812 | + if (!empty($args['title'])) { |
|
813 | + $output .= AUI_Component_Helper::title($args['title']); |
|
814 | 814 | } |
815 | 815 | |
816 | 816 | // data-attributes |
817 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
817 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
818 | 818 | |
819 | 819 | // aria-attributes |
820 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
820 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
821 | 821 | |
822 | 822 | // extra attributes |
823 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
824 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
823 | + if (!empty($args['extra_attributes'])) { |
|
824 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
825 | 825 | } |
826 | 826 | |
827 | 827 | // required |
828 | - if ( ! empty( $args['required'] ) ) { |
|
828 | + if (!empty($args['required'])) { |
|
829 | 829 | $output .= ' required '; |
830 | 830 | } |
831 | 831 | |
832 | 832 | // multiple |
833 | - if ( ! empty( $args['multiple'] ) ) { |
|
833 | + if (!empty($args['multiple'])) { |
|
834 | 834 | $output .= ' multiple '; |
835 | 835 | } |
836 | 836 | |
@@ -838,46 +838,46 @@ discard block |
||
838 | 838 | $output .= ' >'; |
839 | 839 | |
840 | 840 | // placeholder |
841 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
842 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
843 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
841 | + if (isset($args['placeholder']) && '' != $args['placeholder'] && !$is_select2) { |
|
842 | + $output .= '<option value="" disabled selected hidden>' . esc_attr($args['placeholder']) . '</option>'; |
|
843 | + } elseif ($is_select2 && !empty($args['placeholder'])) { |
|
844 | 844 | $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
845 | 845 | } |
846 | 846 | |
847 | 847 | // Options |
848 | - if ( ! empty( $args['options'] ) ) { |
|
848 | + if (!empty($args['options'])) { |
|
849 | 849 | |
850 | - if ( ! is_array( $args['options'] ) ) { |
|
850 | + if (!is_array($args['options'])) { |
|
851 | 851 | $output .= $args['options']; // not the preferred way but an option |
852 | 852 | } else { |
853 | - foreach ( $args['options'] as $val => $name ) { |
|
853 | + foreach ($args['options'] as $val => $name) { |
|
854 | 854 | $selected = ''; |
855 | - if ( is_array( $name ) ) { |
|
856 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
857 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
855 | + if (is_array($name)) { |
|
856 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
857 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
858 | 858 | |
859 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
859 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
860 | 860 | } else { |
861 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
862 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
863 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
864 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
865 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
866 | - } elseif ( ! empty( $args['value'] ) ) { |
|
867 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
861 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
862 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
863 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes($name['extra_attributes']) : ''; |
|
864 | + if (!empty($args['multiple']) && !empty($args['value']) && is_array($args['value'])) { |
|
865 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
866 | + } elseif (!empty($args['value'])) { |
|
867 | + $selected = selected($option_value, stripslashes_deep($args['value']), false); |
|
868 | 868 | } |
869 | 869 | |
870 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
870 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . ' ' . $extra_attributes . '>' . $option_label . '</option>'; |
|
871 | 871 | } |
872 | 872 | } else { |
873 | - if ( ! empty( $args['value'] ) ) { |
|
874 | - if ( is_array( $args['value'] ) ) { |
|
875 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
876 | - } elseif ( ! empty( $args['value'] ) ) { |
|
877 | - $selected = selected( $args['value'], $val, false ); |
|
873 | + if (!empty($args['value'])) { |
|
874 | + if (is_array($args['value'])) { |
|
875 | + $selected = in_array($val, $args['value']) ? 'selected="selected"' : ''; |
|
876 | + } elseif (!empty($args['value'])) { |
|
877 | + $selected = selected($args['value'], $val, false); |
|
878 | 878 | } |
879 | 879 | } |
880 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
880 | + $output .= '<option value="' . esc_attr($val) . '" ' . $selected . '>' . esc_attr($name) . '</option>'; |
|
881 | 881 | } |
882 | 882 | } |
883 | 883 | } |
@@ -890,8 +890,8 @@ discard block |
||
890 | 890 | $label = ''; |
891 | 891 | $help_text = ''; |
892 | 892 | // label |
893 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
894 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
893 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
894 | + } elseif (!empty($args['label']) && !$label_after) { |
|
895 | 895 | $label_args = array( |
896 | 896 | 'title' => $args['label'], |
897 | 897 | 'for' => $args['id'], |
@@ -899,49 +899,49 @@ discard block |
||
899 | 899 | 'label_type' => $args['label_type'], |
900 | 900 | 'label_col' => $args['label_col'] |
901 | 901 | ); |
902 | - $label = self::label( $label_args ); |
|
902 | + $label = self::label($label_args); |
|
903 | 903 | } |
904 | 904 | |
905 | 905 | // help text |
906 | - if ( ! empty( $args['help_text'] ) ) { |
|
907 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
906 | + if (!empty($args['help_text'])) { |
|
907 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
908 | 908 | } |
909 | 909 | |
910 | 910 | // input group wraps |
911 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
912 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
913 | - if ( $args['input_group_left'] ) { |
|
914 | - $output = self::wrap( array( |
|
911 | + if ($args['input_group_left'] || $args['input_group_right']) { |
|
912 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
913 | + if ($args['input_group_left']) { |
|
914 | + $output = self::wrap(array( |
|
915 | 915 | 'content' => $output, |
916 | 916 | 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
917 | 917 | 'input_group_left' => $args['input_group_left'], |
918 | 918 | 'input_group_left_inside' => $args['input_group_left_inside'] |
919 | - ) ); |
|
919 | + )); |
|
920 | 920 | } |
921 | - if ( $args['input_group_right'] ) { |
|
922 | - $output = self::wrap( array( |
|
921 | + if ($args['input_group_right']) { |
|
922 | + $output = self::wrap(array( |
|
923 | 923 | 'content' => $output, |
924 | 924 | 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
925 | 925 | 'input_group_right' => $args['input_group_right'], |
926 | 926 | 'input_group_right_inside' => $args['input_group_right_inside'] |
927 | - ) ); |
|
927 | + )); |
|
928 | 928 | } |
929 | 929 | |
930 | 930 | } |
931 | 931 | |
932 | - if ( ! $label_after ) { |
|
932 | + if (!$label_after) { |
|
933 | 933 | $output .= $help_text; |
934 | 934 | } |
935 | 935 | |
936 | 936 | |
937 | - if ( $args['label_type'] == 'horizontal' ) { |
|
938 | - $output = self::wrap( array( |
|
937 | + if ($args['label_type'] == 'horizontal') { |
|
938 | + $output = self::wrap(array( |
|
939 | 939 | 'content' => $output, |
940 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
941 | - ) ); |
|
940 | + 'class' => AUI_Component_Helper::get_column_class($args['label_col'], 'input') |
|
941 | + )); |
|
942 | 942 | } |
943 | 943 | |
944 | - if ( ! $label_after ) { |
|
944 | + if (!$label_after) { |
|
945 | 945 | $output = $label . $output; |
946 | 946 | } |
947 | 947 | |
@@ -952,16 +952,16 @@ discard block |
||
952 | 952 | |
953 | 953 | |
954 | 954 | // wrap |
955 | - if ( ! $args['no_wrap'] ) { |
|
955 | + if (!$args['no_wrap']) { |
|
956 | 956 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
957 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
958 | - $output = self::wrap( array( |
|
957 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
958 | + $output = self::wrap(array( |
|
959 | 959 | 'content' => $output, |
960 | 960 | 'class' => $wrap_class, |
961 | 961 | 'element_require' => $args['element_require'], |
962 | 962 | 'argument_id' => $args['id'], |
963 | 963 | 'wrap_attributes' => $args['wrap_attributes'], |
964 | - ) ); |
|
964 | + )); |
|
965 | 965 | } |
966 | 966 | |
967 | 967 | |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | * |
976 | 976 | * @return string The rendered component. |
977 | 977 | */ |
978 | - public static function radio( $args = array() ) { |
|
978 | + public static function radio($args = array()) { |
|
979 | 979 | $defaults = array( |
980 | 980 | 'class' => '', |
981 | 981 | 'wrap_class' => '', |
@@ -1005,10 +1005,10 @@ discard block |
||
1005 | 1005 | /** |
1006 | 1006 | * Parse incoming $args into an array and merge it with $defaults |
1007 | 1007 | */ |
1008 | - $args = wp_parse_args( $args, $defaults ); |
|
1008 | + $args = wp_parse_args($args, $defaults); |
|
1009 | 1009 | |
1010 | 1010 | // for now lets use horizontal for floating |
1011 | - if ( $args['label_type'] == 'floating' ) { |
|
1011 | + if ($args['label_type'] == 'floating') { |
|
1012 | 1012 | $args['label_type'] = 'horizontal'; |
1013 | 1013 | } |
1014 | 1014 | |
@@ -1023,47 +1023,47 @@ discard block |
||
1023 | 1023 | |
1024 | 1024 | |
1025 | 1025 | // label before |
1026 | - if ( ! empty( $args['label'] ) ) { |
|
1027 | - $output .= self::label( $label_args, 'radio' ); |
|
1026 | + if (!empty($args['label'])) { |
|
1027 | + $output .= self::label($label_args, 'radio'); |
|
1028 | 1028 | } |
1029 | 1029 | |
1030 | 1030 | // maybe horizontal label |
1031 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1032 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1031 | + if ($args['label_type'] == 'horizontal') { |
|
1032 | + $input_col = AUI_Component_Helper::get_column_class($args['label_col'], 'input'); |
|
1033 | 1033 | $output .= '<div class="' . $input_col . '">'; |
1034 | 1034 | } |
1035 | 1035 | |
1036 | - if ( ! empty( $args['options'] ) ) { |
|
1036 | + if (!empty($args['options'])) { |
|
1037 | 1037 | $count = 0; |
1038 | - foreach ( $args['options'] as $value => $label ) { |
|
1038 | + foreach ($args['options'] as $value => $label) { |
|
1039 | 1039 | $option_args = $args; |
1040 | 1040 | $option_args['value'] = $value; |
1041 | 1041 | $option_args['label'] = $label; |
1042 | 1042 | $option_args['checked'] = $value == $args['value'] ? true : false; |
1043 | - $output .= self::radio_option( $option_args, $count ); |
|
1044 | - $count ++; |
|
1043 | + $output .= self::radio_option($option_args, $count); |
|
1044 | + $count++; |
|
1045 | 1045 | } |
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | // help text |
1049 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1049 | + $help_text = !empty($args['help_text']) ? AUI_Component_Helper::help_text($args['help_text']) : ''; |
|
1050 | 1050 | $output .= $help_text; |
1051 | 1051 | |
1052 | 1052 | // maybe horizontal label |
1053 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1053 | + if ($args['label_type'] == 'horizontal') { |
|
1054 | 1054 | $output .= '</div>'; |
1055 | 1055 | } |
1056 | 1056 | |
1057 | 1057 | // wrap |
1058 | 1058 | $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
1059 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1060 | - $output = self::wrap( array( |
|
1059 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1060 | + $output = self::wrap(array( |
|
1061 | 1061 | 'content' => $output, |
1062 | 1062 | 'class' => $wrap_class, |
1063 | 1063 | 'element_require' => $args['element_require'], |
1064 | 1064 | 'argument_id' => $args['id'], |
1065 | 1065 | 'wrap_attributes' => $args['wrap_attributes'], |
1066 | - ) ); |
|
1066 | + )); |
|
1067 | 1067 | |
1068 | 1068 | |
1069 | 1069 | return $output; |
@@ -1076,7 +1076,7 @@ discard block |
||
1076 | 1076 | * |
1077 | 1077 | * @return string The rendered component. |
1078 | 1078 | */ |
1079 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1079 | + public static function radio_option($args = array(), $count = '') { |
|
1080 | 1080 | $defaults = array( |
1081 | 1081 | 'class' => '', |
1082 | 1082 | 'id' => '', |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | /** |
1095 | 1095 | * Parse incoming $args into an array and merge it with $defaults |
1096 | 1096 | */ |
1097 | - $args = wp_parse_args( $args, $defaults ); |
|
1097 | + $args = wp_parse_args($args, $defaults); |
|
1098 | 1098 | |
1099 | 1099 | $output = ''; |
1100 | 1100 | |
@@ -1105,43 +1105,43 @@ discard block |
||
1105 | 1105 | $output .= ' class="form-check-input" '; |
1106 | 1106 | |
1107 | 1107 | // name |
1108 | - if ( ! empty( $args['name'] ) ) { |
|
1109 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1108 | + if (!empty($args['name'])) { |
|
1109 | + $output .= AUI_Component_Helper::name($args['name']); |
|
1110 | 1110 | } |
1111 | 1111 | |
1112 | 1112 | // id |
1113 | - if ( ! empty( $args['id'] ) ) { |
|
1114 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1113 | + if (!empty($args['id'])) { |
|
1114 | + $output .= AUI_Component_Helper::id($args['id'] . $count); |
|
1115 | 1115 | } |
1116 | 1116 | |
1117 | 1117 | // title |
1118 | - if ( ! empty( $args['title'] ) ) { |
|
1119 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1118 | + if (!empty($args['title'])) { |
|
1119 | + $output .= AUI_Component_Helper::title($args['title']); |
|
1120 | 1120 | } |
1121 | 1121 | |
1122 | 1122 | // value |
1123 | - if ( isset( $args['value'] ) ) { |
|
1124 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1123 | + if (isset($args['value'])) { |
|
1124 | + $output .= AUI_Component_Helper::value($args['value']); |
|
1125 | 1125 | } |
1126 | 1126 | |
1127 | 1127 | // checked, for radio and checkboxes |
1128 | - if ( $args['checked'] ) { |
|
1128 | + if ($args['checked']) { |
|
1129 | 1129 | $output .= ' checked '; |
1130 | 1130 | } |
1131 | 1131 | |
1132 | 1132 | // data-attributes |
1133 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1133 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
1134 | 1134 | |
1135 | 1135 | // aria-attributes |
1136 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1136 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
1137 | 1137 | |
1138 | 1138 | // extra attributes |
1139 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1140 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1139 | + if (!empty($args['extra_attributes'])) { |
|
1140 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
1141 | 1141 | } |
1142 | 1142 | |
1143 | 1143 | // required |
1144 | - if ( ! empty( $args['required'] ) ) { |
|
1144 | + if (!empty($args['required'])) { |
|
1145 | 1145 | $output .= ' required '; |
1146 | 1146 | } |
1147 | 1147 | |
@@ -1149,38 +1149,38 @@ discard block |
||
1149 | 1149 | $output .= ' >'; |
1150 | 1150 | |
1151 | 1151 | // label |
1152 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1153 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1154 | - $output .= self::label( array( |
|
1152 | + if (!empty($args['label']) && is_array($args['label'])) { |
|
1153 | + } elseif (!empty($args['label'])) { |
|
1154 | + $output .= self::label(array( |
|
1155 | 1155 | 'title' => $args['label'], |
1156 | 1156 | 'for' => $args['id'] . $count, |
1157 | 1157 | 'class' => 'form-check-label' |
1158 | - ), 'radio' ); |
|
1158 | + ), 'radio'); |
|
1159 | 1159 | } |
1160 | 1160 | |
1161 | 1161 | // wrap |
1162 | - if ( ! $args['no_wrap'] ) { |
|
1162 | + if (!$args['no_wrap']) { |
|
1163 | 1163 | $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
1164 | 1164 | |
1165 | 1165 | // Unique wrap class |
1166 | 1166 | $uniq_class = 'fwrap'; |
1167 | - if ( ! empty( $args['name'] ) ) { |
|
1167 | + if (!empty($args['name'])) { |
|
1168 | 1168 | $uniq_class .= '-' . $args['name']; |
1169 | - } else if ( ! empty( $args['id'] ) ) { |
|
1169 | + } else if (!empty($args['id'])) { |
|
1170 | 1170 | $uniq_class .= '-' . $args['id']; |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1173 | + if (isset($args['value']) || $args['value'] !== "") { |
|
1174 | 1174 | $uniq_class .= '-' . $args['value']; |
1175 | 1175 | } else { |
1176 | 1176 | $uniq_class .= '-' . $count; |
1177 | 1177 | } |
1178 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1178 | + $wrap_class .= ' ' . sanitize_html_class($uniq_class); |
|
1179 | 1179 | |
1180 | - $output = self::wrap( array( |
|
1180 | + $output = self::wrap(array( |
|
1181 | 1181 | 'content' => $output, |
1182 | 1182 | 'class' => $wrap_class |
1183 | - ) ); |
|
1183 | + )); |
|
1184 | 1184 | } |
1185 | 1185 | |
1186 | 1186 | return $output; |
@@ -209,7 +209,7 @@ |
||
209 | 209 | $help_text = ''; |
210 | 210 | //$label_args['class'] .= ' d-inline '; |
211 | 211 | $args['wrap_class'] .= ' align-items-center '; |
212 | - }else{ |
|
212 | + } else{ |
|
213 | 213 | |
214 | 214 | } |
215 | 215 |
@@ -12,492 +12,492 @@ |
||
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, $hook ); |
|
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 | - $merge_tags = 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}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
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( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
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 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | - |
|
152 | - if ( is_array( $payment_form_data ) ) { |
|
153 | - |
|
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
155 | - |
|
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | - |
|
159 | - if ( is_scalar ( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | - } |
|
162 | - |
|
163 | - } |
|
164 | - |
|
165 | - } |
|
166 | - |
|
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Helper function to send an email. |
|
172 | - * |
|
173 | - * @param WPInv_Invoice $invoice |
|
174 | - * @param GetPaid_Notification_Email $email |
|
175 | - * @param string $type |
|
176 | - * @param string|array $recipients |
|
177 | - * @param array $extra_args Extra template args. |
|
178 | - */ |
|
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | - |
|
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | - |
|
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | - return; |
|
186 | - } |
|
187 | - |
|
188 | - $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | - $merge_tags = $email->get_merge_tags(); |
|
190 | - |
|
191 | - $result = $mailer->send( |
|
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
195 | - $email->get_attachments() |
|
196 | - ); |
|
197 | - |
|
198 | - // Maybe send a copy to the admin. |
|
199 | - if ( $email->include_admin_bcc() ) { |
|
200 | - $mailer->send( |
|
201 | - wpinv_get_admin_email(), |
|
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
204 | - $email->get_attachments() |
|
205 | - ); |
|
206 | - } |
|
207 | - |
|
208 | - if ( $result ) { |
|
209 | - $invoice->add_system_note( |
|
210 | - sprintf( |
|
211 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | - ) |
|
215 | - ); |
|
216 | - } else { |
|
217 | - $invoice->add_system_note( |
|
218 | - sprintf( |
|
219 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
225 | - |
|
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | - |
|
228 | - return $result; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Also send emails to any cc users. |
|
233 | - * |
|
234 | - * @param array $recipients |
|
235 | - * @param GetPaid_Notification_Email $email |
|
236 | - */ |
|
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
238 | - |
|
239 | - if ( ! $email->is_admin_email() ) { |
|
240 | - $cc = $email->object->get_email_cc(); |
|
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | - |
|
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | - } |
|
247 | - |
|
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | - } |
|
252 | - |
|
253 | - } |
|
254 | - |
|
255 | - return $recipients; |
|
256 | - |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Sends a new invoice notification. |
|
261 | - * |
|
262 | - * @param WPInv_Invoice $invoice |
|
263 | - */ |
|
264 | - public function new_invoice( $invoice ) { |
|
265 | - |
|
266 | - // Only send this email for invoices created via the admin page. |
|
267 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | - return; |
|
269 | - } |
|
270 | - |
|
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | - $recipient = wpinv_get_admin_email(); |
|
273 | - |
|
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | - |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Sends a cancelled invoice notification. |
|
280 | - * |
|
281 | - * @param WPInv_Invoice $invoice |
|
282 | - */ |
|
283 | - public function cancelled_invoice( $invoice ) { |
|
284 | - |
|
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | - $recipient = wpinv_get_admin_email(); |
|
287 | - |
|
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | - |
|
290 | - } |
|
291 | - |
|
292 | - /** |
|
293 | - * Sends a failed invoice notification. |
|
294 | - * |
|
295 | - * @param WPInv_Invoice $invoice |
|
296 | - */ |
|
297 | - public function failed_invoice( $invoice ) { |
|
298 | - |
|
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | - $recipient = wpinv_get_admin_email(); |
|
301 | - |
|
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | - |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Sends a notification whenever an invoice is put on hold. |
|
308 | - * |
|
309 | - * @param WPInv_Invoice $invoice |
|
310 | - */ |
|
311 | - public function onhold_invoice( $invoice ) { |
|
312 | - |
|
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | - $recipient = $invoice->get_email(); |
|
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, $hook ); |
|
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 | + $merge_tags = 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}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
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( strtolower( $invoice->get_label() ) ), |
|
144 | + '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
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 | + $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
151 | + |
|
152 | + if ( is_array( $payment_form_data ) ) { |
|
153 | + |
|
154 | + foreach ( $payment_form_data as $label => $value ) { |
|
155 | + |
|
156 | + $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | + $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
158 | + |
|
159 | + if ( is_scalar ( $value ) ) { |
|
160 | + $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
161 | + } |
|
162 | + |
|
163 | + } |
|
164 | + |
|
165 | + } |
|
166 | + |
|
167 | + return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Helper function to send an email. |
|
172 | + * |
|
173 | + * @param WPInv_Invoice $invoice |
|
174 | + * @param GetPaid_Notification_Email $email |
|
175 | + * @param string $type |
|
176 | + * @param string|array $recipients |
|
177 | + * @param array $extra_args Extra template args. |
|
178 | + */ |
|
179 | + public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
180 | + |
|
181 | + do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
182 | + |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | + if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
185 | + return; |
|
186 | + } |
|
187 | + |
|
188 | + $mailer = new GetPaid_Notification_Email_Sender(); |
|
189 | + $merge_tags = $email->get_merge_tags(); |
|
190 | + |
|
191 | + $result = $mailer->send( |
|
192 | + apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | + $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | + $email->get_content( $merge_tags, $extra_args ), |
|
195 | + $email->get_attachments() |
|
196 | + ); |
|
197 | + |
|
198 | + // Maybe send a copy to the admin. |
|
199 | + if ( $email->include_admin_bcc() ) { |
|
200 | + $mailer->send( |
|
201 | + wpinv_get_admin_email(), |
|
202 | + $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | + $email->get_content( $merge_tags ), |
|
204 | + $email->get_attachments() |
|
205 | + ); |
|
206 | + } |
|
207 | + |
|
208 | + if ( $result ) { |
|
209 | + $invoice->add_system_note( |
|
210 | + sprintf( |
|
211 | + __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | + sanitize_key( $type ), |
|
213 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
214 | + ) |
|
215 | + ); |
|
216 | + } else { |
|
217 | + $invoice->add_system_note( |
|
218 | + sprintf( |
|
219 | + __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | + sanitize_key( $type ), |
|
221 | + $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | + |
|
226 | + do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
227 | + |
|
228 | + return $result; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Also send emails to any cc users. |
|
233 | + * |
|
234 | + * @param array $recipients |
|
235 | + * @param GetPaid_Notification_Email $email |
|
236 | + */ |
|
237 | + public function filter_email_recipients( $recipients, $email ) { |
|
238 | + |
|
239 | + if ( ! $email->is_admin_email() ) { |
|
240 | + $cc = $email->object->get_email_cc(); |
|
241 | + $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
242 | + |
|
243 | + if ( ! empty( $cc ) ) { |
|
244 | + $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
246 | + } |
|
247 | + |
|
248 | + if ( ! empty( $cc_2 ) ) { |
|
249 | + $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | + $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
251 | + } |
|
252 | + |
|
253 | + } |
|
254 | + |
|
255 | + return $recipients; |
|
256 | + |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Sends a new invoice notification. |
|
261 | + * |
|
262 | + * @param WPInv_Invoice $invoice |
|
263 | + */ |
|
264 | + public function new_invoice( $invoice ) { |
|
265 | + |
|
266 | + // Only send this email for invoices created via the admin page. |
|
267 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
268 | + return; |
|
269 | + } |
|
270 | + |
|
271 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
272 | + $recipient = wpinv_get_admin_email(); |
|
273 | + |
|
274 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
275 | + |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Sends a cancelled invoice notification. |
|
280 | + * |
|
281 | + * @param WPInv_Invoice $invoice |
|
282 | + */ |
|
283 | + public function cancelled_invoice( $invoice ) { |
|
284 | + |
|
285 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
286 | + $recipient = wpinv_get_admin_email(); |
|
287 | + |
|
288 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
289 | + |
|
290 | + } |
|
291 | + |
|
292 | + /** |
|
293 | + * Sends a failed invoice notification. |
|
294 | + * |
|
295 | + * @param WPInv_Invoice $invoice |
|
296 | + */ |
|
297 | + public function failed_invoice( $invoice ) { |
|
298 | + |
|
299 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
300 | + $recipient = wpinv_get_admin_email(); |
|
301 | + |
|
302 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
303 | + |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Sends a notification whenever an invoice is put on hold. |
|
308 | + * |
|
309 | + * @param WPInv_Invoice $invoice |
|
310 | + */ |
|
311 | + public function onhold_invoice( $invoice ) { |
|
312 | + |
|
313 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
314 | + $recipient = $invoice->get_email(); |
|
315 | 315 | |
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
317 | 317 | |
318 | - } |
|
318 | + } |
|
319 | 319 | |
320 | - /** |
|
321 | - * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | - * |
|
323 | - * @param WPInv_Invoice $invoice |
|
324 | - */ |
|
325 | - public function processing_invoice( $invoice ) { |
|
320 | + /** |
|
321 | + * Sends a notification whenever an invoice is marked as processing payment. |
|
322 | + * |
|
323 | + * @param WPInv_Invoice $invoice |
|
324 | + */ |
|
325 | + public function processing_invoice( $invoice ) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | - $recipient = $invoice->get_email(); |
|
327 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
328 | + $recipient = $invoice->get_email(); |
|
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | - |
|
332 | - } |
|
333 | - |
|
334 | - /** |
|
335 | - * Sends a notification whenever an invoice is paid. |
|
336 | - * |
|
337 | - * @param WPInv_Invoice $invoice |
|
338 | - */ |
|
339 | - public function completed_invoice( $invoice ) { |
|
330 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
331 | + |
|
332 | + } |
|
333 | + |
|
334 | + /** |
|
335 | + * Sends a notification whenever an invoice is paid. |
|
336 | + * |
|
337 | + * @param WPInv_Invoice $invoice |
|
338 | + */ |
|
339 | + public function completed_invoice( $invoice ) { |
|
340 | 340 | |
341 | - // (Maybe) abort if it is a renewal invoice. |
|
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | - return; |
|
344 | - } |
|
341 | + // (Maybe) abort if it is a renewal invoice. |
|
342 | + if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
343 | + return; |
|
344 | + } |
|
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | - $recipient = $invoice->get_email(); |
|
346 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
347 | + $recipient = $invoice->get_email(); |
|
348 | 348 | |
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
350 | 350 | |
351 | - } |
|
351 | + } |
|
352 | 352 | |
353 | - /** |
|
354 | - * Sends a notification whenever an invoice is refunded. |
|
355 | - * |
|
356 | - * @param WPInv_Invoice $invoice |
|
357 | - */ |
|
358 | - public function refunded_invoice( $invoice ) { |
|
353 | + /** |
|
354 | + * Sends a notification whenever an invoice is refunded. |
|
355 | + * |
|
356 | + * @param WPInv_Invoice $invoice |
|
357 | + */ |
|
358 | + public function refunded_invoice( $invoice ) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | - $recipient = $invoice->get_email(); |
|
360 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
361 | + $recipient = $invoice->get_email(); |
|
362 | 362 | |
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
364 | 364 | |
365 | - } |
|
365 | + } |
|
366 | 366 | |
367 | - /** |
|
368 | - * Notifies a user about new invoices |
|
369 | - * |
|
370 | - * @param WPInv_Invoice $invoice |
|
371 | - * @param bool $force |
|
372 | - */ |
|
373 | - public function user_invoice( $invoice, $force = false ) { |
|
367 | + /** |
|
368 | + * Notifies a user about new invoices |
|
369 | + * |
|
370 | + * @param WPInv_Invoice $invoice |
|
371 | + * @param bool $force |
|
372 | + */ |
|
373 | + public function user_invoice( $invoice, $force = false ) { |
|
374 | 374 | |
375 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | - return; |
|
377 | - } |
|
378 | - |
|
379 | - // Only send this email for invoices created via the admin page. |
|
380 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | - return; |
|
382 | - } |
|
375 | + if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
376 | + return; |
|
377 | + } |
|
378 | + |
|
379 | + // Only send this email for invoices created via the admin page. |
|
380 | + if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
381 | + return; |
|
382 | + } |
|
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | - $recipient = $invoice->get_email(); |
|
384 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
385 | + $recipient = $invoice->get_email(); |
|
386 | 386 | |
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
388 | 388 | |
389 | - } |
|
390 | - |
|
391 | - /** |
|
392 | - * Checks if an invoice is a payment form invoice. |
|
393 | - * |
|
394 | - * @param int $invoice |
|
395 | - * @return bool |
|
396 | - */ |
|
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
399 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | - } |
|
389 | + } |
|
390 | + |
|
391 | + /** |
|
392 | + * Checks if an invoice is a payment form invoice. |
|
393 | + * |
|
394 | + * @param int $invoice |
|
395 | + * @return bool |
|
396 | + */ |
|
397 | + public function is_payment_form_invoice( $invoice ) { |
|
398 | + $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
399 | + return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Notifies admin about new invoice notes |
|
404 | - * |
|
405 | - * @param WPInv_Invoice $invoice |
|
406 | - * @param string $note |
|
407 | - */ |
|
408 | - public function user_note( $invoice, $note ) { |
|
409 | - |
|
410 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | - $recipient = $invoice->get_email(); |
|
402 | + /** |
|
403 | + * Notifies admin about new invoice notes |
|
404 | + * |
|
405 | + * @param WPInv_Invoice $invoice |
|
406 | + * @param string $note |
|
407 | + */ |
|
408 | + public function user_note( $invoice, $note ) { |
|
409 | + |
|
410 | + $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
411 | + $recipient = $invoice->get_email(); |
|
412 | 412 | |
413 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | - |
|
415 | - } |
|
416 | - |
|
417 | - /** |
|
418 | - * (Force) Sends overdue notices. |
|
419 | - * |
|
420 | - * @param WPInv_Invoice $invoice |
|
421 | - */ |
|
422 | - public function force_send_overdue_notice( $invoice ) { |
|
423 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
425 | - } |
|
426 | - |
|
427 | - /** |
|
428 | - * Sends overdue notices. |
|
429 | - * |
|
430 | - * @TODO: Create an invoices query class. |
|
431 | - */ |
|
432 | - public function overdue() { |
|
433 | - global $wpdb; |
|
434 | - |
|
435 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | - |
|
437 | - // Fetch reminder days. |
|
438 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | - |
|
440 | - // Abort if non is set. |
|
441 | - if ( empty( $reminder_days ) ) { |
|
442 | - return; |
|
443 | - } |
|
444 | - |
|
445 | - // Retrieve date query. |
|
446 | - $date_query = $this->get_date_query( $reminder_days ); |
|
447 | - |
|
448 | - // Invoices table. |
|
449 | - $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | - |
|
451 | - // Fetch invoices. |
|
452 | - $invoices = $wpdb->get_col( |
|
453 | - "SELECT posts.ID FROM $wpdb->posts as posts |
|
413 | + return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
414 | + |
|
415 | + } |
|
416 | + |
|
417 | + /** |
|
418 | + * (Force) Sends overdue notices. |
|
419 | + * |
|
420 | + * @param WPInv_Invoice $invoice |
|
421 | + */ |
|
422 | + public function force_send_overdue_notice( $invoice ) { |
|
423 | + $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | + return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
425 | + } |
|
426 | + |
|
427 | + /** |
|
428 | + * Sends overdue notices. |
|
429 | + * |
|
430 | + * @TODO: Create an invoices query class. |
|
431 | + */ |
|
432 | + public function overdue() { |
|
433 | + global $wpdb; |
|
434 | + |
|
435 | + $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
436 | + |
|
437 | + // Fetch reminder days. |
|
438 | + $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
439 | + |
|
440 | + // Abort if non is set. |
|
441 | + if ( empty( $reminder_days ) ) { |
|
442 | + return; |
|
443 | + } |
|
444 | + |
|
445 | + // Retrieve date query. |
|
446 | + $date_query = $this->get_date_query( $reminder_days ); |
|
447 | + |
|
448 | + // Invoices table. |
|
449 | + $table = $wpdb->prefix . 'getpaid_invoices'; |
|
450 | + |
|
451 | + // Fetch invoices. |
|
452 | + $invoices = $wpdb->get_col( |
|
453 | + "SELECT posts.ID FROM $wpdb->posts as posts |
|
454 | 454 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
455 | 455 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
456 | 456 | |
457 | - foreach ( $invoices as $invoice ) { |
|
457 | + foreach ( $invoices as $invoice ) { |
|
458 | 458 | |
459 | - // Only send this email for invoices created via the admin page. |
|
460 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
461 | - $invoice = new WPInv_Invoice( $invoice ); |
|
462 | - $email->object = $invoice; |
|
459 | + // Only send this email for invoices created via the admin page. |
|
460 | + if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
461 | + $invoice = new WPInv_Invoice( $invoice ); |
|
462 | + $email->object = $invoice; |
|
463 | 463 | |
464 | - if ( $invoice->needs_payment() ) { |
|
465 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
466 | - } |
|
464 | + if ( $invoice->needs_payment() ) { |
|
465 | + $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
466 | + } |
|
467 | 467 | |
468 | - } |
|
468 | + } |
|
469 | 469 | |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - } |
|
472 | + } |
|
473 | 473 | |
474 | - /** |
|
475 | - * Calculates the date query for an invoices query |
|
476 | - * |
|
477 | - * @param array $reminder_days |
|
478 | - * @return string |
|
479 | - */ |
|
480 | - public function get_date_query( $reminder_days ) { |
|
474 | + /** |
|
475 | + * Calculates the date query for an invoices query |
|
476 | + * |
|
477 | + * @param array $reminder_days |
|
478 | + * @return string |
|
479 | + */ |
|
480 | + public function get_date_query( $reminder_days ) { |
|
481 | 481 | |
482 | - $date_query = array( |
|
483 | - 'relation' => 'OR' |
|
484 | - ); |
|
482 | + $date_query = array( |
|
483 | + 'relation' => 'OR' |
|
484 | + ); |
|
485 | 485 | |
486 | - foreach ( $reminder_days as $days ) { |
|
487 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
486 | + foreach ( $reminder_days as $days ) { |
|
487 | + $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
488 | 488 | |
489 | - $date_query[] = array( |
|
490 | - 'year' => $date['year'], |
|
491 | - 'month' => $date['month'], |
|
492 | - 'day' => $date['day'], |
|
493 | - ); |
|
489 | + $date_query[] = array( |
|
490 | + 'year' => $date['year'], |
|
491 | + 'month' => $date['month'], |
|
492 | + 'day' => $date['day'], |
|
493 | + ); |
|
494 | 494 | |
495 | - } |
|
495 | + } |
|
496 | 496 | |
497 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | + $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
498 | 498 | |
499 | - return $date_query->get_sql(); |
|
499 | + return $date_query->get_sql(); |
|
500 | 500 | |
501 | - } |
|
501 | + } |
|
502 | 502 | |
503 | 503 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * This class handles invoice notificaiton emails. |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | $this->invoice_actions = apply_filters( |
29 | 29 | 'getpaid_notification_email_invoice_triggers', |
30 | 30 | array( |
31 | - 'getpaid_new_invoice' => array( 'new_invoice', 'user_invoice' ), |
|
31 | + 'getpaid_new_invoice' => array('new_invoice', 'user_invoice'), |
|
32 | 32 | 'getpaid_invoice_status_wpi-cancelled' => 'cancelled_invoice', |
33 | 33 | 'getpaid_invoice_status_wpi-failed' => 'failed_invoice', |
34 | 34 | 'getpaid_invoice_status_wpi-onhold' => 'onhold_invoice', |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function init_hooks() { |
52 | 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 ); |
|
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 | 55 | |
56 | - foreach ( $this->invoice_actions as $hook => $email_type ) { |
|
57 | - $this->init_email_type_hook( $hook, $email_type ); |
|
56 | + foreach ($this->invoice_actions as $hook => $email_type) { |
|
57 | + $this->init_email_type_hook($hook, $email_type); |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | |
@@ -64,25 +64,25 @@ discard block |
||
64 | 64 | * @param string $hook |
65 | 65 | * @param string|array $email_type |
66 | 66 | */ |
67 | - public function init_email_type_hook( $hook, $email_type ) { |
|
67 | + public function init_email_type_hook($hook, $email_type) { |
|
68 | 68 | |
69 | - $email_type = wpinv_parse_list( $email_type ); |
|
69 | + $email_type = wpinv_parse_list($email_type); |
|
70 | 70 | |
71 | - foreach ( $email_type as $type ) { |
|
71 | + foreach ($email_type as $type) { |
|
72 | 72 | |
73 | - $email = new GetPaid_Notification_Email( $type ); |
|
73 | + $email = new GetPaid_Notification_Email($type); |
|
74 | 74 | |
75 | 75 | // Abort if it is not active. |
76 | - if ( ! $email->is_active() ) { |
|
76 | + if (!$email->is_active()) { |
|
77 | 77 | continue; |
78 | 78 | } |
79 | 79 | |
80 | - if ( method_exists( $this, $type ) ) { |
|
81 | - add_action( $hook, array( $this, $type ), 100, 2 ); |
|
80 | + if (method_exists($this, $type)) { |
|
81 | + add_action($hook, array($this, $type), 100, 2); |
|
82 | 82 | continue; |
83 | 83 | } |
84 | 84 | |
85 | - do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook ); |
|
85 | + do_action('getpaid_invoice_init_email_type_hook', $type, $hook); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | } |
@@ -93,19 +93,19 @@ discard block |
||
93 | 93 | * @param array $merge_tags |
94 | 94 | * @param mixed|WPInv_Invoice|WPInv_Subscription $object |
95 | 95 | */ |
96 | - public function invoice_merge_tags( $merge_tags, $object ) { |
|
96 | + public function invoice_merge_tags($merge_tags, $object) { |
|
97 | 97 | |
98 | - if ( is_a( $object, 'WPInv_Invoice' ) ) { |
|
98 | + if (is_a($object, 'WPInv_Invoice')) { |
|
99 | 99 | return array_merge( |
100 | 100 | $merge_tags, |
101 | - $this->get_invoice_merge_tags( $object ) |
|
101 | + $this->get_invoice_merge_tags($object) |
|
102 | 102 | ); |
103 | 103 | } |
104 | 104 | |
105 | - if ( is_a( $object, 'WPInv_Subscription' ) ) { |
|
105 | + if (is_a($object, 'WPInv_Subscription')) { |
|
106 | 106 | return array_merge( |
107 | 107 | $merge_tags, |
108 | - $this->get_invoice_merge_tags( $object->get_parent_payment() ) |
|
108 | + $this->get_invoice_merge_tags($object->get_parent_payment()) |
|
109 | 109 | ); |
110 | 110 | } |
111 | 111 | |
@@ -119,52 +119,52 @@ discard block |
||
119 | 119 | * @param WPInv_Invoice $invoice |
120 | 120 | * @return array |
121 | 121 | */ |
122 | - public function get_invoice_merge_tags( $invoice ) { |
|
122 | + public function get_invoice_merge_tags($invoice) { |
|
123 | 123 | |
124 | 124 | // Abort if it does not exist. |
125 | - if ( ! $invoice->get_id() ) { |
|
125 | + if (!$invoice->get_id()) { |
|
126 | 126 | return array(); |
127 | 127 | } |
128 | 128 | |
129 | 129 | $merge_tags = 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}' => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ), |
|
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( strtolower( $invoice->get_label() ) ), |
|
144 | - '{invoice_label}' => sanitize_text_field( ucfirst( $invoice->get_label() ) ), |
|
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' ), |
|
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}' => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())), |
|
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(strtolower($invoice->get_label())), |
|
144 | + '{invoice_label}' => sanitize_text_field(ucfirst($invoice->get_label())), |
|
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 | 148 | ); |
149 | 149 | |
150 | - $payment_form_data = $invoice->get_meta( 'payment_form_data', true ); |
|
150 | + $payment_form_data = $invoice->get_meta('payment_form_data', true); |
|
151 | 151 | |
152 | - if ( is_array( $payment_form_data ) ) { |
|
152 | + if (is_array($payment_form_data)) { |
|
153 | 153 | |
154 | - foreach ( $payment_form_data as $label => $value ) { |
|
154 | + foreach ($payment_form_data as $label => $value) { |
|
155 | 155 | |
156 | - $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) ); |
|
157 | - $value = is_array( $value ) ? implode( ', ', $value ) : $value; |
|
156 | + $label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label)); |
|
157 | + $value = is_array($value) ? implode(', ', $value) : $value; |
|
158 | 158 | |
159 | - if ( is_scalar ( $value ) ) { |
|
160 | - $merge_tags[ "{{$label}}" ] = wp_kses_post( $value ); |
|
159 | + if (is_scalar($value)) { |
|
160 | + $merge_tags["{{$label}}"] = wp_kses_post($value); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | } |
164 | 164 | |
165 | 165 | } |
166 | 166 | |
167 | - return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice ); |
|
167 | + return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -176,12 +176,12 @@ discard block |
||
176 | 176 | * @param string|array $recipients |
177 | 177 | * @param array $extra_args Extra template args. |
178 | 178 | */ |
179 | - public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) { |
|
179 | + public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) { |
|
180 | 180 | |
181 | - do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email ); |
|
181 | + do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email); |
|
182 | 182 | |
183 | - $skip = $invoice->is_free() && wpinv_get_option( 'skip_email_free_invoice' ); |
|
184 | - if ( apply_filters( 'getpaid_skip_invoice_email', $skip, $type, $invoice ) ) { |
|
183 | + $skip = $invoice->is_free() && wpinv_get_option('skip_email_free_invoice'); |
|
184 | + if (apply_filters('getpaid_skip_invoice_email', $skip, $type, $invoice)) { |
|
185 | 185 | return; |
186 | 186 | } |
187 | 187 | |
@@ -189,41 +189,41 @@ discard block |
||
189 | 189 | $merge_tags = $email->get_merge_tags(); |
190 | 190 | |
191 | 191 | $result = $mailer->send( |
192 | - apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ), |
|
193 | - $email->add_merge_tags( $email->get_subject(), $merge_tags ), |
|
194 | - $email->get_content( $merge_tags, $extra_args ), |
|
192 | + apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email), |
|
193 | + $email->add_merge_tags($email->get_subject(), $merge_tags), |
|
194 | + $email->get_content($merge_tags, $extra_args), |
|
195 | 195 | $email->get_attachments() |
196 | 196 | ); |
197 | 197 | |
198 | 198 | // Maybe send a copy to the admin. |
199 | - if ( $email->include_admin_bcc() ) { |
|
199 | + if ($email->include_admin_bcc()) { |
|
200 | 200 | $mailer->send( |
201 | 201 | wpinv_get_admin_email(), |
202 | - $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ), |
|
203 | - $email->get_content( $merge_tags ), |
|
202 | + $email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags), |
|
203 | + $email->get_content($merge_tags), |
|
204 | 204 | $email->get_attachments() |
205 | 205 | ); |
206 | 206 | } |
207 | 207 | |
208 | - if ( $result ) { |
|
208 | + if ($result) { |
|
209 | 209 | $invoice->add_system_note( |
210 | 210 | sprintf( |
211 | - __( 'Successfully sent %s notification email to %s.', 'invoicing' ), |
|
212 | - sanitize_key( $type ), |
|
213 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
211 | + __('Successfully sent %s notification email to %s.', 'invoicing'), |
|
212 | + sanitize_key($type), |
|
213 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | } else { |
217 | 217 | $invoice->add_system_note( |
218 | 218 | sprintf( |
219 | - __( 'Failed sending %s notification email to %s.', 'invoicing' ), |
|
220 | - sanitize_key( $type ), |
|
221 | - $email->is_admin_email() ? __( 'admin' ) : __( 'the customer' ) |
|
219 | + __('Failed sending %s notification email to %s.', 'invoicing'), |
|
220 | + sanitize_key($type), |
|
221 | + $email->is_admin_email() ? __('admin') : __('the customer') |
|
222 | 222 | ) |
223 | 223 | ); |
224 | 224 | } |
225 | 225 | |
226 | - do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email ); |
|
226 | + do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email); |
|
227 | 227 | |
228 | 228 | return $result; |
229 | 229 | } |
@@ -234,20 +234,20 @@ discard block |
||
234 | 234 | * @param array $recipients |
235 | 235 | * @param GetPaid_Notification_Email $email |
236 | 236 | */ |
237 | - public function filter_email_recipients( $recipients, $email ) { |
|
237 | + public function filter_email_recipients($recipients, $email) { |
|
238 | 238 | |
239 | - if ( ! $email->is_admin_email() ) { |
|
239 | + if (!$email->is_admin_email()) { |
|
240 | 240 | $cc = $email->object->get_email_cc(); |
241 | - $cc_2 = get_user_meta( $email->object->get_user_id(), '_wpinv_email_cc', true ); |
|
241 | + $cc_2 = get_user_meta($email->object->get_user_id(), '_wpinv_email_cc', true); |
|
242 | 242 | |
243 | - if ( ! empty( $cc ) ) { |
|
244 | - $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) ); |
|
245 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) ); |
|
243 | + if (!empty($cc)) { |
|
244 | + $cc = array_map('sanitize_email', wpinv_parse_list($cc)); |
|
245 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc))); |
|
246 | 246 | } |
247 | 247 | |
248 | - if ( ! empty( $cc_2 ) ) { |
|
249 | - $cc_2 = array_map( 'sanitize_email', wpinv_parse_list( $cc_2 ) ); |
|
250 | - $recipients = array_filter( array_unique( array_merge( $recipients, $cc_2 ) ) ); |
|
248 | + if (!empty($cc_2)) { |
|
249 | + $cc_2 = array_map('sanitize_email', wpinv_parse_list($cc_2)); |
|
250 | + $recipients = array_filter(array_unique(array_merge($recipients, $cc_2))); |
|
251 | 251 | } |
252 | 252 | |
253 | 253 | } |
@@ -261,17 +261,17 @@ discard block |
||
261 | 261 | * |
262 | 262 | * @param WPInv_Invoice $invoice |
263 | 263 | */ |
264 | - public function new_invoice( $invoice ) { |
|
264 | + public function new_invoice($invoice) { |
|
265 | 265 | |
266 | 266 | // Only send this email for invoices created via the admin page. |
267 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || $this->is_payment_form_invoice( $invoice->get_id() ) ) { |
|
267 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || $this->is_payment_form_invoice($invoice->get_id())) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
271 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
272 | 272 | $recipient = wpinv_get_admin_email(); |
273 | 273 | |
274 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
274 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
275 | 275 | |
276 | 276 | } |
277 | 277 | |
@@ -280,12 +280,12 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @param WPInv_Invoice $invoice |
282 | 282 | */ |
283 | - public function cancelled_invoice( $invoice ) { |
|
283 | + public function cancelled_invoice($invoice) { |
|
284 | 284 | |
285 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
285 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
286 | 286 | $recipient = wpinv_get_admin_email(); |
287 | 287 | |
288 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
288 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
289 | 289 | |
290 | 290 | } |
291 | 291 | |
@@ -294,12 +294,12 @@ discard block |
||
294 | 294 | * |
295 | 295 | * @param WPInv_Invoice $invoice |
296 | 296 | */ |
297 | - public function failed_invoice( $invoice ) { |
|
297 | + public function failed_invoice($invoice) { |
|
298 | 298 | |
299 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
299 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
300 | 300 | $recipient = wpinv_get_admin_email(); |
301 | 301 | |
302 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
302 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
303 | 303 | |
304 | 304 | } |
305 | 305 | |
@@ -308,12 +308,12 @@ discard block |
||
308 | 308 | * |
309 | 309 | * @param WPInv_Invoice $invoice |
310 | 310 | */ |
311 | - public function onhold_invoice( $invoice ) { |
|
311 | + public function onhold_invoice($invoice) { |
|
312 | 312 | |
313 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
313 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
314 | 314 | $recipient = $invoice->get_email(); |
315 | 315 | |
316 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
316 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
317 | 317 | |
318 | 318 | } |
319 | 319 | |
@@ -322,12 +322,12 @@ discard block |
||
322 | 322 | * |
323 | 323 | * @param WPInv_Invoice $invoice |
324 | 324 | */ |
325 | - public function processing_invoice( $invoice ) { |
|
325 | + public function processing_invoice($invoice) { |
|
326 | 326 | |
327 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
327 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
328 | 328 | $recipient = $invoice->get_email(); |
329 | 329 | |
330 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
330 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
331 | 331 | |
332 | 332 | } |
333 | 333 | |
@@ -336,17 +336,17 @@ discard block |
||
336 | 336 | * |
337 | 337 | * @param WPInv_Invoice $invoice |
338 | 338 | */ |
339 | - public function completed_invoice( $invoice ) { |
|
339 | + public function completed_invoice($invoice) { |
|
340 | 340 | |
341 | 341 | // (Maybe) abort if it is a renewal invoice. |
342 | - if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) { |
|
342 | + if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) { |
|
343 | 343 | return; |
344 | 344 | } |
345 | 345 | |
346 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
346 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
347 | 347 | $recipient = $invoice->get_email(); |
348 | 348 | |
349 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
349 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
350 | 350 | |
351 | 351 | } |
352 | 352 | |
@@ -355,12 +355,12 @@ discard block |
||
355 | 355 | * |
356 | 356 | * @param WPInv_Invoice $invoice |
357 | 357 | */ |
358 | - public function refunded_invoice( $invoice ) { |
|
358 | + public function refunded_invoice($invoice) { |
|
359 | 359 | |
360 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
360 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
361 | 361 | $recipient = $invoice->get_email(); |
362 | 362 | |
363 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
363 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
364 | 364 | |
365 | 365 | } |
366 | 366 | |
@@ -370,21 +370,21 @@ discard block |
||
370 | 370 | * @param WPInv_Invoice $invoice |
371 | 371 | * @param bool $force |
372 | 372 | */ |
373 | - public function user_invoice( $invoice, $force = false ) { |
|
373 | + public function user_invoice($invoice, $force = false) { |
|
374 | 374 | |
375 | - if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) { |
|
375 | + if (!empty($GLOBALS['wpinv_skip_invoice_notification'])) { |
|
376 | 376 | return; |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Only send this email for invoices created via the admin page. |
380 | - if ( ! $invoice->is_type( 'invoice' ) || $invoice->is_paid() || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) { |
|
380 | + if (!$invoice->is_type('invoice') || $invoice->is_paid() || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) { |
|
381 | 381 | return; |
382 | 382 | } |
383 | 383 | |
384 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
384 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
385 | 385 | $recipient = $invoice->get_email(); |
386 | 386 | |
387 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient ); |
|
387 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient); |
|
388 | 388 | |
389 | 389 | } |
390 | 390 | |
@@ -394,9 +394,9 @@ discard block |
||
394 | 394 | * @param int $invoice |
395 | 395 | * @return bool |
396 | 396 | */ |
397 | - public function is_payment_form_invoice( $invoice ) { |
|
398 | - $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) ); |
|
399 | - return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice ); |
|
397 | + public function is_payment_form_invoice($invoice) { |
|
398 | + $is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' == get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' == get_post_meta($invoice, 'wpinv_created_via', true)); |
|
399 | + return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -405,12 +405,12 @@ discard block |
||
405 | 405 | * @param WPInv_Invoice $invoice |
406 | 406 | * @param string $note |
407 | 407 | */ |
408 | - public function user_note( $invoice, $note ) { |
|
408 | + public function user_note($invoice, $note) { |
|
409 | 409 | |
410 | - $email = new GetPaid_Notification_Email( __FUNCTION__, $invoice ); |
|
410 | + $email = new GetPaid_Notification_Email(__FUNCTION__, $invoice); |
|
411 | 411 | $recipient = $invoice->get_email(); |
412 | 412 | |
413 | - return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) ); |
|
413 | + return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note)); |
|
414 | 414 | |
415 | 415 | } |
416 | 416 | |
@@ -419,9 +419,9 @@ discard block |
||
419 | 419 | * |
420 | 420 | * @param WPInv_Invoice $invoice |
421 | 421 | */ |
422 | - public function force_send_overdue_notice( $invoice ) { |
|
423 | - $email = new GetPaid_Notification_Email( 'overdue', $invoice ); |
|
424 | - return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() ); |
|
422 | + public function force_send_overdue_notice($invoice) { |
|
423 | + $email = new GetPaid_Notification_Email('overdue', $invoice); |
|
424 | + return $this->send_email($invoice, $email, 'overdue', $invoice->get_email()); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -432,37 +432,37 @@ discard block |
||
432 | 432 | public function overdue() { |
433 | 433 | global $wpdb; |
434 | 434 | |
435 | - $email = new GetPaid_Notification_Email( __FUNCTION__ ); |
|
435 | + $email = new GetPaid_Notification_Email(__FUNCTION__); |
|
436 | 436 | |
437 | 437 | // Fetch reminder days. |
438 | - $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) ); |
|
438 | + $reminder_days = array_unique(wp_parse_id_list($email->get_option('days'))); |
|
439 | 439 | |
440 | 440 | // Abort if non is set. |
441 | - if ( empty( $reminder_days ) ) { |
|
441 | + if (empty($reminder_days)) { |
|
442 | 442 | return; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Retrieve date query. |
446 | - $date_query = $this->get_date_query( $reminder_days ); |
|
446 | + $date_query = $this->get_date_query($reminder_days); |
|
447 | 447 | |
448 | 448 | // Invoices table. |
449 | 449 | $table = $wpdb->prefix . 'getpaid_invoices'; |
450 | 450 | |
451 | 451 | // Fetch invoices. |
452 | - $invoices = $wpdb->get_col( |
|
452 | + $invoices = $wpdb->get_col( |
|
453 | 453 | "SELECT posts.ID FROM $wpdb->posts as posts |
454 | 454 | LEFT JOIN $table as invoices ON invoices.post_id = posts.ID |
455 | 455 | WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query"); |
456 | 456 | |
457 | - foreach ( $invoices as $invoice ) { |
|
457 | + foreach ($invoices as $invoice) { |
|
458 | 458 | |
459 | 459 | // Only send this email for invoices created via the admin page. |
460 | - if ( ! $this->is_payment_form_invoice( $invoice ) ) { |
|
461 | - $invoice = new WPInv_Invoice( $invoice ); |
|
460 | + if (!$this->is_payment_form_invoice($invoice)) { |
|
461 | + $invoice = new WPInv_Invoice($invoice); |
|
462 | 462 | $email->object = $invoice; |
463 | 463 | |
464 | - if ( $invoice->needs_payment() ) { |
|
465 | - $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() ); |
|
464 | + if ($invoice->needs_payment()) { |
|
465 | + $this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email()); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | } |
@@ -477,14 +477,14 @@ discard block |
||
477 | 477 | * @param array $reminder_days |
478 | 478 | * @return string |
479 | 479 | */ |
480 | - public function get_date_query( $reminder_days ) { |
|
480 | + public function get_date_query($reminder_days) { |
|
481 | 481 | |
482 | 482 | $date_query = array( |
483 | 483 | 'relation' => 'OR' |
484 | 484 | ); |
485 | 485 | |
486 | - foreach ( $reminder_days as $days ) { |
|
487 | - $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) ); |
|
486 | + foreach ($reminder_days as $days) { |
|
487 | + $date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp')))); |
|
488 | 488 | |
489 | 489 | $date_query[] = array( |
490 | 490 | 'year' => $date['year'], |
@@ -494,7 +494,7 @@ discard block |
||
494 | 494 | |
495 | 495 | } |
496 | 496 | |
497 | - $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' ); |
|
497 | + $date_query = new WP_Date_Query($date_query, 'invoices.due_date'); |
|
498 | 498 | |
499 | 499 | return $date_query->get_sql(); |
500 | 500 |
@@ -7,40 +7,40 @@ |
||
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; |
|
10 | + exit; |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | 16 | add_action('after_setup_theme', function () { |
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | - $this_version = "0.1.64"; |
|
19 | - if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | - } |
|
17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | + $this_version = "0.1.64"; |
|
19 | + if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | + $ayecode_ui_version = $this_version ; |
|
21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | + } |
|
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | 28 | add_action('after_setup_theme', function () { |
29 | - global $ayecode_ui_file_key; |
|
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | - } |
|
29 | + global $ayecode_ui_file_key; |
|
30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | + } |
|
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | 39 | if(!function_exists('aui')){ |
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
42 | - return false; |
|
43 | - } |
|
44 | - return AUI::instance(); |
|
45 | - } |
|
40 | + function aui(){ |
|
41 | + if(!class_exists("AUI",false)){ |
|
42 | + return false; |
|
43 | + } |
|
44 | + return AUI::instance(); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |
@@ -6,39 +6,39 @@ |
||
6 | 6 | /** |
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; |
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | -add_action('after_setup_theme', function () { |
|
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
16 | +add_action('after_setup_theme', function() { |
|
17 | + global $ayecode_ui_version, $ayecode_ui_file_key; |
|
18 | 18 | $this_version = "0.1.64"; |
19 | - if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
19 | + if (empty($ayecode_ui_version) || version_compare($this_version, $ayecode_ui_version, '>')) { |
|
20 | + $ayecode_ui_version = $this_version; |
|
21 | + $ayecode_ui_file_key = wp_hash(__FILE__); |
|
22 | 22 | } |
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | -add_action('after_setup_theme', function () { |
|
28 | +add_action('after_setup_theme', function() { |
|
29 | 29 | global $ayecode_ui_file_key; |
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
30 | + if ($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash(__FILE__)) { |
|
31 | + include_once(dirname(__FILE__) . '/includes/class-aui.php'); |
|
32 | + include_once(dirname(__FILE__) . '/includes/ayecode-ui-settings.php'); |
|
33 | 33 | } |
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | -if(!function_exists('aui')){ |
|
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
39 | +if (!function_exists('aui')) { |
|
40 | + function aui() { |
|
41 | + if (!class_exists("AUI", false)) { |
|
42 | 42 | return false; |
43 | 43 | } |
44 | 44 | return AUI::instance(); |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | class InstalledVersions |
13 | 13 | { |
14 | 14 | private static $installed = array ( |
15 | - 'root' => |
|
16 | - array ( |
|
15 | + 'root' => |
|
16 | + array ( |
|
17 | 17 | 'pretty_version' => 'dev-master', |
18 | 18 | 'version' => 'dev-master', |
19 | 19 | 'aliases' => |
@@ -21,96 +21,96 @@ discard block |
||
21 | 21 | ), |
22 | 22 | 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
23 | 23 | 'name' => 'ayecode/invoicing', |
24 | - ), |
|
25 | - 'versions' => |
|
26 | - array ( |
|
24 | + ), |
|
25 | + 'versions' => |
|
26 | + array ( |
|
27 | 27 | 'ayecode/ayecode-connect-helper' => |
28 | 28 | array ( |
29 | - 'pretty_version' => '1.0.3', |
|
30 | - 'version' => '1.0.3.0', |
|
31 | - 'aliases' => |
|
32 | - array ( |
|
33 | - ), |
|
34 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
29 | + 'pretty_version' => '1.0.3', |
|
30 | + 'version' => '1.0.3.0', |
|
31 | + 'aliases' => |
|
32 | + array ( |
|
33 | + ), |
|
34 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
35 | 35 | ), |
36 | 36 | 'ayecode/invoicing' => |
37 | 37 | array ( |
38 | - 'pretty_version' => 'dev-master', |
|
39 | - 'version' => 'dev-master', |
|
40 | - 'aliases' => |
|
41 | - array ( |
|
42 | - ), |
|
43 | - 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
|
38 | + 'pretty_version' => 'dev-master', |
|
39 | + 'version' => 'dev-master', |
|
40 | + 'aliases' => |
|
41 | + array ( |
|
42 | + ), |
|
43 | + 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
|
44 | 44 | ), |
45 | 45 | 'ayecode/wp-ayecode-ui' => |
46 | 46 | array ( |
47 | - 'pretty_version' => '0.1.64', |
|
48 | - 'version' => '0.1.64.0', |
|
49 | - 'aliases' => |
|
50 | - array ( |
|
51 | - ), |
|
52 | - 'reference' => 'e47b13915328f4253e470646ebd1dcd2b753e09f', |
|
47 | + 'pretty_version' => '0.1.64', |
|
48 | + 'version' => '0.1.64.0', |
|
49 | + 'aliases' => |
|
50 | + array ( |
|
51 | + ), |
|
52 | + 'reference' => 'e47b13915328f4253e470646ebd1dcd2b753e09f', |
|
53 | 53 | ), |
54 | 54 | 'ayecode/wp-deactivation-survey' => |
55 | 55 | array ( |
56 | - 'pretty_version' => '1.0.4', |
|
57 | - 'version' => '1.0.4.0', |
|
58 | - 'aliases' => |
|
59 | - array ( |
|
60 | - ), |
|
61 | - 'reference' => 'd2777fed30acfc4da53b45bf3b4fec2fb27d8398', |
|
56 | + 'pretty_version' => '1.0.4', |
|
57 | + 'version' => '1.0.4.0', |
|
58 | + 'aliases' => |
|
59 | + array ( |
|
60 | + ), |
|
61 | + 'reference' => 'd2777fed30acfc4da53b45bf3b4fec2fb27d8398', |
|
62 | 62 | ), |
63 | 63 | 'ayecode/wp-font-awesome-settings' => |
64 | 64 | array ( |
65 | - 'pretty_version' => '1.0.13', |
|
66 | - 'version' => '1.0.13.0', |
|
67 | - 'aliases' => |
|
68 | - array ( |
|
69 | - ), |
|
70 | - 'reference' => 'a7a11ee4290674ec214d1fe694139af275350402', |
|
65 | + 'pretty_version' => '1.0.13', |
|
66 | + 'version' => '1.0.13.0', |
|
67 | + 'aliases' => |
|
68 | + array ( |
|
69 | + ), |
|
70 | + 'reference' => 'a7a11ee4290674ec214d1fe694139af275350402', |
|
71 | 71 | ), |
72 | 72 | 'ayecode/wp-super-duper' => |
73 | 73 | array ( |
74 | - 'pretty_version' => '1.0.29', |
|
75 | - 'version' => '1.0.29.0', |
|
76 | - 'aliases' => |
|
77 | - array ( |
|
78 | - ), |
|
79 | - 'reference' => '18f3da558aec750cfeaa582f72619fbf8867677a', |
|
74 | + 'pretty_version' => '1.0.29', |
|
75 | + 'version' => '1.0.29.0', |
|
76 | + 'aliases' => |
|
77 | + array ( |
|
78 | + ), |
|
79 | + 'reference' => '18f3da558aec750cfeaa582f72619fbf8867677a', |
|
80 | 80 | ), |
81 | 81 | 'composer/installers' => |
82 | 82 | array ( |
83 | - 'pretty_version' => 'v1.12.0', |
|
84 | - 'version' => '1.12.0.0', |
|
85 | - 'aliases' => |
|
86 | - array ( |
|
87 | - ), |
|
88 | - 'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19', |
|
83 | + 'pretty_version' => 'v1.12.0', |
|
84 | + 'version' => '1.12.0.0', |
|
85 | + 'aliases' => |
|
86 | + array ( |
|
87 | + ), |
|
88 | + 'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19', |
|
89 | 89 | ), |
90 | 90 | 'maxmind-db/reader' => |
91 | 91 | array ( |
92 | - 'pretty_version' => 'v1.6.0', |
|
93 | - 'version' => '1.6.0.0', |
|
94 | - 'aliases' => |
|
95 | - array ( |
|
96 | - ), |
|
97 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
92 | + 'pretty_version' => 'v1.6.0', |
|
93 | + 'version' => '1.6.0.0', |
|
94 | + 'aliases' => |
|
95 | + array ( |
|
96 | + ), |
|
97 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
98 | 98 | ), |
99 | 99 | 'roundcube/plugin-installer' => |
100 | 100 | array ( |
101 | - 'replaced' => |
|
102 | - array ( |
|
101 | + 'replaced' => |
|
102 | + array ( |
|
103 | 103 | 0 => '*', |
104 | - ), |
|
104 | + ), |
|
105 | 105 | ), |
106 | 106 | 'shama/baton' => |
107 | 107 | array ( |
108 | - 'replaced' => |
|
109 | - array ( |
|
108 | + 'replaced' => |
|
109 | + array ( |
|
110 | 110 | 0 => '*', |
111 | - ), |
|
111 | + ), |
|
112 | + ), |
|
112 | 113 | ), |
113 | - ), |
|
114 | 114 | ); |
115 | 115 | |
116 | 116 |
@@ -11,102 +11,102 @@ |
||
11 | 11 | |
12 | 12 | class InstalledVersions |
13 | 13 | { |
14 | -private static $installed = array ( |
|
14 | +private static $installed = array( |
|
15 | 15 | 'root' => |
16 | - array ( |
|
16 | + array( |
|
17 | 17 | 'pretty_version' => 'dev-master', |
18 | 18 | 'version' => 'dev-master', |
19 | 19 | 'aliases' => |
20 | - array ( |
|
20 | + array( |
|
21 | 21 | ), |
22 | 22 | 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
23 | 23 | 'name' => 'ayecode/invoicing', |
24 | 24 | ), |
25 | 25 | 'versions' => |
26 | - array ( |
|
26 | + array( |
|
27 | 27 | 'ayecode/ayecode-connect-helper' => |
28 | - array ( |
|
28 | + array( |
|
29 | 29 | 'pretty_version' => '1.0.3', |
30 | 30 | 'version' => '1.0.3.0', |
31 | 31 | 'aliases' => |
32 | - array ( |
|
32 | + array( |
|
33 | 33 | ), |
34 | 34 | 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
35 | 35 | ), |
36 | 36 | 'ayecode/invoicing' => |
37 | - array ( |
|
37 | + array( |
|
38 | 38 | 'pretty_version' => 'dev-master', |
39 | 39 | 'version' => 'dev-master', |
40 | 40 | 'aliases' => |
41 | - array ( |
|
41 | + array( |
|
42 | 42 | ), |
43 | 43 | 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
44 | 44 | ), |
45 | 45 | 'ayecode/wp-ayecode-ui' => |
46 | - array ( |
|
46 | + array( |
|
47 | 47 | 'pretty_version' => '0.1.64', |
48 | 48 | 'version' => '0.1.64.0', |
49 | 49 | 'aliases' => |
50 | - array ( |
|
50 | + array( |
|
51 | 51 | ), |
52 | 52 | 'reference' => 'e47b13915328f4253e470646ebd1dcd2b753e09f', |
53 | 53 | ), |
54 | 54 | 'ayecode/wp-deactivation-survey' => |
55 | - array ( |
|
55 | + array( |
|
56 | 56 | 'pretty_version' => '1.0.4', |
57 | 57 | 'version' => '1.0.4.0', |
58 | 58 | 'aliases' => |
59 | - array ( |
|
59 | + array( |
|
60 | 60 | ), |
61 | 61 | 'reference' => 'd2777fed30acfc4da53b45bf3b4fec2fb27d8398', |
62 | 62 | ), |
63 | 63 | 'ayecode/wp-font-awesome-settings' => |
64 | - array ( |
|
64 | + array( |
|
65 | 65 | 'pretty_version' => '1.0.13', |
66 | 66 | 'version' => '1.0.13.0', |
67 | 67 | 'aliases' => |
68 | - array ( |
|
68 | + array( |
|
69 | 69 | ), |
70 | 70 | 'reference' => 'a7a11ee4290674ec214d1fe694139af275350402', |
71 | 71 | ), |
72 | 72 | 'ayecode/wp-super-duper' => |
73 | - array ( |
|
73 | + array( |
|
74 | 74 | 'pretty_version' => '1.0.29', |
75 | 75 | 'version' => '1.0.29.0', |
76 | 76 | 'aliases' => |
77 | - array ( |
|
77 | + array( |
|
78 | 78 | ), |
79 | 79 | 'reference' => '18f3da558aec750cfeaa582f72619fbf8867677a', |
80 | 80 | ), |
81 | 81 | 'composer/installers' => |
82 | - array ( |
|
82 | + array( |
|
83 | 83 | 'pretty_version' => 'v1.12.0', |
84 | 84 | 'version' => '1.12.0.0', |
85 | 85 | 'aliases' => |
86 | - array ( |
|
86 | + array( |
|
87 | 87 | ), |
88 | 88 | 'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19', |
89 | 89 | ), |
90 | 90 | 'maxmind-db/reader' => |
91 | - array ( |
|
91 | + array( |
|
92 | 92 | 'pretty_version' => 'v1.6.0', |
93 | 93 | 'version' => '1.6.0.0', |
94 | 94 | 'aliases' => |
95 | - array ( |
|
95 | + array( |
|
96 | 96 | ), |
97 | 97 | 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
98 | 98 | ), |
99 | 99 | 'roundcube/plugin-installer' => |
100 | - array ( |
|
100 | + array( |
|
101 | 101 | 'replaced' => |
102 | - array ( |
|
102 | + array( |
|
103 | 103 | 0 => '*', |
104 | 104 | ), |
105 | 105 | ), |
106 | 106 | 'shama/baton' => |
107 | - array ( |
|
107 | + array( |
|
108 | 108 | 'replaced' => |
109 | - array ( |
|
109 | + array( |
|
110 | 110 | 0 => '*', |
111 | 111 | ), |
112 | 112 | ), |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php return array ( |
2 | - 'root' => |
|
3 | - array ( |
|
2 | + 'root' => |
|
3 | + array ( |
|
4 | 4 | 'pretty_version' => 'dev-master', |
5 | 5 | 'version' => 'dev-master', |
6 | 6 | 'aliases' => |
@@ -8,94 +8,94 @@ discard block |
||
8 | 8 | ), |
9 | 9 | 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
10 | 10 | 'name' => 'ayecode/invoicing', |
11 | - ), |
|
12 | - 'versions' => |
|
13 | - array ( |
|
11 | + ), |
|
12 | + 'versions' => |
|
13 | + array ( |
|
14 | 14 | 'ayecode/ayecode-connect-helper' => |
15 | 15 | array ( |
16 | - 'pretty_version' => '1.0.3', |
|
17 | - 'version' => '1.0.3.0', |
|
18 | - 'aliases' => |
|
19 | - array ( |
|
20 | - ), |
|
21 | - 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
16 | + 'pretty_version' => '1.0.3', |
|
17 | + 'version' => '1.0.3.0', |
|
18 | + 'aliases' => |
|
19 | + array ( |
|
20 | + ), |
|
21 | + 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
|
22 | 22 | ), |
23 | 23 | 'ayecode/invoicing' => |
24 | 24 | array ( |
25 | - 'pretty_version' => 'dev-master', |
|
26 | - 'version' => 'dev-master', |
|
27 | - 'aliases' => |
|
28 | - array ( |
|
29 | - ), |
|
30 | - 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
|
25 | + 'pretty_version' => 'dev-master', |
|
26 | + 'version' => 'dev-master', |
|
27 | + 'aliases' => |
|
28 | + array ( |
|
29 | + ), |
|
30 | + 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
|
31 | 31 | ), |
32 | 32 | 'ayecode/wp-ayecode-ui' => |
33 | 33 | array ( |
34 | - 'pretty_version' => '0.1.64', |
|
35 | - 'version' => '0.1.64.0', |
|
36 | - 'aliases' => |
|
37 | - array ( |
|
38 | - ), |
|
39 | - 'reference' => 'e47b13915328f4253e470646ebd1dcd2b753e09f', |
|
34 | + 'pretty_version' => '0.1.64', |
|
35 | + 'version' => '0.1.64.0', |
|
36 | + 'aliases' => |
|
37 | + array ( |
|
38 | + ), |
|
39 | + 'reference' => 'e47b13915328f4253e470646ebd1dcd2b753e09f', |
|
40 | 40 | ), |
41 | 41 | 'ayecode/wp-deactivation-survey' => |
42 | 42 | array ( |
43 | - 'pretty_version' => '1.0.4', |
|
44 | - 'version' => '1.0.4.0', |
|
45 | - 'aliases' => |
|
46 | - array ( |
|
47 | - ), |
|
48 | - 'reference' => 'd2777fed30acfc4da53b45bf3b4fec2fb27d8398', |
|
43 | + 'pretty_version' => '1.0.4', |
|
44 | + 'version' => '1.0.4.0', |
|
45 | + 'aliases' => |
|
46 | + array ( |
|
47 | + ), |
|
48 | + 'reference' => 'd2777fed30acfc4da53b45bf3b4fec2fb27d8398', |
|
49 | 49 | ), |
50 | 50 | 'ayecode/wp-font-awesome-settings' => |
51 | 51 | array ( |
52 | - 'pretty_version' => '1.0.13', |
|
53 | - 'version' => '1.0.13.0', |
|
54 | - 'aliases' => |
|
55 | - array ( |
|
56 | - ), |
|
57 | - 'reference' => 'a7a11ee4290674ec214d1fe694139af275350402', |
|
52 | + 'pretty_version' => '1.0.13', |
|
53 | + 'version' => '1.0.13.0', |
|
54 | + 'aliases' => |
|
55 | + array ( |
|
56 | + ), |
|
57 | + 'reference' => 'a7a11ee4290674ec214d1fe694139af275350402', |
|
58 | 58 | ), |
59 | 59 | 'ayecode/wp-super-duper' => |
60 | 60 | array ( |
61 | - 'pretty_version' => '1.0.29', |
|
62 | - 'version' => '1.0.29.0', |
|
63 | - 'aliases' => |
|
64 | - array ( |
|
65 | - ), |
|
66 | - 'reference' => '18f3da558aec750cfeaa582f72619fbf8867677a', |
|
61 | + 'pretty_version' => '1.0.29', |
|
62 | + 'version' => '1.0.29.0', |
|
63 | + 'aliases' => |
|
64 | + array ( |
|
65 | + ), |
|
66 | + 'reference' => '18f3da558aec750cfeaa582f72619fbf8867677a', |
|
67 | 67 | ), |
68 | 68 | 'composer/installers' => |
69 | 69 | array ( |
70 | - 'pretty_version' => 'v1.12.0', |
|
71 | - 'version' => '1.12.0.0', |
|
72 | - 'aliases' => |
|
73 | - array ( |
|
74 | - ), |
|
75 | - 'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19', |
|
70 | + 'pretty_version' => 'v1.12.0', |
|
71 | + 'version' => '1.12.0.0', |
|
72 | + 'aliases' => |
|
73 | + array ( |
|
74 | + ), |
|
75 | + 'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19', |
|
76 | 76 | ), |
77 | 77 | 'maxmind-db/reader' => |
78 | 78 | array ( |
79 | - 'pretty_version' => 'v1.6.0', |
|
80 | - 'version' => '1.6.0.0', |
|
81 | - 'aliases' => |
|
82 | - array ( |
|
83 | - ), |
|
84 | - 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
79 | + 'pretty_version' => 'v1.6.0', |
|
80 | + 'version' => '1.6.0.0', |
|
81 | + 'aliases' => |
|
82 | + array ( |
|
83 | + ), |
|
84 | + 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
|
85 | 85 | ), |
86 | 86 | 'roundcube/plugin-installer' => |
87 | 87 | array ( |
88 | - 'replaced' => |
|
89 | - array ( |
|
88 | + 'replaced' => |
|
89 | + array ( |
|
90 | 90 | 0 => '*', |
91 | - ), |
|
91 | + ), |
|
92 | 92 | ), |
93 | 93 | 'shama/baton' => |
94 | 94 | array ( |
95 | - 'replaced' => |
|
96 | - array ( |
|
95 | + 'replaced' => |
|
96 | + array ( |
|
97 | 97 | 0 => '*', |
98 | - ), |
|
98 | + ), |
|
99 | + ), |
|
99 | 100 | ), |
100 | - ), |
|
101 | 101 | ); |
@@ -1,99 +1,99 @@ |
||
1 | -<?php return array ( |
|
1 | +<?php return array( |
|
2 | 2 | 'root' => |
3 | - array ( |
|
3 | + array( |
|
4 | 4 | 'pretty_version' => 'dev-master', |
5 | 5 | 'version' => 'dev-master', |
6 | 6 | 'aliases' => |
7 | - array ( |
|
7 | + array( |
|
8 | 8 | ), |
9 | 9 | 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
10 | 10 | 'name' => 'ayecode/invoicing', |
11 | 11 | ), |
12 | 12 | 'versions' => |
13 | - array ( |
|
13 | + array( |
|
14 | 14 | 'ayecode/ayecode-connect-helper' => |
15 | - array ( |
|
15 | + array( |
|
16 | 16 | 'pretty_version' => '1.0.3', |
17 | 17 | 'version' => '1.0.3.0', |
18 | 18 | 'aliases' => |
19 | - array ( |
|
19 | + array( |
|
20 | 20 | ), |
21 | 21 | 'reference' => '1af7cdefdbd20d4443a3ab4834e4c1cd8fe57fb4', |
22 | 22 | ), |
23 | 23 | 'ayecode/invoicing' => |
24 | - array ( |
|
24 | + array( |
|
25 | 25 | 'pretty_version' => 'dev-master', |
26 | 26 | 'version' => 'dev-master', |
27 | 27 | 'aliases' => |
28 | - array ( |
|
28 | + array( |
|
29 | 29 | ), |
30 | 30 | 'reference' => '9f729ee78be545f474a617e1a4abb041d6f6eb4a', |
31 | 31 | ), |
32 | 32 | 'ayecode/wp-ayecode-ui' => |
33 | - array ( |
|
33 | + array( |
|
34 | 34 | 'pretty_version' => '0.1.64', |
35 | 35 | 'version' => '0.1.64.0', |
36 | 36 | 'aliases' => |
37 | - array ( |
|
37 | + array( |
|
38 | 38 | ), |
39 | 39 | 'reference' => 'e47b13915328f4253e470646ebd1dcd2b753e09f', |
40 | 40 | ), |
41 | 41 | 'ayecode/wp-deactivation-survey' => |
42 | - array ( |
|
42 | + array( |
|
43 | 43 | 'pretty_version' => '1.0.4', |
44 | 44 | 'version' => '1.0.4.0', |
45 | 45 | 'aliases' => |
46 | - array ( |
|
46 | + array( |
|
47 | 47 | ), |
48 | 48 | 'reference' => 'd2777fed30acfc4da53b45bf3b4fec2fb27d8398', |
49 | 49 | ), |
50 | 50 | 'ayecode/wp-font-awesome-settings' => |
51 | - array ( |
|
51 | + array( |
|
52 | 52 | 'pretty_version' => '1.0.13', |
53 | 53 | 'version' => '1.0.13.0', |
54 | 54 | 'aliases' => |
55 | - array ( |
|
55 | + array( |
|
56 | 56 | ), |
57 | 57 | 'reference' => 'a7a11ee4290674ec214d1fe694139af275350402', |
58 | 58 | ), |
59 | 59 | 'ayecode/wp-super-duper' => |
60 | - array ( |
|
60 | + array( |
|
61 | 61 | 'pretty_version' => '1.0.29', |
62 | 62 | 'version' => '1.0.29.0', |
63 | 63 | 'aliases' => |
64 | - array ( |
|
64 | + array( |
|
65 | 65 | ), |
66 | 66 | 'reference' => '18f3da558aec750cfeaa582f72619fbf8867677a', |
67 | 67 | ), |
68 | 68 | 'composer/installers' => |
69 | - array ( |
|
69 | + array( |
|
70 | 70 | 'pretty_version' => 'v1.12.0', |
71 | 71 | 'version' => '1.12.0.0', |
72 | 72 | 'aliases' => |
73 | - array ( |
|
73 | + array( |
|
74 | 74 | ), |
75 | 75 | 'reference' => 'd20a64ed3c94748397ff5973488761b22f6d3f19', |
76 | 76 | ), |
77 | 77 | 'maxmind-db/reader' => |
78 | - array ( |
|
78 | + array( |
|
79 | 79 | 'pretty_version' => 'v1.6.0', |
80 | 80 | 'version' => '1.6.0.0', |
81 | 81 | 'aliases' => |
82 | - array ( |
|
82 | + array( |
|
83 | 83 | ), |
84 | 84 | 'reference' => 'febd4920bf17c1da84cef58e56a8227dfb37fbe4', |
85 | 85 | ), |
86 | 86 | 'roundcube/plugin-installer' => |
87 | - array ( |
|
87 | + array( |
|
88 | 88 | 'replaced' => |
89 | - array ( |
|
89 | + array( |
|
90 | 90 | 0 => '*', |
91 | 91 | ), |
92 | 92 | ), |
93 | 93 | 'shama/baton' => |
94 | - array ( |
|
94 | + array( |
|
95 | 95 | 'replaced' => |
96 | - array ( |
|
96 | + array( |
|
97 | 97 | 0 => '*', |
98 | 98 | ), |
99 | 99 | ), |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Item_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the item. |
@@ -270,35 +270,35 @@ discard block |
||
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
273 | - * Save meta box data. |
|
274 | - * |
|
275 | - * @param int $post_id |
|
276 | - */ |
|
277 | - public static function save( $post_id ) { |
|
273 | + * Save meta box data. |
|
274 | + * |
|
275 | + * @param int $post_id |
|
276 | + */ |
|
277 | + public static function save( $post_id ) { |
|
278 | 278 | |
279 | 279 | // Prepare the item. |
280 | 280 | $item = new WPInv_Item( $post_id ); |
281 | 281 | |
282 | 282 | // Load new data. |
283 | 283 | $item->set_props( |
284 | - array( |
|
285 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | - 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
284 | + array( |
|
285 | + 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | + 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | + 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | + 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | + 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
290 | 290 | 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
291 | - 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
292 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | - ) |
|
291 | + 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
292 | + 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | + 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | + 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | + 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | + 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | + 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | + ) |
|
299 | 299 | ); |
300 | 300 | |
301 | - $item->save(); |
|
302 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
303 | - } |
|
301 | + $item->save(); |
|
302 | + do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
303 | + } |
|
304 | 304 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,27 +21,27 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the item. |
27 | - $item = new WPInv_Item( $post ); |
|
27 | + $item = new WPInv_Item($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | 32 | // Set the currency position. |
33 | 33 | $position = wpinv_currency_position(); |
34 | 34 | |
35 | - if ( $position == 'left_space' ) { |
|
35 | + if ($position == 'left_space') { |
|
36 | 36 | $position = 'left'; |
37 | 37 | } |
38 | 38 | |
39 | - if ( $position == 'right_space' ) { |
|
39 | + if ($position == 'right_space') { |
|
40 | 40 | $position = 'right'; |
41 | 41 | } |
42 | 42 | |
43 | 43 | ?> |
44 | - <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" /> |
|
44 | + <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr($item->get_type('edit')); ?>" /> |
|
45 | 45 | <style> |
46 | 46 | #poststuff .input-group-text, |
47 | 47 | #poststuff .form-control { |
@@ -55,21 +55,21 @@ discard block |
||
55 | 55 | </style> |
56 | 56 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
57 | 57 | |
58 | - <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?> |
|
58 | + <?php do_action('wpinv_item_details_metabox_before_price', $item); ?> |
|
59 | 59 | <div class="form-group row"> |
60 | - <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e( 'Item Price', 'invoicing' )?></span></label> |
|
60 | + <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php _e('Item Price', 'invoicing')?></span></label> |
|
61 | 61 | <div class="col-sm-8"> |
62 | 62 | <div class="row"> |
63 | 63 | <div class="col-sm-4 getpaid-price-input"> |
64 | 64 | <div class="input-group input-group-sm"> |
65 | - <?php if( 'left' == $position ) : ?> |
|
65 | + <?php if ('left' == $position) : ?> |
|
66 | 66 | <div class="input-group-prepend"> |
67 | 67 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
68 | 68 | </div> |
69 | 69 | <?php endif; ?> |
70 | - <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
|
70 | + <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control"> |
|
71 | 71 | |
72 | - <?php if( 'left' != $position ) : ?> |
|
72 | + <?php if ('left' != $position) : ?> |
|
73 | 73 | <div class="input-group-append"> |
74 | 74 | <span class="input-group-text" id="wpinv_item_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
75 | 75 | </div> |
@@ -79,10 +79,10 @@ discard block |
||
79 | 79 | </div> |
80 | 80 | <div class="col-sm-4 wpinv_show_if_recurring"> |
81 | 81 | <?php |
82 | - _e( 'every' ); |
|
82 | + _e('every'); |
|
83 | 83 | echo " "; |
84 | 84 | ?> |
85 | - <input type="number" style="max-width: 60px;" value="<?php echo esc_attr( $item->get_recurring_interval( 'edit' ) ); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" /> |
|
85 | + <input type="number" style="max-width: 60px;" value="<?php echo esc_attr($item->get_recurring_interval('edit')); ?>" placeholder="1" name="wpinv_recurring_interval" id="wpinv_recurring_interval" /> |
|
86 | 86 | </div> |
87 | 87 | <div class="col-sm-4 wpinv_show_if_recurring"> |
88 | 88 | <?php |
@@ -90,16 +90,16 @@ discard block |
||
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_recurring_period', |
92 | 92 | 'name' => 'wpinv_recurring_period', |
93 | - 'label' => __( 'Period', 'invoicing' ), |
|
94 | - 'placeholder' => __( 'Select Period', 'invoicing' ), |
|
95 | - 'value' => $item->get_recurring_period( 'edit' ), |
|
93 | + 'label' => __('Period', 'invoicing'), |
|
94 | + 'placeholder' => __('Select Period', 'invoicing'), |
|
95 | + 'value' => $item->get_recurring_period('edit'), |
|
96 | 96 | 'select2' => true, |
97 | 97 | 'data-allow-clear' => 'false', |
98 | 98 | 'options' => array( |
99 | - 'D' => __( 'day(s)', 'invoicing' ), |
|
100 | - 'W' => __( 'week(s)', 'invoicing' ), |
|
101 | - 'M' => __( 'month(s)', 'invoicing' ), |
|
102 | - 'Y' => __( 'year(s)', 'invoicing' ), |
|
99 | + 'D' => __('day(s)', 'invoicing'), |
|
100 | + 'W' => __('week(s)', 'invoicing'), |
|
101 | + 'M' => __('month(s)', 'invoicing'), |
|
102 | + 'Y' => __('year(s)', 'invoicing'), |
|
103 | 103 | ) |
104 | 104 | ) |
105 | 105 | ); |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | <?php |
112 | 112 | |
113 | 113 | // Dynamic pricing. |
114 | - if( $item->supports_dynamic_pricing() ) { |
|
114 | + if ($item->supports_dynamic_pricing()) { |
|
115 | 115 | |
116 | - do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item ); |
|
116 | + do_action('wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item); |
|
117 | 117 | |
118 | 118 | // NYP toggle. |
119 | 119 | echo aui()->input( |
@@ -121,31 +121,31 @@ discard block |
||
121 | 121 | 'id' => 'wpinv_name_your_price', |
122 | 122 | 'name' => 'wpinv_name_your_price', |
123 | 123 | 'type' => 'checkbox', |
124 | - 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ), |
|
124 | + 'label' => apply_filters('wpinv_name_your_price_toggle_text', __('Let customers name their price', 'invoicing')), |
|
125 | 125 | 'value' => '1', |
126 | 126 | 'checked' => $item->user_can_set_their_price(), |
127 | 127 | 'no_wrap' => true, |
128 | 128 | ) |
129 | 129 | ); |
130 | 130 | |
131 | - do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item ); |
|
131 | + do_action('wpinv_item_details_metabox_dynamic_pricing_checkbox', $item); |
|
132 | 132 | |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Subscriptions. |
136 | - do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item ); |
|
136 | + do_action('wpinv_item_details_metabox_before_subscription_checkbox', $item); |
|
137 | 137 | echo aui()->input( |
138 | 138 | array( |
139 | 139 | 'id' => 'wpinv_is_recurring', |
140 | 140 | 'name' => 'wpinv_is_recurring', |
141 | 141 | 'type' => 'checkbox', |
142 | - 'label' => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ), |
|
142 | + 'label' => apply_filters('wpinv_is_recurring_toggle_text', __('Charge customers a recurring amount for this item', 'invoicing')), |
|
143 | 143 | 'value' => '1', |
144 | 144 | 'checked' => $item->is_recurring(), |
145 | 145 | 'no_wrap' => true, |
146 | 146 | ) |
147 | 147 | ); |
148 | - do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item ); |
|
148 | + do_action('wpinv_item_details_metabox_subscription_checkbox', $item); |
|
149 | 149 | |
150 | 150 | ?> |
151 | 151 | <div class="wpinv_show_if_recurring"> |
@@ -155,30 +155,30 @@ discard block |
||
155 | 155 | </div> |
156 | 156 | </div> |
157 | 157 | <div class="col-sm-1 pt-2 pl-0"> |
158 | - <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span> |
|
158 | + <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e('Set the subscription price, billing interval and period.', 'invoicing'); ?>"></span> |
|
159 | 159 | </div> |
160 | 160 | </div> |
161 | - <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?> |
|
161 | + <?php do_action('wpinv_item_details_metabox_after_price', $item); ?> |
|
162 | 162 | |
163 | - <?php if( $item->supports_dynamic_pricing() ) : ?> |
|
164 | - <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?> |
|
163 | + <?php if ($item->supports_dynamic_pricing()) : ?> |
|
164 | + <?php do_action('wpinv_item_details_metabox_before_minimum_price', $item); ?> |
|
165 | 165 | <div class="wpinv_show_if_dynamic wpinv_minimum_price"> |
166 | 166 | |
167 | 167 | <div class="form-group row"> |
168 | 168 | <label for="wpinv_minimum_price" class="col-sm-3 col-form-label"> |
169 | - <?php _e( 'Minimum Price', 'invoicing' );?> |
|
169 | + <?php _e('Minimum Price', 'invoicing'); ?> |
|
170 | 170 | </label> |
171 | 171 | <div class="col-sm-8"> |
172 | 172 | <div class="input-group input-group-sm"> |
173 | - <?php if( 'left' == $position ) : ?> |
|
173 | + <?php if ('left' == $position) : ?> |
|
174 | 174 | <div class="input-group-prepend"> |
175 | 175 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
176 | 176 | </div> |
177 | 177 | <?php endif; ?> |
178 | 178 | |
179 | - <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control"> |
|
179 | + <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr(getpaid_unstandardize_amount($item->get_minimum_price('edit'))); ?>" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control"> |
|
180 | 180 | |
181 | - <?php if( 'left' != $position ) : ?> |
|
181 | + <?php if ('left' != $position) : ?> |
|
182 | 182 | <div class="input-group-append"> |
183 | 183 | <span class="input-group-text" id="wpinv_item_minimum_price_symbol"><?php echo wpinv_currency_symbol(); ?></span> |
184 | 184 | </div> |
@@ -187,45 +187,45 @@ discard block |
||
187 | 187 | </div> |
188 | 188 | |
189 | 189 | <div class="col-sm-1 pt-2 pl-0"> |
190 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span> |
|
190 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the minimum amount that users are allowed to set', 'invoicing'); ?>"></span> |
|
191 | 191 | </div> |
192 | 192 | </div> |
193 | 193 | |
194 | 194 | </div> |
195 | - <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?> |
|
195 | + <?php do_action('wpinv_item_details_metabox_minimum_price', $item); ?> |
|
196 | 196 | <?php endif; ?> |
197 | 197 | |
198 | - <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?> |
|
198 | + <?php do_action('wpinv_item_details_metabox_before_maximum_renewals', $item); ?> |
|
199 | 199 | <div class="wpinv_show_if_recurring wpinv_maximum_renewals"> |
200 | 200 | |
201 | 201 | <div class="form-group row"> |
202 | 202 | <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label"> |
203 | - <?php _e( 'Maximum Renewals', 'invoicing' );?> |
|
203 | + <?php _e('Maximum Renewals', 'invoicing'); ?> |
|
204 | 204 | </label> |
205 | 205 | <div class="col-sm-8"> |
206 | - <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
|
206 | + <input type="number" value="<?php echo esc_attr($item->get_recurring_limit('edit')); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" style="width: 100%;" /> |
|
207 | 207 | </div> |
208 | 208 | <div class="col-sm-1 pt-2 pl-0"> |
209 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span> |
|
209 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing'); ?>"></span> |
|
210 | 210 | </div> |
211 | 211 | </div> |
212 | 212 | |
213 | 213 | </div> |
214 | - <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?> |
|
214 | + <?php do_action('wpinv_item_details_metabox_maximum_renewals', $item); ?> |
|
215 | 215 | |
216 | - <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?> |
|
216 | + <?php do_action('wpinv_item_details_metabox_before_free_trial', $item); ?> |
|
217 | 217 | <div class="wpinv_show_if_recurring wpinv_free_trial"> |
218 | 218 | |
219 | 219 | <div class="form-group row"> |
220 | - <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined( 'GETPAID_PAID_TRIALS_VERSION' ) ? _e( 'Free/Paid Trial', 'invoicing' ) : _e( 'Free Trial', 'invoicing' )?></label> |
|
220 | + <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined('GETPAID_PAID_TRIALS_VERSION') ? _e('Free/Paid Trial', 'invoicing') : _e('Free Trial', 'invoicing')?></label> |
|
221 | 221 | |
222 | 222 | <div class="col-sm-8"> |
223 | 223 | <div class="row"> |
224 | 224 | <div class="col-sm-6"> |
225 | - <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0;?> |
|
225 | + <?php $value = $item->has_free_trial() ? $item->get_trial_interval('edit') : 0; ?> |
|
226 | 226 | |
227 | 227 | <div> |
228 | - <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" > |
|
228 | + <input type="number" name="wpinv_trial_interval" style="width: 100%;" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr($value); ?>" > |
|
229 | 229 | </div> |
230 | 230 | </div> |
231 | 231 | <div class="col-sm-6"> |
@@ -234,17 +234,17 @@ discard block |
||
234 | 234 | array( |
235 | 235 | 'id' => 'wpinv_trial_period', |
236 | 236 | 'name' => 'wpinv_trial_period', |
237 | - 'label' => __( 'Trial Period', 'invoicing' ), |
|
238 | - 'placeholder' => __( 'Trial Period', 'invoicing' ), |
|
239 | - 'value' => $item->get_trial_period( 'edit' ), |
|
237 | + 'label' => __('Trial Period', 'invoicing'), |
|
238 | + 'placeholder' => __('Trial Period', 'invoicing'), |
|
239 | + 'value' => $item->get_trial_period('edit'), |
|
240 | 240 | 'select2' => true, |
241 | 241 | 'data-allow-clear' => 'false', |
242 | 242 | 'no_wrap' => true, |
243 | 243 | 'options' => array( |
244 | - 'D' => __( 'day(s)', 'invoicing' ), |
|
245 | - 'W' => __( 'week(s)', 'invoicing' ), |
|
246 | - 'M' => __( 'month(s)', 'invoicing' ), |
|
247 | - 'Y' => __( 'year(s)', 'invoicing' ), |
|
244 | + 'D' => __('day(s)', 'invoicing'), |
|
245 | + 'W' => __('week(s)', 'invoicing'), |
|
246 | + 'M' => __('month(s)', 'invoicing'), |
|
247 | + 'Y' => __('year(s)', 'invoicing'), |
|
248 | 248 | ) |
249 | 249 | ) |
250 | 250 | ); |
@@ -255,15 +255,15 @@ discard block |
||
255 | 255 | </div> |
256 | 256 | |
257 | 257 | <div class="col-sm-1 pt-2 pl-0"> |
258 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span> |
|
258 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('An optional period of time to wait before charging the first recurring payment.', 'invoicing'); ?>"></span> |
|
259 | 259 | </div> |
260 | 260 | |
261 | 261 | </div> |
262 | 262 | |
263 | 263 | </div> |
264 | - <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?> |
|
264 | + <?php do_action('wpinv_item_details_metabox__free_trial', $item); ?> |
|
265 | 265 | |
266 | - <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?> |
|
266 | + <?php do_action('wpinv_item_details_metabox_item_details', $item); ?> |
|
267 | 267 | </div> |
268 | 268 | <?php |
269 | 269 | |
@@ -274,31 +274,31 @@ discard block |
||
274 | 274 | * |
275 | 275 | * @param int $post_id |
276 | 276 | */ |
277 | - public static function save( $post_id ) { |
|
277 | + public static function save($post_id) { |
|
278 | 278 | |
279 | 279 | // Prepare the item. |
280 | - $item = new WPInv_Item( $post_id ); |
|
280 | + $item = new WPInv_Item($post_id); |
|
281 | 281 | |
282 | 282 | // Load new data. |
283 | 283 | $item->set_props( |
284 | 284 | array( |
285 | - 'price' => isset( $_POST['wpinv_item_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_item_price'] ) : null, |
|
286 | - 'vat_rule' => isset( $_POST['wpinv_vat_rules'] ) ? wpinv_clean( $_POST['wpinv_vat_rules'] ) : null, |
|
287 | - 'vat_class' => isset( $_POST['wpinv_vat_class'] ) ? wpinv_clean( $_POST['wpinv_vat_class'] ) : null, |
|
288 | - 'type' => isset( $_POST['wpinv_item_type'] ) ? wpinv_clean( $_POST['wpinv_item_type'] ) : null, |
|
289 | - 'is_dynamic_pricing' => ! empty( $_POST['wpinv_name_your_price'] ), |
|
290 | - 'minimum_price' => isset( $_POST['wpinv_minimum_price'] ) ? getpaid_standardize_amount( $_POST['wpinv_minimum_price'] ) : null, |
|
291 | - 'is_recurring' => ! empty( $_POST['wpinv_is_recurring'] ), |
|
292 | - 'recurring_period' => isset( $_POST['wpinv_recurring_period'] ) ? wpinv_clean( $_POST['wpinv_recurring_period'] ) : null, |
|
293 | - 'recurring_interval' => isset( $_POST['wpinv_recurring_interval'] ) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | - 'recurring_limit' => isset( $_POST['wpinv_recurring_limit'] ) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | - 'is_free_trial' => isset( $_POST['wpinv_trial_interval'] ) ? ( 0 != (int) $_POST['wpinv_trial_interval'] ) : null, |
|
296 | - 'trial_period' => isset( $_POST['wpinv_trial_period'] ) ? wpinv_clean( $_POST['wpinv_trial_period'] ) : null, |
|
297 | - 'trial_interval' => isset( $_POST['wpinv_trial_interval'] ) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
285 | + 'price' => isset($_POST['wpinv_item_price']) ? getpaid_standardize_amount($_POST['wpinv_item_price']) : null, |
|
286 | + 'vat_rule' => isset($_POST['wpinv_vat_rules']) ? wpinv_clean($_POST['wpinv_vat_rules']) : null, |
|
287 | + 'vat_class' => isset($_POST['wpinv_vat_class']) ? wpinv_clean($_POST['wpinv_vat_class']) : null, |
|
288 | + 'type' => isset($_POST['wpinv_item_type']) ? wpinv_clean($_POST['wpinv_item_type']) : null, |
|
289 | + 'is_dynamic_pricing' => !empty($_POST['wpinv_name_your_price']), |
|
290 | + 'minimum_price' => isset($_POST['wpinv_minimum_price']) ? getpaid_standardize_amount($_POST['wpinv_minimum_price']) : null, |
|
291 | + 'is_recurring' => !empty($_POST['wpinv_is_recurring']), |
|
292 | + 'recurring_period' => isset($_POST['wpinv_recurring_period']) ? wpinv_clean($_POST['wpinv_recurring_period']) : null, |
|
293 | + 'recurring_interval' => isset($_POST['wpinv_recurring_interval']) ? (int) $_POST['wpinv_recurring_interval'] : 1, |
|
294 | + 'recurring_limit' => isset($_POST['wpinv_recurring_limit']) ? (int) $_POST['wpinv_recurring_limit'] : null, |
|
295 | + 'is_free_trial' => isset($_POST['wpinv_trial_interval']) ? (0 != (int) $_POST['wpinv_trial_interval']) : null, |
|
296 | + 'trial_period' => isset($_POST['wpinv_trial_period']) ? wpinv_clean($_POST['wpinv_trial_period']) : null, |
|
297 | + 'trial_interval' => isset($_POST['wpinv_trial_interval']) ? (int) $_POST['wpinv_trial_interval'] : null, |
|
298 | 298 | ) |
299 | 299 | ); |
300 | 300 | |
301 | 301 | $item->save(); |
302 | - do_action( 'getpaid_item_metabox_save', $post_id, $item ); |
|
302 | + do_action('getpaid_item_metabox_save', $post_id, $item); |
|
303 | 303 | } |
304 | 304 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Discount_Details { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the discount. |
@@ -396,35 +396,35 @@ discard block |
||
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
399 | - * Save meta box data. |
|
400 | - * |
|
401 | - * @param int $post_id |
|
402 | - */ |
|
403 | - public static function save( $post_id ) { |
|
399 | + * Save meta box data. |
|
400 | + * |
|
401 | + * @param int $post_id |
|
402 | + */ |
|
403 | + public static function save( $post_id ) { |
|
404 | 404 | |
405 | 405 | // Prepare the discount. |
406 | 406 | $discount = new WPInv_Discount( $post_id ); |
407 | 407 | |
408 | 408 | // Load new data. |
409 | 409 | $discount->set_props( |
410 | - array( |
|
411 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | - 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
410 | + array( |
|
411 | + 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | + 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | + 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | + 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | + 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
416 | 416 | 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
417 | - 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
418 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
417 | + 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
418 | + 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | + 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
420 | 420 | 'required_items' => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(), |
421 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | - ) |
|
421 | + 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | + 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | + 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
424 | + ) |
|
425 | 425 | ); |
426 | 426 | |
427 | - $discount->save(); |
|
428 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | - } |
|
427 | + $discount->save(); |
|
428 | + do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
429 | + } |
|
430 | 430 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,24 +21,24 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the discount. |
27 | - $discount = new WPInv_Discount( $post ); |
|
27 | + $discount = new WPInv_Discount($post); |
|
28 | 28 | |
29 | 29 | // Nonce field. |
30 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
30 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
31 | 31 | |
32 | - do_action( 'wpinv_discount_form_top', $discount ); |
|
32 | + do_action('wpinv_discount_form_top', $discount); |
|
33 | 33 | |
34 | 34 | // Set the currency position. |
35 | 35 | $position = wpinv_currency_position(); |
36 | 36 | |
37 | - if ( $position == 'left_space' ) { |
|
37 | + if ($position == 'left_space') { |
|
38 | 38 | $position = 'left'; |
39 | 39 | } |
40 | 40 | |
41 | - if ( $position == 'right_space' ) { |
|
41 | + if ($position == 'right_space') { |
|
42 | 42 | $position = 'right'; |
43 | 43 | } |
44 | 44 | |
@@ -52,66 +52,66 @@ discard block |
||
52 | 52 | </style> |
53 | 53 | <div class='bsui' style='max-width: 600px;padding-top: 10px;'> |
54 | 54 | |
55 | - <?php do_action( 'wpinv_discount_form_first', $discount ); ?> |
|
55 | + <?php do_action('wpinv_discount_form_first', $discount); ?> |
|
56 | 56 | |
57 | - <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?> |
|
57 | + <?php do_action('wpinv_discount_form_before_code', $discount); ?> |
|
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_discount_code" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Discount Code', 'invoicing' );?> |
|
60 | + <?php _e('Discount Code', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <div class="row"> |
64 | 64 | <div class="col-sm-12 form-group"> |
65 | - <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
65 | + <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" /> |
|
66 | 66 | </div> |
67 | 67 | <div class="col-sm-12"> |
68 | 68 | <?php |
69 | - do_action( 'wpinv_discount_form_before_single_use', $discount ); |
|
69 | + do_action('wpinv_discount_form_before_single_use', $discount); |
|
70 | 70 | |
71 | 71 | echo aui()->input( |
72 | 72 | array( |
73 | 73 | 'id' => 'wpinv_discount_single_use', |
74 | 74 | 'name' => 'wpinv_discount_single_use', |
75 | 75 | 'type' => 'checkbox', |
76 | - 'label' => __( 'Each customer can only use this discount once', 'invoicing' ), |
|
76 | + 'label' => __('Each customer can only use this discount once', 'invoicing'), |
|
77 | 77 | 'value' => '1', |
78 | 78 | 'checked' => $discount->is_single_use(), |
79 | 79 | ) |
80 | 80 | ); |
81 | 81 | |
82 | - do_action( 'wpinv_discount_form_single_use', $discount ); |
|
82 | + do_action('wpinv_discount_form_single_use', $discount); |
|
83 | 83 | ?> |
84 | 84 | </div> |
85 | 85 | <div class="col-sm-12"> |
86 | 86 | <?php |
87 | - do_action( 'wpinv_discount_form_before_recurring', $discount ); |
|
87 | + do_action('wpinv_discount_form_before_recurring', $discount); |
|
88 | 88 | |
89 | 89 | echo aui()->input( |
90 | 90 | array( |
91 | 91 | 'id' => 'wpinv_discount_recurring', |
92 | 92 | 'name' => 'wpinv_discount_recurring', |
93 | 93 | 'type' => 'checkbox', |
94 | - 'label' => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ), |
|
94 | + 'label' => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'), |
|
95 | 95 | 'value' => '1', |
96 | 96 | 'checked' => $discount->is_recurring(), |
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | |
100 | - do_action( 'wpinv_discount_form_recurring', $discount ); |
|
100 | + do_action('wpinv_discount_form_recurring', $discount); |
|
101 | 101 | ?> |
102 | 102 | </div> |
103 | 103 | </div> |
104 | 104 | </div> |
105 | 105 | <div class="col-sm-1 pt-2 pl-0"> |
106 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span> |
|
106 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span> |
|
107 | 107 | </div> |
108 | 108 | </div> |
109 | - <?php do_action( 'wpinv_discount_form_code', $discount ); ?> |
|
109 | + <?php do_action('wpinv_discount_form_code', $discount); ?> |
|
110 | 110 | |
111 | - <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?> |
|
111 | + <?php do_action('wpinv_discount_form_before_type', $discount); ?> |
|
112 | 112 | <div class="form-group row"> |
113 | 113 | <label for="wpinv_discount_type" class="col-sm-3 col-form-label"> |
114 | - <?php _e( 'Discount Type', 'invoicing' );?> |
|
114 | + <?php _e('Discount Type', 'invoicing'); ?> |
|
115 | 115 | </label> |
116 | 116 | <div class="col-sm-8"> |
117 | 117 | <?php |
@@ -119,9 +119,9 @@ discard block |
||
119 | 119 | array( |
120 | 120 | 'id' => 'wpinv_discount_type', |
121 | 121 | 'name' => 'wpinv_discount_type', |
122 | - 'label' => __( 'Discount Type', 'invoicing' ), |
|
123 | - 'placeholder' => __( 'Select Discount Type', 'invoicing' ), |
|
124 | - 'value' => $discount->get_type( 'edit' ), |
|
122 | + 'label' => __('Discount Type', 'invoicing'), |
|
123 | + 'placeholder' => __('Select Discount Type', 'invoicing'), |
|
124 | + 'value' => $discount->get_type('edit'), |
|
125 | 125 | 'select2' => true, |
126 | 126 | 'data-allow-clear' => 'false', |
127 | 127 | 'options' => wpinv_get_discount_types() |
@@ -130,19 +130,19 @@ discard block |
||
130 | 130 | ?> |
131 | 131 | </div> |
132 | 132 | <div class="col-sm-1 pt-2 pl-0"> |
133 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span> |
|
133 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span> |
|
134 | 134 | </div> |
135 | 135 | </div> |
136 | - <?php do_action( 'wpinv_discount_form_type', $discount ); ?> |
|
136 | + <?php do_action('wpinv_discount_form_type', $discount); ?> |
|
137 | 137 | |
138 | - <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?> |
|
139 | - <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap"> |
|
138 | + <?php do_action('wpinv_discount_form_before_amount', $discount); ?> |
|
139 | + <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap"> |
|
140 | 140 | <label for="wpinv_discount_amount" class="col-sm-3 col-form-label"> |
141 | - <?php _e( 'Discount Amount', 'invoicing' );?> |
|
141 | + <?php _e('Discount Amount', 'invoicing'); ?> |
|
142 | 142 | </label> |
143 | 143 | <div class="col-sm-8"> |
144 | 144 | <div class="input-group input-group-sm"> |
145 | - <?php if( 'left' == $position ) : ?> |
|
145 | + <?php if ('left' == $position) : ?> |
|
146 | 146 | <div class="input-group-prepend left wpinv-if-flat"> |
147 | 147 | <span class="input-group-text"> |
148 | 148 | <?php echo wpinv_currency_symbol(); ?> |
@@ -150,9 +150,9 @@ discard block |
||
150 | 150 | </div> |
151 | 151 | <?php endif; ?> |
152 | 152 | |
153 | - <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control"> |
|
153 | + <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control"> |
|
154 | 154 | |
155 | - <?php if( 'right' == $position ) : ?> |
|
155 | + <?php if ('right' == $position) : ?> |
|
156 | 156 | <div class="input-group-prepend left wpinv-if-flat"> |
157 | 157 | <span class="input-group-text"> |
158 | 158 | <?php echo wpinv_currency_symbol(); ?> |
@@ -165,15 +165,15 @@ discard block |
||
165 | 165 | </div> |
166 | 166 | </div> |
167 | 167 | <div class="col-sm-1 pt-2 pl-0"> |
168 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span> |
|
168 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span> |
|
169 | 169 | </div> |
170 | 170 | </div> |
171 | - <?php do_action( 'wpinv_discount_form_amount', $discount ); ?> |
|
171 | + <?php do_action('wpinv_discount_form_amount', $discount); ?> |
|
172 | 172 | |
173 | - <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?> |
|
173 | + <?php do_action('wpinv_discount_form_before_items', $discount); ?> |
|
174 | 174 | <div class="form-group row"> |
175 | 175 | <label for="wpinv_discount_items" class="col-sm-3 col-form-label"> |
176 | - <?php _e( 'Items', 'invoicing' );?> |
|
176 | + <?php _e('Items', 'invoicing'); ?> |
|
177 | 177 | </label> |
178 | 178 | <div class="col-sm-8"> |
179 | 179 | <?php |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | array( |
182 | 182 | 'id' => 'wpinv_discount_items', |
183 | 183 | 'name' => 'wpinv_discount_items[]', |
184 | - 'label' => __( 'Items', 'invoicing' ), |
|
185 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
186 | - 'value' => $discount->get_items( 'edit' ), |
|
184 | + 'label' => __('Items', 'invoicing'), |
|
185 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
186 | + 'value' => $discount->get_items('edit'), |
|
187 | 187 | 'select2' => true, |
188 | 188 | 'multiple' => true, |
189 | 189 | 'data-allow-clear' => 'false', |
@@ -193,15 +193,15 @@ discard block |
||
193 | 193 | ?> |
194 | 194 | </div> |
195 | 195 | <div class="col-sm-1 pt-2 pl-0"> |
196 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span> |
|
196 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span> |
|
197 | 197 | </div> |
198 | 198 | </div> |
199 | - <?php do_action( 'wpinv_discount_form_items', $discount ); ?> |
|
199 | + <?php do_action('wpinv_discount_form_items', $discount); ?> |
|
200 | 200 | |
201 | - <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?> |
|
201 | + <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?> |
|
202 | 202 | <div class="form-group row"> |
203 | 203 | <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label"> |
204 | - <?php _e( 'Excluded Items', 'invoicing' );?> |
|
204 | + <?php _e('Excluded Items', 'invoicing'); ?> |
|
205 | 205 | </label> |
206 | 206 | <div class="col-sm-8"> |
207 | 207 | <?php |
@@ -209,9 +209,9 @@ discard block |
||
209 | 209 | array( |
210 | 210 | 'id' => 'wpinv_discount_excluded_items', |
211 | 211 | 'name' => 'wpinv_discount_excluded_items[]', |
212 | - 'label' => __( 'Excluded Items', 'invoicing' ), |
|
213 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
214 | - 'value' => $discount->get_excluded_items( 'edit' ), |
|
212 | + 'label' => __('Excluded Items', 'invoicing'), |
|
213 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
214 | + 'value' => $discount->get_excluded_items('edit'), |
|
215 | 215 | 'select2' => true, |
216 | 216 | 'multiple' => true, |
217 | 217 | 'data-allow-clear' => 'false', |
@@ -221,15 +221,15 @@ discard block |
||
221 | 221 | ?> |
222 | 222 | </div> |
223 | 223 | <div class="col-sm-1 pt-2 pl-0"> |
224 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span> |
|
224 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span> |
|
225 | 225 | </div> |
226 | 226 | </div> |
227 | - <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?> |
|
227 | + <?php do_action('wpinv_discount_form_excluded_items', $discount); ?> |
|
228 | 228 | |
229 | - <?php do_action( 'wpinv_discount_form_before_required_items', $discount ); ?> |
|
229 | + <?php do_action('wpinv_discount_form_before_required_items', $discount); ?> |
|
230 | 230 | <div class="form-group row"> |
231 | 231 | <label for="wpinv_discount_required_items" class="col-sm-3 col-form-label"> |
232 | - <?php _e( 'Required Items', 'invoicing' );?> |
|
232 | + <?php _e('Required Items', 'invoicing'); ?> |
|
233 | 233 | </label> |
234 | 234 | <div class="col-sm-8"> |
235 | 235 | <?php |
@@ -237,9 +237,9 @@ discard block |
||
237 | 237 | array( |
238 | 238 | 'id' => 'wpinv_discount_required_items', |
239 | 239 | 'name' => 'wpinv_discount_required_items[]', |
240 | - 'label' => __( 'Required Items', 'invoicing' ), |
|
241 | - 'placeholder' => __( 'Select Items', 'invoicing' ), |
|
242 | - 'value' => $discount->get_required_items( 'edit' ), |
|
240 | + 'label' => __('Required Items', 'invoicing'), |
|
241 | + 'placeholder' => __('Select Items', 'invoicing'), |
|
242 | + 'value' => $discount->get_required_items('edit'), |
|
243 | 243 | 'select2' => true, |
244 | 244 | 'multiple' => true, |
245 | 245 | 'data-allow-clear' => 'false', |
@@ -249,15 +249,15 @@ discard block |
||
249 | 249 | ?> |
250 | 250 | </div> |
251 | 251 | <div class="col-sm-1 pt-2 pl-0"> |
252 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are required to be in the cart before using this discount.', 'invoicing' ); ?>"></span> |
|
252 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are required to be in the cart before using this discount.', 'invoicing'); ?>"></span> |
|
253 | 253 | </div> |
254 | 254 | </div> |
255 | - <?php do_action( 'wpinv_discount_form_required_items', $discount ); ?> |
|
255 | + <?php do_action('wpinv_discount_form_required_items', $discount); ?> |
|
256 | 256 | |
257 | - <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?> |
|
257 | + <?php do_action('wpinv_discount_form_before_start', $discount); ?> |
|
258 | 258 | <div class="form-group row"> |
259 | 259 | <label for="wpinv_discount_start" class="col-sm-3 col-form-label"> |
260 | - <?php _e( 'Start Date', 'invoicing' );?> |
|
260 | + <?php _e('Start Date', 'invoicing'); ?> |
|
261 | 261 | </label> |
262 | 262 | <div class="col-sm-8"> |
263 | 263 | <?php |
@@ -266,10 +266,10 @@ discard block |
||
266 | 266 | 'type' => 'datepicker', |
267 | 267 | 'id' => 'wpinv_discount_start', |
268 | 268 | 'name' => 'wpinv_discount_start', |
269 | - 'label' => __( 'Start Date', 'invoicing' ), |
|
269 | + 'label' => __('Start Date', 'invoicing'), |
|
270 | 270 | 'placeholder' => 'YYYY-MM-DD 00:00', |
271 | 271 | 'class' => 'form-control-sm', |
272 | - 'value' => $discount->get_start_date( 'edit' ), |
|
272 | + 'value' => $discount->get_start_date('edit'), |
|
273 | 273 | 'extra_attributes' => array( |
274 | 274 | 'data-enable-time' => 'true', |
275 | 275 | 'data-time_24hr' => 'true', |
@@ -280,15 +280,15 @@ discard block |
||
280 | 280 | ?> |
281 | 281 | </div> |
282 | 282 | <div class="col-sm-1 pt-2 pl-0"> |
283 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span> |
|
283 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span> |
|
284 | 284 | </div> |
285 | 285 | </div> |
286 | - <?php do_action( 'wpinv_discount_form_start', $discount ); ?> |
|
286 | + <?php do_action('wpinv_discount_form_start', $discount); ?> |
|
287 | 287 | |
288 | - <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?> |
|
288 | + <?php do_action('wpinv_discount_form_before_expiration', $discount); ?> |
|
289 | 289 | <div class="form-group row"> |
290 | 290 | <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label"> |
291 | - <?php _e( 'Expiration Date', 'invoicing' );?> |
|
291 | + <?php _e('Expiration Date', 'invoicing'); ?> |
|
292 | 292 | </label> |
293 | 293 | <div class="col-sm-8"> |
294 | 294 | <?php |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | 'type' => 'datepicker', |
298 | 298 | 'id' => 'wpinv_discount_expiration', |
299 | 299 | 'name' => 'wpinv_discount_expiration', |
300 | - 'label' => __( 'Expiration Date', 'invoicing' ), |
|
300 | + 'label' => __('Expiration Date', 'invoicing'), |
|
301 | 301 | 'placeholder' => 'YYYY-MM-DD 00:00', |
302 | 302 | 'class' => 'form-control-sm', |
303 | - 'value' => $discount->get_end_date( 'edit' ), |
|
303 | + 'value' => $discount->get_end_date('edit'), |
|
304 | 304 | 'extra_attributes' => array( |
305 | 305 | 'data-enable-time' => 'true', |
306 | 306 | 'data-time_24hr' => 'true', |
@@ -313,27 +313,27 @@ discard block |
||
313 | 313 | ?> |
314 | 314 | </div> |
315 | 315 | <div class="col-sm-1 pt-2 pl-0"> |
316 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span> |
|
316 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span> |
|
317 | 317 | </div> |
318 | 318 | </div> |
319 | - <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?> |
|
319 | + <?php do_action('wpinv_discount_form_expiration', $discount); ?> |
|
320 | 320 | |
321 | - <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?> |
|
321 | + <?php do_action('wpinv_discount_form_before_min_total', $discount); ?> |
|
322 | 322 | <div class="form-group row"> |
323 | 323 | <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label"> |
324 | - <?php _e( 'Minimum Amount', 'invoicing' );?> |
|
324 | + <?php _e('Minimum Amount', 'invoicing'); ?> |
|
325 | 325 | </label> |
326 | 326 | <div class="col-sm-8"> |
327 | 327 | <div class="input-group input-group-sm"> |
328 | - <?php if( 'left' == $position ) : ?> |
|
328 | + <?php if ('left' == $position) : ?> |
|
329 | 329 | <div class="input-group-prepend"> |
330 | 330 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
331 | 331 | </div> |
332 | 332 | <?php endif; ?> |
333 | 333 | |
334 | - <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control"> |
|
334 | + <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control"> |
|
335 | 335 | |
336 | - <?php if( 'left' != $position ) : ?> |
|
336 | + <?php if ('left' != $position) : ?> |
|
337 | 337 | <div class="input-group-append"> |
338 | 338 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
339 | 339 | </div> |
@@ -341,27 +341,27 @@ discard block |
||
341 | 341 | </div> |
342 | 342 | </div> |
343 | 343 | <div class="col-sm-1 pt-2 pl-0"> |
344 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span> |
|
344 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span> |
|
345 | 345 | </div> |
346 | 346 | </div> |
347 | - <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?> |
|
347 | + <?php do_action('wpinv_discount_form_min_total', $discount); ?> |
|
348 | 348 | |
349 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
349 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
350 | 350 | <div class="form-group row"> |
351 | 351 | <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label"> |
352 | - <?php _e( 'Maximum Amount', 'invoicing' );?> |
|
352 | + <?php _e('Maximum Amount', 'invoicing'); ?> |
|
353 | 353 | </label> |
354 | 354 | <div class="col-sm-8"> |
355 | 355 | <div class="input-group input-group-sm"> |
356 | - <?php if( 'left' == $position ) : ?> |
|
356 | + <?php if ('left' == $position) : ?> |
|
357 | 357 | <div class="input-group-prepend"> |
358 | 358 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
359 | 359 | </div> |
360 | 360 | <?php endif; ?> |
361 | 361 | |
362 | - <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control"> |
|
362 | + <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control"> |
|
363 | 363 | |
364 | - <?php if( 'left' != $position ) : ?> |
|
364 | + <?php if ('left' != $position) : ?> |
|
365 | 365 | <div class="input-group-append"> |
366 | 366 | <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span> |
367 | 367 | </div> |
@@ -369,30 +369,30 @@ discard block |
||
369 | 369 | </div> |
370 | 370 | </div> |
371 | 371 | <div class="col-sm-1 pt-2 pl-0"> |
372 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span> |
|
372 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span> |
|
373 | 373 | </div> |
374 | 374 | </div> |
375 | - <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?> |
|
375 | + <?php do_action('wpinv_discount_form_before_max_total', $discount); ?> |
|
376 | 376 | |
377 | - <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?> |
|
377 | + <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?> |
|
378 | 378 | <div class="form-group row"> |
379 | 379 | <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label"> |
380 | - <?php _e( 'Maximum Uses', 'invoicing' );?> |
|
380 | + <?php _e('Maximum Uses', 'invoicing'); ?> |
|
381 | 381 | </label> |
382 | 382 | <div class="col-sm-8"> |
383 | - <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
383 | + <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" /> |
|
384 | 384 | </div> |
385 | 385 | <div class="col-sm-1 pt-2 pl-0"> |
386 | - <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span> |
|
386 | + <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span> |
|
387 | 387 | </div> |
388 | 388 | </div> |
389 | - <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?> |
|
389 | + <?php do_action('wpinv_discount_form_max_uses', $discount); ?> |
|
390 | 390 | |
391 | - <?php do_action( 'wpinv_discount_form_last', $discount ); ?> |
|
391 | + <?php do_action('wpinv_discount_form_last', $discount); ?> |
|
392 | 392 | |
393 | 393 | </div> |
394 | 394 | <?php |
395 | - do_action( 'wpinv_discount_form_bottom', $post ); |
|
395 | + do_action('wpinv_discount_form_bottom', $post); |
|
396 | 396 | } |
397 | 397 | |
398 | 398 | /** |
@@ -400,31 +400,31 @@ discard block |
||
400 | 400 | * |
401 | 401 | * @param int $post_id |
402 | 402 | */ |
403 | - public static function save( $post_id ) { |
|
403 | + public static function save($post_id) { |
|
404 | 404 | |
405 | 405 | // Prepare the discount. |
406 | - $discount = new WPInv_Discount( $post_id ); |
|
406 | + $discount = new WPInv_Discount($post_id); |
|
407 | 407 | |
408 | 408 | // Load new data. |
409 | 409 | $discount->set_props( |
410 | 410 | array( |
411 | - 'code' => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null, |
|
412 | - 'amount' => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null, |
|
413 | - 'start' => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null, |
|
414 | - 'expiration' => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null, |
|
415 | - 'is_single_use' => ! empty( $_POST['wpinv_discount_single_use'] ), |
|
416 | - 'type' => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null, |
|
417 | - 'is_recurring' => ! empty( $_POST['wpinv_discount_recurring'] ), |
|
418 | - 'items' => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(), |
|
419 | - 'excluded_items' => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(), |
|
420 | - 'required_items' => isset( $_POST['wpinv_discount_required_items'] ) ? wpinv_clean( $_POST['wpinv_discount_required_items'] ) : array(), |
|
421 | - 'max_uses' => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null, |
|
422 | - 'min_total' => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null, |
|
423 | - 'max_total' => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null, |
|
411 | + 'code' => isset($_POST['wpinv_discount_code']) ? wpinv_clean($_POST['wpinv_discount_code']) : null, |
|
412 | + 'amount' => isset($_POST['wpinv_discount_amount']) ? floatval($_POST['wpinv_discount_amount']) : null, |
|
413 | + 'start' => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null, |
|
414 | + 'expiration' => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null, |
|
415 | + 'is_single_use' => !empty($_POST['wpinv_discount_single_use']), |
|
416 | + 'type' => isset($_POST['wpinv_discount_type']) ? wpinv_clean($_POST['wpinv_discount_type']) : null, |
|
417 | + 'is_recurring' => !empty($_POST['wpinv_discount_recurring']), |
|
418 | + 'items' => isset($_POST['wpinv_discount_items']) ? wpinv_clean($_POST['wpinv_discount_items']) : array(), |
|
419 | + 'excluded_items' => isset($_POST['wpinv_discount_excluded_items']) ? wpinv_clean($_POST['wpinv_discount_excluded_items']) : array(), |
|
420 | + 'required_items' => isset($_POST['wpinv_discount_required_items']) ? wpinv_clean($_POST['wpinv_discount_required_items']) : array(), |
|
421 | + 'max_uses' => isset($_POST['wpinv_discount_max_uses']) ? intval($_POST['wpinv_discount_max_uses']) : null, |
|
422 | + 'min_total' => isset($_POST['wpinv_discount_min_total']) ? floatval($_POST['wpinv_discount_min_total']) : null, |
|
423 | + 'max_total' => isset($_POST['wpinv_discount_max_total']) ? floatval($_POST['wpinv_discount_max_total']) : null, |
|
424 | 424 | ) |
425 | 425 | ); |
426 | 426 | |
427 | 427 | $discount->save(); |
428 | - do_action( 'getpaid_discount_metabox_save', $post_id, $discount ); |
|
428 | + do_action('getpaid_discount_metabox_save', $post_id, $discount); |
|
429 | 429 | } |
430 | 430 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Invoice_Address { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the invoice. |
@@ -366,18 +366,18 @@ discard block |
||
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
369 | - * Save meta box data. |
|
370 | - * |
|
371 | - * @param int $post_id |
|
372 | - */ |
|
373 | - public static function save( $post_id ) { |
|
369 | + * Save meta box data. |
|
370 | + * |
|
371 | + * @param int $post_id |
|
372 | + */ |
|
373 | + public static function save( $post_id ) { |
|
374 | 374 | |
375 | 375 | // Prepare the invoice. |
376 | 376 | $invoice = new WPInv_Invoice( $post_id ); |
377 | 377 | |
378 | 378 | // Load new data. |
379 | 379 | $invoice->set_props( |
380 | - array( |
|
380 | + array( |
|
381 | 381 | 'template' => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null, |
382 | 382 | 'email_cc' => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null, |
383 | 383 | 'disable_taxes' => ! empty( $_POST['disable_taxes'] ), |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | 'due_date' => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null, |
401 | 401 | 'number' => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null, |
402 | 402 | 'status' => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null, |
403 | - ) |
|
403 | + ) |
|
404 | 404 | ); |
405 | 405 | |
406 | 406 | // Discount code. |
@@ -465,6 +465,6 @@ discard block |
||
465 | 465 | } |
466 | 466 | |
467 | 467 | // Fires after an invoice is saved. |
468 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
469 | - } |
|
468 | + do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
469 | + } |
|
470 | 470 | } |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,14 +21,14 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the invoice. |
27 | - $invoice = new WPInv_Invoice( $post ); |
|
28 | - $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id(); |
|
29 | - $customer = new WP_User( $customer ); |
|
30 | - $display = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ); |
|
31 | - wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' ); |
|
27 | + $invoice = new WPInv_Invoice($post); |
|
28 | + $customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id(); |
|
29 | + $customer = new WP_User($customer); |
|
30 | + $display = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email); |
|
31 | + wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce'); |
|
32 | 32 | |
33 | 33 | ?> |
34 | 34 | |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | <div class="col-12 col-sm-6"> |
44 | 44 | <div id="getpaid-invoice-user-id-wrapper" class="form-group"> |
45 | 45 | <div> |
46 | - <label for="post_author_override"><?php _e( 'Customer', 'invoicing' );?></label> |
|
46 | + <label for="post_author_override"><?php _e('Customer', 'invoicing'); ?></label> |
|
47 | 47 | </div> |
48 | 48 | <div> |
49 | - <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>"> |
|
50 | - <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html( $display ); ?> </option>) |
|
49 | + <select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>"> |
|
50 | + <option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html($display); ?> </option>) |
|
51 | 51 | </select> |
52 | 52 | </div> |
53 | 53 | </div> |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | 'type' => 'text', |
61 | 61 | 'id' => 'getpaid-invoice-new-user-email', |
62 | 62 | 'name' => 'wpinv_email', |
63 | - 'label' => __( 'Email', 'invoicing' ) . '<span class="required">*</span>', |
|
63 | + 'label' => __('Email', 'invoicing') . '<span class="required">*</span>', |
|
64 | 64 | 'label_type' => 'vertical', |
65 | 65 | 'placeholder' => '[email protected]', |
66 | 66 | 'class' => 'form-control-sm', |
@@ -70,18 +70,18 @@ discard block |
||
70 | 70 | </div> |
71 | 71 | </div> |
72 | 72 | <div class="col-12 col-sm-6 form-group mt-sm-4"> |
73 | - <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?> |
|
73 | + <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?> |
|
74 | 74 | <a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)"> |
75 | 75 | <i aria-hidden="true" class="fa fa-refresh"></i> |
76 | - <?php _e( 'Fill User Details', 'invoicing' );?> |
|
76 | + <?php _e('Fill User Details', 'invoicing'); ?> |
|
77 | 77 | </a> |
78 | 78 | <a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)"> |
79 | 79 | <i aria-hidden="true" class="fa fa-plus"></i> |
80 | - <?php _e( 'Add New User', 'invoicing' );?> |
|
80 | + <?php _e('Add New User', 'invoicing'); ?> |
|
81 | 81 | </a> |
82 | 82 | <a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)"> |
83 | 83 | <i aria-hidden="true" class="fa fa-close"></i> |
84 | - <?php _e( 'Cancel', 'invoicing' );?> |
|
84 | + <?php _e('Cancel', 'invoicing'); ?> |
|
85 | 85 | </a> |
86 | 86 | <?php endif; ?> |
87 | 87 | </div> |
@@ -94,11 +94,11 @@ discard block |
||
94 | 94 | 'type' => 'text', |
95 | 95 | 'id' => 'wpinv_first_name', |
96 | 96 | 'name' => 'wpinv_first_name', |
97 | - 'label' => __( 'First Name', 'invoicing' ), |
|
97 | + 'label' => __('First Name', 'invoicing'), |
|
98 | 98 | 'label_type' => 'vertical', |
99 | 99 | 'placeholder' => '', |
100 | 100 | 'class' => 'form-control-sm', |
101 | - 'value' => $invoice->get_first_name( 'edit' ), |
|
101 | + 'value' => $invoice->get_first_name('edit'), |
|
102 | 102 | ) |
103 | 103 | ); |
104 | 104 | ?> |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | 'type' => 'text', |
111 | 111 | 'id' => 'wpinv_last_name', |
112 | 112 | 'name' => 'wpinv_last_name', |
113 | - 'label' => __( 'Last Name', 'invoicing' ), |
|
113 | + 'label' => __('Last Name', 'invoicing'), |
|
114 | 114 | 'label_type' => 'vertical', |
115 | 115 | 'placeholder' => '', |
116 | 116 | 'class' => 'form-control-sm', |
117 | - 'value' => $invoice->get_last_name( 'edit' ), |
|
117 | + 'value' => $invoice->get_last_name('edit'), |
|
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | ?> |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | 'type' => 'text', |
130 | 130 | 'id' => 'wpinv_company', |
131 | 131 | 'name' => 'wpinv_company', |
132 | - 'label' => __( 'Company', 'invoicing' ), |
|
132 | + 'label' => __('Company', 'invoicing'), |
|
133 | 133 | 'label_type' => 'vertical', |
134 | 134 | 'placeholder' => '', |
135 | 135 | 'class' => 'form-control-sm', |
136 | - 'value' => $invoice->get_company( 'edit' ), |
|
136 | + 'value' => $invoice->get_company('edit'), |
|
137 | 137 | ) |
138 | 138 | ); |
139 | 139 | ?> |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | 'type' => 'text', |
146 | 146 | 'id' => 'wpinv_vat_number', |
147 | 147 | 'name' => 'wpinv_vat_number', |
148 | - 'label' => __( 'Vat Number', 'invoicing' ), |
|
148 | + 'label' => __('Vat Number', 'invoicing'), |
|
149 | 149 | 'label_type' => 'vertical', |
150 | 150 | 'placeholder' => '', |
151 | 151 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
152 | - 'value' => $invoice->get_vat_number( 'edit' ), |
|
152 | + 'value' => $invoice->get_vat_number('edit'), |
|
153 | 153 | ) |
154 | 154 | ); |
155 | 155 | ?> |
@@ -164,11 +164,11 @@ discard block |
||
164 | 164 | 'type' => 'text', |
165 | 165 | 'id' => 'wpinv_address', |
166 | 166 | 'name' => 'wpinv_address', |
167 | - 'label' => __( 'Address', 'invoicing' ), |
|
167 | + 'label' => __('Address', 'invoicing'), |
|
168 | 168 | 'label_type' => 'vertical', |
169 | 169 | 'placeholder' => '', |
170 | 170 | 'class' => 'form-control-sm', |
171 | - 'value' => $invoice->get_address( 'edit' ), |
|
171 | + 'value' => $invoice->get_address('edit'), |
|
172 | 172 | ) |
173 | 173 | ); |
174 | 174 | ?> |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | 'type' => 'text', |
181 | 181 | 'id' => 'wpinv_city', |
182 | 182 | 'name' => 'wpinv_city', |
183 | - 'label' => __( 'City', 'invoicing' ), |
|
183 | + 'label' => __('City', 'invoicing'), |
|
184 | 184 | 'label_type' => 'vertical', |
185 | 185 | 'placeholder' => '', |
186 | 186 | 'class' => 'form-control-sm', |
187 | - 'value' => $invoice->get_city( 'edit' ), |
|
187 | + 'value' => $invoice->get_city('edit'), |
|
188 | 188 | ) |
189 | 189 | ); |
190 | 190 | ?> |
@@ -198,11 +198,11 @@ discard block |
||
198 | 198 | array( |
199 | 199 | 'id' => 'wpinv_country', |
200 | 200 | 'name' => 'wpinv_country', |
201 | - 'label' => __( 'Country', 'invoicing' ), |
|
201 | + 'label' => __('Country', 'invoicing'), |
|
202 | 202 | 'label_type' => 'vertical', |
203 | - 'placeholder' => __( 'Choose a country', 'invoicing' ), |
|
203 | + 'placeholder' => __('Choose a country', 'invoicing'), |
|
204 | 204 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
205 | - 'value' => $invoice->get_country( 'edit' ), |
|
205 | + 'value' => $invoice->get_country('edit'), |
|
206 | 206 | 'options' => wpinv_get_country_list(), |
207 | 207 | 'data-allow-clear' => 'false', |
208 | 208 | 'select2' => true, |
@@ -213,20 +213,20 @@ discard block |
||
213 | 213 | <div class="col-12 col-sm-6"> |
214 | 214 | <?php |
215 | 215 | |
216 | - $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) ); |
|
216 | + $states = wpinv_get_country_states($invoice->get_country('edit')); |
|
217 | 217 | |
218 | - if ( empty( $states ) ) { |
|
218 | + if (empty($states)) { |
|
219 | 219 | |
220 | 220 | echo aui()->input( |
221 | 221 | array( |
222 | 222 | 'type' => 'text', |
223 | 223 | 'id' => 'wpinv_state', |
224 | 224 | 'name' => 'wpinv_state', |
225 | - 'label' => __( 'State', 'invoicing' ), |
|
225 | + 'label' => __('State', 'invoicing'), |
|
226 | 226 | 'label_type' => 'vertical', |
227 | 227 | 'placeholder' => '', |
228 | 228 | 'class' => 'form-control-sm', |
229 | - 'value' => $invoice->get_state( 'edit' ), |
|
229 | + 'value' => $invoice->get_state('edit'), |
|
230 | 230 | ) |
231 | 231 | ); |
232 | 232 | |
@@ -236,11 +236,11 @@ discard block |
||
236 | 236 | array( |
237 | 237 | 'id' => 'wpinv_state', |
238 | 238 | 'name' => 'wpinv_state', |
239 | - 'label' => __( 'State', 'invoicing' ), |
|
239 | + 'label' => __('State', 'invoicing'), |
|
240 | 240 | 'label_type' => 'vertical', |
241 | - 'placeholder' => __( 'Select a state', 'invoicing' ), |
|
241 | + 'placeholder' => __('Select a state', 'invoicing'), |
|
242 | 242 | 'class' => 'form-control-sm', |
243 | - 'value' => $invoice->get_state( 'edit' ), |
|
243 | + 'value' => $invoice->get_state('edit'), |
|
244 | 244 | 'options' => $states, |
245 | 245 | 'data-allow-clear' => 'false', |
246 | 246 | 'select2' => true, |
@@ -261,11 +261,11 @@ discard block |
||
261 | 261 | 'type' => 'text', |
262 | 262 | 'id' => 'wpinv_zip', |
263 | 263 | 'name' => 'wpinv_zip', |
264 | - 'label' => __( 'Zip / Postal Code', 'invoicing' ), |
|
264 | + 'label' => __('Zip / Postal Code', 'invoicing'), |
|
265 | 265 | 'label_type' => 'vertical', |
266 | 266 | 'placeholder' => '', |
267 | 267 | 'class' => 'form-control-sm', |
268 | - 'value' => $invoice->get_zip( 'edit' ), |
|
268 | + 'value' => $invoice->get_zip('edit'), |
|
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | ?> |
@@ -277,19 +277,19 @@ discard block |
||
277 | 277 | 'type' => 'text', |
278 | 278 | 'id' => 'wpinv_phone', |
279 | 279 | 'name' => 'wpinv_phone', |
280 | - 'label' => __( 'Phone', 'invoicing' ), |
|
280 | + 'label' => __('Phone', 'invoicing'), |
|
281 | 281 | 'label_type' => 'vertical', |
282 | 282 | 'placeholder' => '', |
283 | 283 | 'class' => 'form-control-sm', |
284 | - 'value' => $invoice->get_phone( 'edit' ), |
|
284 | + 'value' => $invoice->get_phone('edit'), |
|
285 | 285 | ) |
286 | 286 | ); |
287 | 287 | ?> |
288 | 288 | </div> |
289 | 289 | </div> |
290 | 290 | |
291 | - <?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?> |
|
292 | - <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?> |
|
291 | + <?php if (!apply_filters('getpaid_use_new_invoice_items_metabox', false)) : ?> |
|
292 | + <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?> |
|
293 | 293 | |
294 | 294 | <div class="row"> |
295 | 295 | <div class="col-12 col-sm-6"> |
@@ -298,14 +298,14 @@ discard block |
||
298 | 298 | array( |
299 | 299 | 'id' => 'wpinv_template', |
300 | 300 | 'name' => 'wpinv_template', |
301 | - 'label' => __( 'Template', 'invoicing' ), |
|
301 | + 'label' => __('Template', 'invoicing'), |
|
302 | 302 | 'label_type' => 'vertical', |
303 | - 'placeholder' => __( 'Choose a template', 'invoicing' ), |
|
303 | + 'placeholder' => __('Choose a template', 'invoicing'), |
|
304 | 304 | 'class' => 'form-control-sm', |
305 | - 'value' => $invoice->get_template( 'edit' ), |
|
305 | + 'value' => $invoice->get_template('edit'), |
|
306 | 306 | 'options' => array( |
307 | - 'quantity' => __( 'Quantity', 'invoicing' ), |
|
308 | - 'hours' => __( 'Hours', 'invoicing' ), |
|
307 | + 'quantity' => __('Quantity', 'invoicing'), |
|
308 | + 'hours' => __('Hours', 'invoicing'), |
|
309 | 309 | //'amount' => __( 'Amount Only', 'invoicing' ), |
310 | 310 | ), |
311 | 311 | 'data-allow-clear' => 'false', |
@@ -322,11 +322,11 @@ discard block |
||
322 | 322 | array( |
323 | 323 | 'id' => 'wpinv_currency', |
324 | 324 | 'name' => 'wpinv_currency', |
325 | - 'label' => __( 'Currency', 'invoicing' ), |
|
325 | + 'label' => __('Currency', 'invoicing'), |
|
326 | 326 | 'label_type' => 'vertical', |
327 | - 'placeholder' => __( 'Select Invoice Currency', 'invoicing' ), |
|
327 | + 'placeholder' => __('Select Invoice Currency', 'invoicing'), |
|
328 | 328 | 'class' => 'form-control-sm getpaid-recalculate-prices-on-change', |
329 | - 'value' => $invoice->get_currency( 'edit' ), |
|
329 | + 'value' => $invoice->get_currency('edit'), |
|
330 | 330 | 'required' => false, |
331 | 331 | 'data-allow-clear' => 'false', |
332 | 332 | 'select2' => true, |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | </div> |
339 | 339 | </div> |
340 | 340 | |
341 | - <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?> |
|
341 | + <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?> |
|
342 | 342 | <?php endif; ?> |
343 | 343 | |
344 | 344 | <div class="row"> |
@@ -349,18 +349,18 @@ discard block |
||
349 | 349 | 'type' => 'text', |
350 | 350 | 'id' => 'wpinv_company_id', |
351 | 351 | 'name' => 'wpinv_company_id', |
352 | - 'label' => __( 'Company ID', 'invoicing' ), |
|
352 | + 'label' => __('Company ID', 'invoicing'), |
|
353 | 353 | 'label_type' => 'vertical', |
354 | 354 | 'placeholder' => '', |
355 | 355 | 'class' => 'form-control-sm', |
356 | - 'value' => $invoice->get_company_id( 'edit' ), |
|
356 | + 'value' => $invoice->get_company_id('edit'), |
|
357 | 357 | ) |
358 | 358 | ); |
359 | 359 | ?> |
360 | 360 | </div> |
361 | 361 | </div> |
362 | 362 | |
363 | - <?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?> |
|
363 | + <?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?> |
|
364 | 364 | </div> |
365 | 365 | <?php |
366 | 366 | } |
@@ -370,51 +370,51 @@ discard block |
||
370 | 370 | * |
371 | 371 | * @param int $post_id |
372 | 372 | */ |
373 | - public static function save( $post_id ) { |
|
373 | + public static function save($post_id) { |
|
374 | 374 | |
375 | 375 | // Prepare the invoice. |
376 | - $invoice = new WPInv_Invoice( $post_id ); |
|
376 | + $invoice = new WPInv_Invoice($post_id); |
|
377 | 377 | |
378 | 378 | // Load new data. |
379 | 379 | $invoice->set_props( |
380 | 380 | array( |
381 | - 'template' => isset( $_POST['wpinv_template'] ) ? wpinv_clean( $_POST['wpinv_template'] ) : null, |
|
382 | - 'email_cc' => isset( $_POST['wpinv_cc'] ) ? wpinv_clean( $_POST['wpinv_cc'] ) : null, |
|
383 | - 'disable_taxes' => ! empty( $_POST['disable_taxes'] ), |
|
384 | - 'currency' => isset( $_POST['wpinv_currency'] ) ? wpinv_clean( $_POST['wpinv_currency'] ) : null, |
|
385 | - 'gateway' => ( $invoice->needs_payment() && isset( $_POST['wpinv_gateway'] ) ) ? wpinv_clean( $_POST['wpinv_gateway'] ) : null, |
|
386 | - 'address' => isset( $_POST['wpinv_address'] ) ? wpinv_clean( $_POST['wpinv_address'] ) : null, |
|
387 | - 'vat_number' => isset( $_POST['wpinv_vat_number'] ) ? wpinv_clean( $_POST['wpinv_vat_number'] ) : null, |
|
388 | - 'company' => isset( $_POST['wpinv_company'] ) ? wpinv_clean( $_POST['wpinv_company'] ) : null, |
|
389 | - 'company_id' => isset( $_POST['wpinv_company_id'] ) ? wpinv_clean( $_POST['wpinv_company_id'] ) : null, |
|
390 | - 'zip' => isset( $_POST['wpinv_zip'] ) ? wpinv_clean( $_POST['wpinv_zip'] ) : null, |
|
391 | - 'state' => isset( $_POST['wpinv_state'] ) ? wpinv_clean( $_POST['wpinv_state'] ) : null, |
|
392 | - 'city' => isset( $_POST['wpinv_city'] ) ? wpinv_clean( $_POST['wpinv_city'] ) : null, |
|
393 | - 'country' => isset( $_POST['wpinv_country'] ) ? wpinv_clean( $_POST['wpinv_country'] ) : null, |
|
394 | - 'phone' => isset( $_POST['wpinv_phone'] ) ? wpinv_clean( $_POST['wpinv_phone'] ) : null, |
|
395 | - 'first_name' => isset( $_POST['wpinv_first_name'] ) ? wpinv_clean( $_POST['wpinv_first_name'] ) : null, |
|
396 | - 'last_name' => isset( $_POST['wpinv_last_name'] ) ? wpinv_clean( $_POST['wpinv_last_name'] ) : null, |
|
397 | - 'author' => isset( $_POST['post_author_override'] ) ? wpinv_clean( $_POST['post_author_override'] ) : null, |
|
398 | - 'date_created' => isset( $_POST['date_created'] ) ? wpinv_clean( $_POST['date_created'] ) : null, |
|
399 | - 'date_completed' => isset( $_POST['wpinv_date_completed'] ) ? wpinv_clean( $_POST['wpinv_date_completed'] ) : null, |
|
400 | - 'due_date' => isset( $_POST['wpinv_due_date'] ) ? wpinv_clean( $_POST['wpinv_due_date'] ) : null, |
|
401 | - 'number' => isset( $_POST['wpinv_number'] ) ? wpinv_clean( $_POST['wpinv_number'] ) : null, |
|
402 | - 'status' => isset( $_POST['wpinv_status'] ) ? wpinv_clean( $_POST['wpinv_status'] ) : null, |
|
381 | + 'template' => isset($_POST['wpinv_template']) ? wpinv_clean($_POST['wpinv_template']) : null, |
|
382 | + 'email_cc' => isset($_POST['wpinv_cc']) ? wpinv_clean($_POST['wpinv_cc']) : null, |
|
383 | + 'disable_taxes' => !empty($_POST['disable_taxes']), |
|
384 | + 'currency' => isset($_POST['wpinv_currency']) ? wpinv_clean($_POST['wpinv_currency']) : null, |
|
385 | + 'gateway' => ($invoice->needs_payment() && isset($_POST['wpinv_gateway'])) ? wpinv_clean($_POST['wpinv_gateway']) : null, |
|
386 | + 'address' => isset($_POST['wpinv_address']) ? wpinv_clean($_POST['wpinv_address']) : null, |
|
387 | + 'vat_number' => isset($_POST['wpinv_vat_number']) ? wpinv_clean($_POST['wpinv_vat_number']) : null, |
|
388 | + 'company' => isset($_POST['wpinv_company']) ? wpinv_clean($_POST['wpinv_company']) : null, |
|
389 | + 'company_id' => isset($_POST['wpinv_company_id']) ? wpinv_clean($_POST['wpinv_company_id']) : null, |
|
390 | + 'zip' => isset($_POST['wpinv_zip']) ? wpinv_clean($_POST['wpinv_zip']) : null, |
|
391 | + 'state' => isset($_POST['wpinv_state']) ? wpinv_clean($_POST['wpinv_state']) : null, |
|
392 | + 'city' => isset($_POST['wpinv_city']) ? wpinv_clean($_POST['wpinv_city']) : null, |
|
393 | + 'country' => isset($_POST['wpinv_country']) ? wpinv_clean($_POST['wpinv_country']) : null, |
|
394 | + 'phone' => isset($_POST['wpinv_phone']) ? wpinv_clean($_POST['wpinv_phone']) : null, |
|
395 | + 'first_name' => isset($_POST['wpinv_first_name']) ? wpinv_clean($_POST['wpinv_first_name']) : null, |
|
396 | + 'last_name' => isset($_POST['wpinv_last_name']) ? wpinv_clean($_POST['wpinv_last_name']) : null, |
|
397 | + 'author' => isset($_POST['post_author_override']) ? wpinv_clean($_POST['post_author_override']) : null, |
|
398 | + 'date_created' => isset($_POST['date_created']) ? wpinv_clean($_POST['date_created']) : null, |
|
399 | + 'date_completed' => isset($_POST['wpinv_date_completed']) ? wpinv_clean($_POST['wpinv_date_completed']) : null, |
|
400 | + 'due_date' => isset($_POST['wpinv_due_date']) ? wpinv_clean($_POST['wpinv_due_date']) : null, |
|
401 | + 'number' => isset($_POST['wpinv_number']) ? wpinv_clean($_POST['wpinv_number']) : null, |
|
402 | + 'status' => isset($_POST['wpinv_status']) ? wpinv_clean($_POST['wpinv_status']) : null, |
|
403 | 403 | ) |
404 | 404 | ); |
405 | 405 | |
406 | 406 | // Discount code. |
407 | - if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) { |
|
407 | + if (!$invoice->is_paid() && !$invoice->is_refunded()) { |
|
408 | 408 | |
409 | - if ( isset( $_POST['wpinv_discount_code'] ) ) { |
|
410 | - $invoice->set_discount_code( wpinv_clean( $_POST['wpinv_discount_code'] ) ); |
|
409 | + if (isset($_POST['wpinv_discount_code'])) { |
|
410 | + $invoice->set_discount_code(wpinv_clean($_POST['wpinv_discount_code'])); |
|
411 | 411 | } |
412 | 412 | |
413 | - $discount = new WPInv_Discount( $invoice->get_discount_code() ); |
|
414 | - if ( $discount->exists() ) { |
|
415 | - $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) ); |
|
413 | + $discount = new WPInv_Discount($invoice->get_discount_code()); |
|
414 | + if ($discount->exists()) { |
|
415 | + $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount)); |
|
416 | 416 | } else { |
417 | - $invoice->remove_discount( 'discount_code' ); |
|
417 | + $invoice->remove_discount('discount_code'); |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | // Recalculate totals. |
@@ -423,17 +423,17 @@ discard block |
||
423 | 423 | } |
424 | 424 | |
425 | 425 | // If we're creating a new user... |
426 | - if ( ! empty( $_POST['wpinv_new_user'] ) && is_email( stripslashes( $_POST['wpinv_email'] ) ) ) { |
|
426 | + if (!empty($_POST['wpinv_new_user']) && is_email(stripslashes($_POST['wpinv_email']))) { |
|
427 | 427 | |
428 | 428 | // Attempt to create the user. |
429 | - $user = wpinv_create_user( sanitize_email( stripslashes( $_POST['wpinv_email'] ) ) ); |
|
429 | + $user = wpinv_create_user(sanitize_email(stripslashes($_POST['wpinv_email']))); |
|
430 | 430 | |
431 | 431 | |
432 | 432 | // If successful, update the invoice author. |
433 | - if ( is_numeric( $user ) ) { |
|
434 | - $invoice->set_author( $user ); |
|
433 | + if (is_numeric($user)) { |
|
434 | + $invoice->set_author($user); |
|
435 | 435 | } else { |
436 | - wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ ); |
|
436 | + wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__); |
|
437 | 437 | } |
438 | 438 | } |
439 | 439 | |
@@ -447,16 +447,16 @@ discard block |
||
447 | 447 | $GLOBALS['wpinv_skip_invoice_notification'] = false; |
448 | 448 | |
449 | 449 | // (Maybe) send new user notification. |
450 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
451 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) { |
|
452 | - wp_send_new_user_notifications( $user, 'user' ); |
|
450 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
451 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) { |
|
452 | + wp_send_new_user_notifications($user, 'user'); |
|
453 | 453 | } |
454 | 454 | |
455 | - if ( ! empty( $_POST['send_to_customer'] ) && ! $invoice->is_draft() ) { |
|
456 | - getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true ); |
|
455 | + if (!empty($_POST['send_to_customer']) && !$invoice->is_draft()) { |
|
456 | + getpaid()->get('invoice_emails')->user_invoice($invoice, true); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | // Fires after an invoice is saved. |
460 | - do_action( 'wpinv_invoice_metabox_saved', $invoice ); |
|
460 | + do_action('wpinv_invoice_metabox_saved', $invoice); |
|
461 | 461 | } |
462 | 462 | } |