@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | - exit; // Exit if accessed directly |
|
3 | + if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,110 +9,110 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @since 1.0.0 |
11 | 11 | */ |
12 | -class AUI { |
|
12 | + class AUI { |
|
13 | 13 | |
14 | - /** |
|
14 | + /** |
|
15 | 15 | * Holds the class instance. |
16 | 16 | * |
17 | 17 | * @since 1.0.0 |
18 | 18 | * @var null |
19 | 19 | */ |
20 | - private static $instance = null; |
|
20 | + private static $instance = null; |
|
21 | 21 | |
22 | - /** |
|
22 | + /** |
|
23 | 23 | * Holds the current AUI version number. |
24 | 24 | * |
25 | 25 | * @var string $ver The current version number. |
26 | 26 | */ |
27 | - public static $ver = '0.1.72'; |
|
27 | + public static $ver = '0.1.72'; |
|
28 | 28 | |
29 | - public static $options = null; |
|
29 | + public static $options = null; |
|
30 | 30 | |
31 | - /** |
|
31 | + /** |
|
32 | 32 | * There can be only one. |
33 | 33 | * |
34 | 34 | * @since 1.0.0 |
35 | 35 | * @return AUI|null |
36 | 36 | */ |
37 | - public static function instance() { |
|
38 | - if ( self::$instance == null ) { |
|
39 | - self::$instance = new AUI(); |
|
40 | - } |
|
37 | + public static function instance() { |
|
38 | + if ( self::$instance == null ) { |
|
39 | + self::$instance = new AUI(); |
|
40 | + } |
|
41 | 41 | |
42 | - return self::$instance; |
|
43 | - } |
|
42 | + return self::$instance; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
45 | + /** |
|
46 | 46 | * AUI constructor. |
47 | 47 | * |
48 | 48 | * @since 1.0.0 |
49 | 49 | */ |
50 | - private function __construct() { |
|
51 | - if ( function_exists( "__autoload" ) ) { |
|
52 | - spl_autoload_register( "__autoload" ); |
|
53 | - } |
|
54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
50 | + private function __construct() { |
|
51 | + if ( function_exists( "__autoload" ) ) { |
|
52 | + spl_autoload_register( "__autoload" ); |
|
53 | + } |
|
54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | 55 | |
56 | - // load options |
|
57 | - self::$options = get_option('aui_options'); |
|
58 | - } |
|
56 | + // load options |
|
57 | + self::$options = get_option('aui_options'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
60 | + /** |
|
61 | 61 | * Autoload any components on the fly. |
62 | 62 | * |
63 | 63 | * @since 1.0.0 |
64 | 64 | * |
65 | 65 | * @param $classname |
66 | 66 | */ |
67 | - private function autoload( $classname ) { |
|
68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
71 | - include_once( $file_path ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
67 | + private function autoload( $classname ) { |
|
68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
71 | + include_once( $file_path ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | 76 | * Get the AUI options. |
77 | 77 | * |
78 | 78 | * @param $option |
79 | 79 | * |
80 | 80 | * @return string|void |
81 | 81 | */ |
82 | - public function get_option( $option ){ |
|
83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | - |
|
85 | - if ( ! $result && $option) { |
|
86 | - if( $option == 'color_primary' ){ |
|
87 | - $result = AUI_PRIMARY_COLOR; |
|
88 | - }elseif( $option == 'color_secondary' ){ |
|
89 | - $result = AUI_SECONDARY_COLOR; |
|
90 | - } |
|
91 | - } |
|
92 | - return $result; |
|
93 | - } |
|
94 | - |
|
95 | - public function render( $items = array(), $echo = false ) { |
|
96 | - $output = ''; |
|
97 | - |
|
98 | - if ( ! empty( $items ) ) { |
|
99 | - foreach ( $items as $args ) { |
|
100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | - $output .= $this->$render( $args ); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - if ( $echo ) { |
|
108 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
109 | - }else{ |
|
110 | - return $output; |
|
111 | - } |
|
112 | - |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
82 | + public function get_option( $option ){ |
|
83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | + |
|
85 | + if ( ! $result && $option) { |
|
86 | + if( $option == 'color_primary' ){ |
|
87 | + $result = AUI_PRIMARY_COLOR; |
|
88 | + }elseif( $option == 'color_secondary' ){ |
|
89 | + $result = AUI_SECONDARY_COLOR; |
|
90 | + } |
|
91 | + } |
|
92 | + return $result; |
|
93 | + } |
|
94 | + |
|
95 | + public function render( $items = array(), $echo = false ) { |
|
96 | + $output = ''; |
|
97 | + |
|
98 | + if ( ! empty( $items ) ) { |
|
99 | + foreach ( $items as $args ) { |
|
100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | + $output .= $this->$render( $args ); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + if ( $echo ) { |
|
108 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
109 | + }else{ |
|
110 | + return $output; |
|
111 | + } |
|
112 | + |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | 116 | * Render and return a bootstrap alert component. |
117 | 117 | * |
118 | 118 | * @since 1.0.0 |
@@ -122,17 +122,17 @@ discard block |
||
122 | 122 | * |
123 | 123 | * @return string The rendered component. |
124 | 124 | */ |
125 | - public function alert( $args = array(), $echo = false ) { |
|
126 | - $output = AUI_Component_Alert::get( $args ); |
|
125 | + public function alert( $args = array(), $echo = false ) { |
|
126 | + $output = AUI_Component_Alert::get( $args ); |
|
127 | 127 | |
128 | - if ( $echo ) { |
|
129 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
130 | - }else{ |
|
131 | - return $output; |
|
132 | - } |
|
133 | - } |
|
128 | + if ( $echo ) { |
|
129 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
130 | + }else{ |
|
131 | + return $output; |
|
132 | + } |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
135 | + /** |
|
136 | 136 | * Render and return a bootstrap input component. |
137 | 137 | * |
138 | 138 | * @since 1.0.0 |
@@ -142,17 +142,17 @@ discard block |
||
142 | 142 | * |
143 | 143 | * @return string The rendered component. |
144 | 144 | */ |
145 | - public function input( $args = array(), $echo = false ) { |
|
146 | - $output = AUI_Component_Input::input( $args ); |
|
145 | + public function input( $args = array(), $echo = false ) { |
|
146 | + $output = AUI_Component_Input::input( $args ); |
|
147 | 147 | |
148 | - if ( $echo ) { |
|
149 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
150 | - }else{ |
|
151 | - return $output; |
|
152 | - } |
|
153 | - } |
|
148 | + if ( $echo ) { |
|
149 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
150 | + }else{ |
|
151 | + return $output; |
|
152 | + } |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
155 | + /** |
|
156 | 156 | * Render and return a bootstrap textarea component. |
157 | 157 | * |
158 | 158 | * @since 1.0.0 |
@@ -162,17 +162,17 @@ discard block |
||
162 | 162 | * |
163 | 163 | * @return string The rendered component. |
164 | 164 | */ |
165 | - public function textarea( $args = array(), $echo = false ) { |
|
166 | - $output = AUI_Component_Input::textarea( $args ); |
|
165 | + public function textarea( $args = array(), $echo = false ) { |
|
166 | + $output = AUI_Component_Input::textarea( $args ); |
|
167 | 167 | |
168 | - if ( $echo ) { |
|
169 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
170 | - }else{ |
|
171 | - return $output; |
|
172 | - } |
|
173 | - } |
|
168 | + if ( $echo ) { |
|
169 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
170 | + }else{ |
|
171 | + return $output; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
175 | + /** |
|
176 | 176 | * Render and return a bootstrap button component. |
177 | 177 | * |
178 | 178 | * @since 1.0.0 |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return string The rendered component. |
184 | 184 | */ |
185 | - public function button( $args = array(), $echo = false ) { |
|
186 | - $output = AUI_Component_Button::get( $args ); |
|
185 | + public function button( $args = array(), $echo = false ) { |
|
186 | + $output = AUI_Component_Button::get( $args ); |
|
187 | 187 | |
188 | - if ( $echo ) { |
|
189 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
190 | - }else{ |
|
191 | - return $output; |
|
192 | - } |
|
193 | - } |
|
188 | + if ( $echo ) { |
|
189 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
190 | + }else{ |
|
191 | + return $output; |
|
192 | + } |
|
193 | + } |
|
194 | 194 | |
195 | - /** |
|
195 | + /** |
|
196 | 196 | * Render and return a bootstrap button component. |
197 | 197 | * |
198 | 198 | * @since 1.0.0 |
@@ -202,31 +202,31 @@ discard block |
||
202 | 202 | * |
203 | 203 | * @return string The rendered component. |
204 | 204 | */ |
205 | - public function badge( $args = array(), $echo = false ) { |
|
206 | - $defaults = array( |
|
207 | - 'class' => 'badge badge-primary align-middle', |
|
208 | - ); |
|
205 | + public function badge( $args = array(), $echo = false ) { |
|
206 | + $defaults = array( |
|
207 | + 'class' => 'badge badge-primary align-middle', |
|
208 | + ); |
|
209 | 209 | |
210 | - // maybe set type. |
|
211 | - if ( empty( $args['href'] ) ) { |
|
212 | - $defaults['type'] = 'badge'; |
|
213 | - } |
|
210 | + // maybe set type. |
|
211 | + if ( empty( $args['href'] ) ) { |
|
212 | + $defaults['type'] = 'badge'; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
215 | + /** |
|
216 | 216 | * Parse incoming $args into an array and merge it with $defaults |
217 | 217 | */ |
218 | - $args = wp_parse_args( $args, $defaults ); |
|
218 | + $args = wp_parse_args( $args, $defaults ); |
|
219 | 219 | |
220 | - $output = AUI_Component_Button::get( $args ); |
|
220 | + $output = AUI_Component_Button::get( $args ); |
|
221 | 221 | |
222 | - if ( $echo ) { |
|
223 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
224 | - }else{ |
|
225 | - return $output; |
|
226 | - } |
|
227 | - } |
|
222 | + if ( $echo ) { |
|
223 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
224 | + }else{ |
|
225 | + return $output; |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
229 | + /** |
|
230 | 230 | * Render and return a bootstrap dropdown component. |
231 | 231 | * |
232 | 232 | * @since 1.0.0 |
@@ -236,17 +236,17 @@ discard block |
||
236 | 236 | * |
237 | 237 | * @return string The rendered component. |
238 | 238 | */ |
239 | - public function dropdown( $args = array(), $echo = false ) { |
|
240 | - $output = AUI_Component_Dropdown::get( $args ); |
|
239 | + public function dropdown( $args = array(), $echo = false ) { |
|
240 | + $output = AUI_Component_Dropdown::get( $args ); |
|
241 | 241 | |
242 | - if ( $echo ) { |
|
243 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
244 | - }else{ |
|
245 | - return $output; |
|
246 | - } |
|
247 | - } |
|
242 | + if ( $echo ) { |
|
243 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
244 | + }else{ |
|
245 | + return $output; |
|
246 | + } |
|
247 | + } |
|
248 | 248 | |
249 | - /** |
|
249 | + /** |
|
250 | 250 | * Render and return a bootstrap select component. |
251 | 251 | * |
252 | 252 | * @since 1.0.0 |
@@ -256,17 +256,17 @@ discard block |
||
256 | 256 | * |
257 | 257 | * @return string The rendered component. |
258 | 258 | */ |
259 | - public function select( $args = array(), $echo = false ) { |
|
260 | - $output = AUI_Component_Input::select( $args ); |
|
259 | + public function select( $args = array(), $echo = false ) { |
|
260 | + $output = AUI_Component_Input::select( $args ); |
|
261 | 261 | |
262 | - if ( $echo ) { |
|
263 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
264 | - }else{ |
|
265 | - return $output; |
|
266 | - } |
|
267 | - } |
|
262 | + if ( $echo ) { |
|
263 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
264 | + }else{ |
|
265 | + return $output; |
|
266 | + } |
|
267 | + } |
|
268 | 268 | |
269 | - /** |
|
269 | + /** |
|
270 | 270 | * Render and return a bootstrap radio component. |
271 | 271 | * |
272 | 272 | * @since 1.0.0 |
@@ -276,17 +276,17 @@ discard block |
||
276 | 276 | * |
277 | 277 | * @return string The rendered component. |
278 | 278 | */ |
279 | - public function radio( $args = array(), $echo = false ) { |
|
280 | - $output = AUI_Component_Input::radio( $args ); |
|
279 | + public function radio( $args = array(), $echo = false ) { |
|
280 | + $output = AUI_Component_Input::radio( $args ); |
|
281 | 281 | |
282 | - if ( $echo ) { |
|
283 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
284 | - }else{ |
|
285 | - return $output; |
|
286 | - } |
|
287 | - } |
|
282 | + if ( $echo ) { |
|
283 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
284 | + }else{ |
|
285 | + return $output; |
|
286 | + } |
|
287 | + } |
|
288 | 288 | |
289 | - /** |
|
289 | + /** |
|
290 | 290 | * Render and return a bootstrap pagination component. |
291 | 291 | * |
292 | 292 | * @since 1.0.0 |
@@ -296,14 +296,14 @@ discard block |
||
296 | 296 | * |
297 | 297 | * @return string The rendered component. |
298 | 298 | */ |
299 | - public function pagination( $args = array(), $echo = false ) { |
|
300 | - $output = AUI_Component_Pagination::get( $args ); |
|
301 | - |
|
302 | - if ( $echo ) { |
|
303 | - echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
304 | - }else{ |
|
305 | - return $output; |
|
306 | - } |
|
307 | - } |
|
299 | + public function pagination( $args = array(), $echo = false ) { |
|
300 | + $output = AUI_Component_Pagination::get( $args ); |
|
301 | + |
|
302 | + if ( $echo ) { |
|
303 | + echo $output; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
304 | + }else{ |
|
305 | + return $output; |
|
306 | + } |
|
307 | + } |
|
308 | 308 | |
309 | 309 | } |
310 | 310 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | /** |
3 | 3 | * Functionality to convert BS4 to BS5. |
4 | 4 | */ |
@@ -13,77 +13,77 @@ discard block |
||
13 | 13 | * |
14 | 14 | * @return array|mixed|string|string[] |
15 | 15 | */ |
16 | -function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) { |
|
17 | - global $aui_bs5; |
|
16 | + function aui_bs_convert_sd_output( $output, $instance = '', $args = '', $sd = '' ) { |
|
17 | + global $aui_bs5; |
|
18 | 18 | |
19 | - if ( $aui_bs5 ) { |
|
20 | - $convert = array( |
|
21 | - '"ml-' => '"ms-', |
|
22 | - '"mr-' => '"me-', |
|
23 | - '"pl-' => '"ps-', |
|
24 | - '"pr-' => '"pe-', |
|
25 | - "'ml-" => "'ms-", |
|
26 | - "'mr-" => "'me-", |
|
27 | - "'pl-" => "'ps-", |
|
28 | - "'pr-" => "'pe-", |
|
29 | - ' ml-' => ' ms-', |
|
30 | - ' mr-' => ' me-', |
|
31 | - ' pl-' => ' ps-', |
|
32 | - ' pr-' => ' pe-', |
|
33 | - '.ml-' => '.ms-', |
|
34 | - '.mr-' => '.me-', |
|
35 | - '.pl-' => '.ps-', |
|
36 | - '.pr-' => '.pe-', |
|
37 | - ' form-row' => ' row', |
|
38 | - ' embed-responsive-item' => '', |
|
39 | - ' embed-responsive' => ' ratio', |
|
40 | - '-1by1' => '-1x1', |
|
41 | - '-4by3' => '-4x3', |
|
42 | - '-16by9' => '-16x9', |
|
43 | - '-21by9' => '-21x9', |
|
44 | - 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
45 | - 'geodir-lightbox-iframe' => 'aui-lightbox-iframe', |
|
46 | - ' badge-' => ' text-bg-', |
|
47 | - 'form-group' => 'mb-3', |
|
48 | - 'custom-select' => 'form-select', |
|
49 | - 'float-left' => 'float-start', |
|
50 | - 'float-right' => 'float-end', |
|
51 | - 'text-left' => 'text-start', |
|
52 | - 'text-sm-left' => 'text-sm-start', |
|
53 | - 'text-md-left' => 'text-md-start', |
|
54 | - 'text-lg-left' => 'text-lg-start', |
|
55 | - 'text-right' => 'text-end', |
|
56 | - 'text-sm-right' => 'text-sm-end', |
|
57 | - 'text-md-right' => 'text-md-end', |
|
58 | - 'text-lg-right' => 'text-lg-end', |
|
59 | - 'border-right' => 'border-end', |
|
60 | - 'border-left' => 'border-start', |
|
61 | - 'font-weight-' => 'fw-', |
|
62 | - 'btn-block' => 'w-100', |
|
63 | - 'rounded-left' => 'rounded-start', |
|
64 | - 'rounded-right' => 'rounded-end', |
|
65 | - 'font-italic' => 'fst-italic', |
|
19 | + if ( $aui_bs5 ) { |
|
20 | + $convert = array( |
|
21 | + '"ml-' => '"ms-', |
|
22 | + '"mr-' => '"me-', |
|
23 | + '"pl-' => '"ps-', |
|
24 | + '"pr-' => '"pe-', |
|
25 | + "'ml-" => "'ms-", |
|
26 | + "'mr-" => "'me-", |
|
27 | + "'pl-" => "'ps-", |
|
28 | + "'pr-" => "'pe-", |
|
29 | + ' ml-' => ' ms-', |
|
30 | + ' mr-' => ' me-', |
|
31 | + ' pl-' => ' ps-', |
|
32 | + ' pr-' => ' pe-', |
|
33 | + '.ml-' => '.ms-', |
|
34 | + '.mr-' => '.me-', |
|
35 | + '.pl-' => '.ps-', |
|
36 | + '.pr-' => '.pe-', |
|
37 | + ' form-row' => ' row', |
|
38 | + ' embed-responsive-item' => '', |
|
39 | + ' embed-responsive' => ' ratio', |
|
40 | + '-1by1' => '-1x1', |
|
41 | + '-4by3' => '-4x3', |
|
42 | + '-16by9' => '-16x9', |
|
43 | + '-21by9' => '-21x9', |
|
44 | + 'geodir-lightbox-image' => 'aui-lightbox-image', |
|
45 | + 'geodir-lightbox-iframe' => 'aui-lightbox-iframe', |
|
46 | + ' badge-' => ' text-bg-', |
|
47 | + 'form-group' => 'mb-3', |
|
48 | + 'custom-select' => 'form-select', |
|
49 | + 'float-left' => 'float-start', |
|
50 | + 'float-right' => 'float-end', |
|
51 | + 'text-left' => 'text-start', |
|
52 | + 'text-sm-left' => 'text-sm-start', |
|
53 | + 'text-md-left' => 'text-md-start', |
|
54 | + 'text-lg-left' => 'text-lg-start', |
|
55 | + 'text-right' => 'text-end', |
|
56 | + 'text-sm-right' => 'text-sm-end', |
|
57 | + 'text-md-right' => 'text-md-end', |
|
58 | + 'text-lg-right' => 'text-lg-end', |
|
59 | + 'border-right' => 'border-end', |
|
60 | + 'border-left' => 'border-start', |
|
61 | + 'font-weight-' => 'fw-', |
|
62 | + 'btn-block' => 'w-100', |
|
63 | + 'rounded-left' => 'rounded-start', |
|
64 | + 'rounded-right' => 'rounded-end', |
|
65 | + 'font-italic' => 'fst-italic', |
|
66 | 66 | |
67 | -// 'custom-control custom-checkbox' => 'form-check', |
|
68 | - // data |
|
69 | - ' data-toggle=' => ' data-bs-toggle=', |
|
70 | - 'data-ride=' => 'data-bs-ride=', |
|
71 | - 'data-controlnav=' => 'data-bs-controlnav=', |
|
72 | - 'data-slide=' => 'data-bs-slide=', |
|
73 | - 'data-slide-to=' => 'data-bs-slide-to=', |
|
74 | - 'data-target=' => 'data-bs-target=', |
|
75 | - 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
76 | - 'class="close"' => 'class="btn-close"', |
|
77 | - '<span aria-hidden="true">×</span>' => '', |
|
78 | - ); |
|
79 | - $output = str_replace( |
|
80 | - array_keys( $convert ), |
|
81 | - array_values( $convert ), |
|
82 | - $output |
|
83 | - ); |
|
84 | - } |
|
67 | + // 'custom-control custom-checkbox' => 'form-check', |
|
68 | + // data |
|
69 | + ' data-toggle=' => ' data-bs-toggle=', |
|
70 | + 'data-ride=' => 'data-bs-ride=', |
|
71 | + 'data-controlnav=' => 'data-bs-controlnav=', |
|
72 | + 'data-slide=' => 'data-bs-slide=', |
|
73 | + 'data-slide-to=' => 'data-bs-slide-to=', |
|
74 | + 'data-target=' => 'data-bs-target=', |
|
75 | + 'data-dismiss="modal"' => 'data-bs-dismiss="modal"', |
|
76 | + 'class="close"' => 'class="btn-close"', |
|
77 | + '<span aria-hidden="true">×</span>' => '', |
|
78 | + ); |
|
79 | + $output = str_replace( |
|
80 | + array_keys( $convert ), |
|
81 | + array_values( $convert ), |
|
82 | + $output |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | - return $output; |
|
86 | + return $output; |
|
87 | 87 | } |
88 | 88 | |
89 | -add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this |
|
89 | + add_filter( 'wp_super_duper_widget_output', 'aui_bs_convert_sd_output', 10, 4 ); //$output, $instance, $args, $this |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | - exit; // Exit if accessed directly |
|
3 | + if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,114 +9,114 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @since 1.0.0 |
11 | 11 | */ |
12 | -class AUI_Component_Pagination { |
|
12 | + class AUI_Component_Pagination { |
|
13 | 13 | |
14 | - /** |
|
14 | + /** |
|
15 | 15 | * Build the component. |
16 | 16 | * |
17 | 17 | * @param array $args |
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function get( $args = array() ) { |
|
22 | - global $wp_query, $aui_bs5; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'class' => '', |
|
26 | - 'mid_size' => 2, |
|
27 | - 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | - 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | - 'screen_reader_text' => __( 'Posts navigation', 'ayecode-connect' ), |
|
30 | - 'before_paging' => '', |
|
31 | - 'after_paging' => '', |
|
32 | - 'type' => 'array', |
|
33 | - 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | - 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
35 | - 'rounded_style' => false, |
|
36 | - 'custom_next_text' => '', // Custom next page text |
|
37 | - 'custom_prev_text' => '', // Custom prev page text |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
21 | + public static function get( $args = array() ) { |
|
22 | + global $wp_query, $aui_bs5; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'class' => '', |
|
26 | + 'mid_size' => 2, |
|
27 | + 'prev_text' => '<i class="fas fa-chevron-left"></i>', |
|
28 | + 'next_text' => '<i class="fas fa-chevron-right"></i>', |
|
29 | + 'screen_reader_text' => __( 'Posts navigation', 'ayecode-connect' ), |
|
30 | + 'before_paging' => '', |
|
31 | + 'after_paging' => '', |
|
32 | + 'type' => 'array', |
|
33 | + 'total' => isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1, |
|
34 | + 'links' => array(), // an array of links if using custom links, this includes the a tag. |
|
35 | + 'rounded_style' => false, |
|
36 | + 'custom_next_text' => '', // Custom next page text |
|
37 | + 'custom_prev_text' => '', // Custom prev page text |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | 41 | * Parse incoming $args into an array and merge it with $defaults |
42 | 42 | */ |
43 | - $args = wp_parse_args( $args, $defaults ); |
|
44 | - |
|
45 | - $output = ''; |
|
46 | - |
|
47 | - // Don't print empty markup if there's only one page. |
|
48 | - if ( $args['total'] > 1 ) { |
|
49 | - // Set up paginated links. |
|
50 | - $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
51 | - |
|
52 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
53 | - |
|
54 | - $custom_prev_link = ''; |
|
55 | - $custom_next_link = ''; |
|
56 | - |
|
57 | - // make the output bootstrap ready |
|
58 | - $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
59 | - if ( ! empty( $links ) ) { |
|
60 | - foreach ( $links as $link ) { |
|
61 | - $_link = $link; |
|
62 | - |
|
63 | - if ( $aui_bs5 ) { |
|
64 | - $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
65 | - $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
66 | - $links_html .= "<li class='page-item mx-0'>"; |
|
67 | - $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
68 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
69 | - $links_html .= $link; |
|
70 | - $links_html .= "</li>"; |
|
71 | - } else { |
|
72 | - $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
73 | - $links_html .= "<li class='page-item $active'>"; |
|
74 | - $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
75 | - $links_html .= "</li>"; |
|
76 | - } |
|
77 | - |
|
78 | - if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
79 | - $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
80 | - $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
81 | - |
|
82 | - if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
83 | - $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
84 | - } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
85 | - $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
90 | - $links_html .= "</ul>"; |
|
91 | - |
|
92 | - if ( $links ) { |
|
93 | - $output .= '<section class="px-0 py-2 w-100">'; |
|
94 | - $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
95 | - $output .= '</section>'; |
|
96 | - } |
|
97 | - |
|
98 | - $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
99 | - $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
100 | - } |
|
101 | - |
|
102 | - if ( $output ) { |
|
103 | - if ( $custom_next_link || $custom_prev_link ) { |
|
104 | - $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
105 | - $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
106 | - |
|
107 | - $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
108 | - } |
|
109 | - |
|
110 | - if ( ! empty( $args['before_paging'] ) ) { |
|
111 | - $output = $args['before_paging'] . $output; |
|
112 | - } |
|
113 | - |
|
114 | - if ( ! empty( $args['after_paging'] ) ) { |
|
115 | - $output = $output . $args['after_paging']; |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - return $output; |
|
120 | - } |
|
43 | + $args = wp_parse_args( $args, $defaults ); |
|
44 | + |
|
45 | + $output = ''; |
|
46 | + |
|
47 | + // Don't print empty markup if there's only one page. |
|
48 | + if ( $args['total'] > 1 ) { |
|
49 | + // Set up paginated links. |
|
50 | + $links = !empty( $args['links'] ) ? $args['links'] : paginate_links( $args ); |
|
51 | + |
|
52 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
53 | + |
|
54 | + $custom_prev_link = ''; |
|
55 | + $custom_next_link = ''; |
|
56 | + |
|
57 | + // make the output bootstrap ready |
|
58 | + $links_html = "<ul class='pagination m-0 p-0 $class'>"; |
|
59 | + if ( ! empty( $links ) ) { |
|
60 | + foreach ( $links as $link ) { |
|
61 | + $_link = $link; |
|
62 | + |
|
63 | + if ( $aui_bs5 ) { |
|
64 | + $link_class = $args['rounded_style'] ? 'page-link badge rounded-pill border-0 mx-1 fs-base text-dark link-primary' : 'page-link'; |
|
65 | + $link_class_active = $args['rounded_style'] ? ' current active fw-bold badge rounded-pill' : ' current active'; |
|
66 | + $links_html .= "<li class='page-item mx-0'>"; |
|
67 | + $link = str_replace( array( "page-numbers", " current" ), array( $link_class, $link_class_active ), $link ); |
|
68 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
69 | + $links_html .= $link; |
|
70 | + $links_html .= "</li>"; |
|
71 | + } else { |
|
72 | + $active = strpos( $link, 'current' ) !== false ? 'active' : ''; |
|
73 | + $links_html .= "<li class='page-item $active'>"; |
|
74 | + $links_html .= str_replace( "page-numbers", "page-link", $link ); |
|
75 | + $links_html .= "</li>"; |
|
76 | + } |
|
77 | + |
|
78 | + if ( strpos( $_link, 'next page-numbers' ) || strpos( $_link, 'prev page-numbers' ) ) { |
|
79 | + $link = str_replace( array( "page-numbers", " current" ), array( 'btn btn-outline-primary rounded' . ( $args['rounded_style'] ? '-pill' : '' ) . ' mx-1 fs-base text-dark link-primary', ' current active fw-bold badge rounded-pill' ), $_link ); |
|
80 | + $link = str_replace( 'text-dark link-primary current', 'current', $link ); |
|
81 | + |
|
82 | + if ( strpos( $_link, 'next page-numbers' ) && ! empty( $args['custom_next_text'] ) ) { |
|
83 | + $custom_next_link = str_replace( $args['next_text'], $args['custom_next_text'], $link ); |
|
84 | + } else if ( strpos( $_link, 'prev page-numbers' ) && ! empty( $args['custom_prev_text'] ) ) { |
|
85 | + $custom_prev_link = str_replace( $args['prev_text'], $args['custom_prev_text'], $link ); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | + $links_html .= "</ul>"; |
|
91 | + |
|
92 | + if ( $links ) { |
|
93 | + $output .= '<section class="px-0 py-2 w-100">'; |
|
94 | + $output .= _navigation_markup( $links_html, 'aui-pagination', $args['screen_reader_text'] ); |
|
95 | + $output .= '</section>'; |
|
96 | + } |
|
97 | + |
|
98 | + $output = str_replace( "screen-reader-text", "screen-reader-text sr-only", $output ); |
|
99 | + $output = str_replace( "nav-links", "aui-nav-links", $output ); |
|
100 | + } |
|
101 | + |
|
102 | + if ( $output ) { |
|
103 | + if ( $custom_next_link || $custom_prev_link ) { |
|
104 | + $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; |
|
105 | + $current = get_query_var( 'paged' ) ? (int) get_query_var( 'paged' ) : 1; |
|
106 | + |
|
107 | + $output = '<div class="row d-flex align-items-center justify-content-between"><div class="col text-start">' . $custom_prev_link . '</div><div class="col text-center d-none d-md-block">' . $output . '</div><div class="col text-center d-md-none">' . $current . '/' . $args['total'] . '</div><div class="col text-end">' . $custom_next_link . '</div></div>'; |
|
108 | + } |
|
109 | + |
|
110 | + if ( ! empty( $args['before_paging'] ) ) { |
|
111 | + $output = $args['before_paging'] . $output; |
|
112 | + } |
|
113 | + |
|
114 | + if ( ! empty( $args['after_paging'] ) ) { |
|
115 | + $output = $output . $args['after_paging']; |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + return $output; |
|
120 | + } |
|
121 | 121 | |
122 | 122 | } |
123 | 123 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | - exit; // Exit if accessed directly |
|
3 | + if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,64 +9,64 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @since 1.0.0 |
11 | 11 | */ |
12 | -class AUI_Component_Dropdown { |
|
12 | + class AUI_Component_Dropdown { |
|
13 | 13 | |
14 | - /** |
|
14 | + /** |
|
15 | 15 | * Build the component. |
16 | 16 | * |
17 | 17 | * @param array $args |
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function get($args = array()){ |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'button', |
|
24 | - 'href' => '#', |
|
25 | - 'class' => 'btn btn-primary dropdown-toggle', |
|
26 | - 'wrapper_class' => '', |
|
27 | - 'dropdown_menu_class' => '', |
|
28 | - 'id' => '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'content' => '', |
|
32 | - 'icon' => '', |
|
33 | - 'hover_content' => '', |
|
34 | - 'hover_icon' => '', |
|
35 | - 'data-toggle' => 'dropdown', |
|
36 | - 'aria-haspopup' => 'true', |
|
37 | - 'aria-expanded' => 'false', |
|
38 | - 'dropdown_menu' => '', // unescaped html menu (non-preferred way) |
|
39 | - 'dropdown_items' => array(), // array of AUI calls |
|
21 | + public static function get($args = array()){ |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'button', |
|
24 | + 'href' => '#', |
|
25 | + 'class' => 'btn btn-primary dropdown-toggle', |
|
26 | + 'wrapper_class' => '', |
|
27 | + 'dropdown_menu_class' => '', |
|
28 | + 'id' => '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'content' => '', |
|
32 | + 'icon' => '', |
|
33 | + 'hover_content' => '', |
|
34 | + 'hover_icon' => '', |
|
35 | + 'data-toggle' => 'dropdown', |
|
36 | + 'aria-haspopup' => 'true', |
|
37 | + 'aria-expanded' => 'false', |
|
38 | + 'dropdown_menu' => '', // unescaped html menu (non-preferred way) |
|
39 | + 'dropdown_items' => array(), // array of AUI calls |
|
40 | 40 | |
41 | - ); |
|
41 | + ); |
|
42 | 42 | |
43 | - /** |
|
43 | + /** |
|
44 | 44 | * Parse incoming $args into an array and merge it with $defaults |
45 | 45 | */ |
46 | - $args = wp_parse_args( $args, $defaults ); |
|
47 | - $output = ''; |
|
48 | - if ( ! empty( $args['type'] ) ) { |
|
49 | - // wrapper open |
|
50 | - $output .= '<div class="dropdown '.AUI_Component_Helper::esc_classes($args['wrapper_class']).'">'; |
|
46 | + $args = wp_parse_args( $args, $defaults ); |
|
47 | + $output = ''; |
|
48 | + if ( ! empty( $args['type'] ) ) { |
|
49 | + // wrapper open |
|
50 | + $output .= '<div class="dropdown '.AUI_Component_Helper::esc_classes($args['wrapper_class']).'">'; |
|
51 | 51 | |
52 | - // button part |
|
53 | - $output .= aui()->button($args); |
|
52 | + // button part |
|
53 | + $output .= aui()->button($args); |
|
54 | 54 | |
55 | - // dropdown-menu |
|
56 | - if(!empty($args['dropdown_menu'])){ |
|
57 | - $output .= $args['dropdown_menu']; |
|
58 | - }elseif(!empty($args['dropdown_items'])){ |
|
59 | - $output .= '<div class="dropdown-menu '.AUI_Component_Helper::esc_classes($args['dropdown_menu_class']).'" aria-labelledby="'.sanitize_html_class($args['id']).'">'; |
|
60 | - $output .= aui()->render($args['dropdown_items']); |
|
61 | - $output .= '</div>'; |
|
62 | - } |
|
55 | + // dropdown-menu |
|
56 | + if(!empty($args['dropdown_menu'])){ |
|
57 | + $output .= $args['dropdown_menu']; |
|
58 | + }elseif(!empty($args['dropdown_items'])){ |
|
59 | + $output .= '<div class="dropdown-menu '.AUI_Component_Helper::esc_classes($args['dropdown_menu_class']).'" aria-labelledby="'.sanitize_html_class($args['id']).'">'; |
|
60 | + $output .= aui()->render($args['dropdown_items']); |
|
61 | + $output .= '</div>'; |
|
62 | + } |
|
63 | 63 | |
64 | - // wrapper close |
|
65 | - $output .= '</div>'; |
|
64 | + // wrapper close |
|
65 | + $output .= '</div>'; |
|
66 | 66 | |
67 | - } |
|
67 | + } |
|
68 | 68 | |
69 | - return $output; |
|
70 | - } |
|
69 | + return $output; |
|
70 | + } |
|
71 | 71 | |
72 | 72 | } |
73 | 73 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | - exit; // Exit if accessed directly |
|
3 | + if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,89 +9,89 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @since 1.0.0 |
11 | 11 | */ |
12 | -class AUI_Component_Alert { |
|
12 | + class AUI_Component_Alert { |
|
13 | 13 | |
14 | - /** |
|
14 | + /** |
|
15 | 15 | * Build the component. |
16 | 16 | * |
17 | 17 | * @param array $args |
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function get($args = array()){ |
|
22 | - global $aui_bs5; |
|
23 | - $defaults = array( |
|
24 | - 'type' => 'info', |
|
25 | - 'class' => '', |
|
26 | - 'icon' => '', |
|
27 | - 'heading' => '', |
|
28 | - 'content' => '', |
|
29 | - 'footer' => '', |
|
30 | - 'dismissible'=> false, |
|
31 | - 'data' => '', |
|
32 | - ); |
|
33 | - |
|
34 | - /** |
|
21 | + public static function get($args = array()){ |
|
22 | + global $aui_bs5; |
|
23 | + $defaults = array( |
|
24 | + 'type' => 'info', |
|
25 | + 'class' => '', |
|
26 | + 'icon' => '', |
|
27 | + 'heading' => '', |
|
28 | + 'content' => '', |
|
29 | + 'footer' => '', |
|
30 | + 'dismissible'=> false, |
|
31 | + 'data' => '', |
|
32 | + ); |
|
33 | + |
|
34 | + /** |
|
35 | 35 | * Parse incoming $args into an array and merge it with $defaults |
36 | 36 | */ |
37 | - $args = wp_parse_args( $args, $defaults ); |
|
38 | - $output = ''; |
|
39 | - if ( ! empty( $args['content'] ) ) { |
|
40 | - $type = sanitize_html_class( $args['type'] ); |
|
41 | - if($type=='error'){$type='danger';} |
|
42 | - $icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : ''; |
|
43 | - |
|
44 | - // set default icon |
|
45 | - if(!$icon && $args['icon']!==false && $type){ |
|
46 | - if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} |
|
47 | - elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} |
|
48 | - elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} |
|
49 | - elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';} |
|
50 | - } |
|
51 | - |
|
52 | - $data = ''; |
|
53 | - $class = !empty($args['class']) ? esc_attr($args['class']) : ''; |
|
54 | - if($args['dismissible']){$class .= " alert-dismissible fade show";} |
|
55 | - |
|
56 | - // open |
|
57 | - $output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>'; |
|
58 | - |
|
59 | - // heading |
|
60 | - if ( ! empty( $args['heading'] ) ) { |
|
61 | - $output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>'; |
|
62 | - } |
|
63 | - |
|
64 | - // icon |
|
65 | - if ( ! empty( $icon) ) { |
|
66 | - $output .= $icon." "; |
|
67 | - } |
|
68 | - |
|
69 | - // content |
|
70 | - $output .= $args['content']; |
|
71 | - |
|
72 | - // dismissible |
|
73 | - if($args['dismissible']){ |
|
74 | - |
|
75 | - if ( $aui_bs5 ) { |
|
76 | - $output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'; |
|
77 | - }else{ |
|
78 | - $output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; |
|
79 | - $output .= '<span aria-hidden="true">×</span>'; |
|
80 | - $output .= '</button>'; |
|
81 | - } |
|
82 | - } |
|
83 | - |
|
84 | - // footer |
|
85 | - if ( ! empty( $args['footer'] ) ) { |
|
86 | - $output .= '<hr>'; |
|
87 | - $output .= '<p class="mb-0">' . $args['footer'] . '</p>'; |
|
88 | - } |
|
89 | - |
|
90 | - // close |
|
91 | - $output .= '</div>'; |
|
92 | - } |
|
93 | - |
|
94 | - return $output; |
|
95 | - } |
|
37 | + $args = wp_parse_args( $args, $defaults ); |
|
38 | + $output = ''; |
|
39 | + if ( ! empty( $args['content'] ) ) { |
|
40 | + $type = sanitize_html_class( $args['type'] ); |
|
41 | + if($type=='error'){$type='danger';} |
|
42 | + $icon = !empty($args['icon']) ? "<i class='".esc_attr($args['icon'])."'></i>" : ''; |
|
43 | + |
|
44 | + // set default icon |
|
45 | + if(!$icon && $args['icon']!==false && $type){ |
|
46 | + if($type=='danger'){$icon = '<i class="fas fa-exclamation-circle"></i>';} |
|
47 | + elseif($type=='warning'){$icon = '<i class="fas fa-exclamation-triangle"></i>';} |
|
48 | + elseif($type=='success'){$icon = '<i class="fas fa-check-circle"></i>';} |
|
49 | + elseif($type=='info'){$icon = '<i class="fas fa-info-circle"></i>';} |
|
50 | + } |
|
51 | + |
|
52 | + $data = ''; |
|
53 | + $class = !empty($args['class']) ? esc_attr($args['class']) : ''; |
|
54 | + if($args['dismissible']){$class .= " alert-dismissible fade show";} |
|
55 | + |
|
56 | + // open |
|
57 | + $output .= '<div class="alert alert-' . $type . ' '.$class.'" role="alert" '.$data.'>'; |
|
58 | + |
|
59 | + // heading |
|
60 | + if ( ! empty( $args['heading'] ) ) { |
|
61 | + $output .= '<h4 class="alert-heading">' . $args['heading'] . '</h4>'; |
|
62 | + } |
|
63 | + |
|
64 | + // icon |
|
65 | + if ( ! empty( $icon) ) { |
|
66 | + $output .= $icon." "; |
|
67 | + } |
|
68 | + |
|
69 | + // content |
|
70 | + $output .= $args['content']; |
|
71 | + |
|
72 | + // dismissible |
|
73 | + if($args['dismissible']){ |
|
74 | + |
|
75 | + if ( $aui_bs5 ) { |
|
76 | + $output .= '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>'; |
|
77 | + }else{ |
|
78 | + $output .= '<button type="button" class="close" data-dismiss="alert" aria-label="Close">'; |
|
79 | + $output .= '<span aria-hidden="true">×</span>'; |
|
80 | + $output .= '</button>'; |
|
81 | + } |
|
82 | + } |
|
83 | + |
|
84 | + // footer |
|
85 | + if ( ! empty( $args['footer'] ) ) { |
|
86 | + $output .= '<hr>'; |
|
87 | + $output .= '<p class="mb-0">' . $args['footer'] . '</p>'; |
|
88 | + } |
|
89 | + |
|
90 | + // close |
|
91 | + $output .= '</div>'; |
|
92 | + } |
|
93 | + |
|
94 | + return $output; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | } |
98 | 98 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | - exit; // Exit if accessed directly |
|
3 | + if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,145 +9,145 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @since 1.0.0 |
11 | 11 | */ |
12 | -class AUI_Component_Button { |
|
12 | + class AUI_Component_Button { |
|
13 | 13 | |
14 | - /** |
|
14 | + /** |
|
15 | 15 | * Build the component. |
16 | 16 | * |
17 | 17 | * @param array $args |
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function get($args = array()){ |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'a', // a, button, badge |
|
24 | - 'href' => '#', |
|
25 | - 'new_window' => false, |
|
26 | - 'class' => 'btn btn-primary', |
|
27 | - 'id' => '', |
|
28 | - 'title' => '', |
|
29 | - 'value' => '', |
|
30 | - 'content' => '', |
|
31 | - 'icon' => '', |
|
32 | - 'hover_content' => '', |
|
33 | - 'hover_icon' => '', |
|
34 | - 'new_line_after' => true, |
|
35 | - 'no_wrap' => true, |
|
36 | - 'onclick' => '', |
|
37 | - 'style' => '', |
|
38 | - 'extra_attributes' => array(), // an array of extra attributes |
|
39 | - 'icon_extra_attributes' => array() // an array of icon extra attributes |
|
40 | - ); |
|
41 | - |
|
42 | - /** |
|
21 | + public static function get($args = array()){ |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'a', // a, button, badge |
|
24 | + 'href' => '#', |
|
25 | + 'new_window' => false, |
|
26 | + 'class' => 'btn btn-primary', |
|
27 | + 'id' => '', |
|
28 | + 'title' => '', |
|
29 | + 'value' => '', |
|
30 | + 'content' => '', |
|
31 | + 'icon' => '', |
|
32 | + 'hover_content' => '', |
|
33 | + 'hover_icon' => '', |
|
34 | + 'new_line_after' => true, |
|
35 | + 'no_wrap' => true, |
|
36 | + 'onclick' => '', |
|
37 | + 'style' => '', |
|
38 | + 'extra_attributes' => array(), // an array of extra attributes |
|
39 | + 'icon_extra_attributes' => array() // an array of icon extra attributes |
|
40 | + ); |
|
41 | + |
|
42 | + /** |
|
43 | 43 | * Parse incoming $args into an array and merge it with $defaults |
44 | 44 | */ |
45 | - $args = wp_parse_args( $args, $defaults ); |
|
46 | - $output = ''; |
|
47 | - if ( ! empty( $args['type'] ) ) { |
|
48 | - $type = $args['type'] != 'a' ? esc_attr($args['type']) : 'a'; |
|
49 | - |
|
50 | - // open/type |
|
51 | - if($type=='a'){ |
|
52 | - $new_window = !empty($args['new_window']) ? ' target="_blank" ' : ''; |
|
53 | - $output .= '<a href="' . $args['href'] . '"'.$new_window; |
|
54 | - }elseif($type=='badge'){ |
|
55 | - $output .= '<span '; |
|
56 | - }else{ |
|
57 | - $output .= '<button type="' . $type . '" '; |
|
58 | - } |
|
59 | - |
|
60 | - // name |
|
61 | - if(!empty($args['name'])){ |
|
62 | - $output .= AUI_Component_Helper::name($args['name']); |
|
63 | - } |
|
64 | - |
|
65 | - // id |
|
66 | - if(!empty($args['id'])){ |
|
67 | - $output .= AUI_Component_Helper::id($args['id']); |
|
68 | - } |
|
69 | - |
|
70 | - // title |
|
71 | - if(!empty($args['title'])){ |
|
72 | - $output .= AUI_Component_Helper::title($args['title']); |
|
73 | - } |
|
74 | - |
|
75 | - // value |
|
76 | - if(!empty($args['value'])){ |
|
77 | - $output .= AUI_Component_Helper::value($args['value']); |
|
78 | - } |
|
79 | - |
|
80 | - // class |
|
81 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
82 | - $output .= AUI_Component_Helper::class_attr($class); |
|
45 | + $args = wp_parse_args( $args, $defaults ); |
|
46 | + $output = ''; |
|
47 | + if ( ! empty( $args['type'] ) ) { |
|
48 | + $type = $args['type'] != 'a' ? esc_attr($args['type']) : 'a'; |
|
49 | + |
|
50 | + // open/type |
|
51 | + if($type=='a'){ |
|
52 | + $new_window = !empty($args['new_window']) ? ' target="_blank" ' : ''; |
|
53 | + $output .= '<a href="' . $args['href'] . '"'.$new_window; |
|
54 | + }elseif($type=='badge'){ |
|
55 | + $output .= '<span '; |
|
56 | + }else{ |
|
57 | + $output .= '<button type="' . $type . '" '; |
|
58 | + } |
|
59 | + |
|
60 | + // name |
|
61 | + if(!empty($args['name'])){ |
|
62 | + $output .= AUI_Component_Helper::name($args['name']); |
|
63 | + } |
|
64 | + |
|
65 | + // id |
|
66 | + if(!empty($args['id'])){ |
|
67 | + $output .= AUI_Component_Helper::id($args['id']); |
|
68 | + } |
|
69 | + |
|
70 | + // title |
|
71 | + if(!empty($args['title'])){ |
|
72 | + $output .= AUI_Component_Helper::title($args['title']); |
|
73 | + } |
|
74 | + |
|
75 | + // value |
|
76 | + if(!empty($args['value'])){ |
|
77 | + $output .= AUI_Component_Helper::value($args['value']); |
|
78 | + } |
|
79 | + |
|
80 | + // class |
|
81 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
82 | + $output .= AUI_Component_Helper::class_attr($class); |
|
83 | 83 | |
84 | - // data-attributes |
|
85 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
84 | + // data-attributes |
|
85 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
86 | 86 | |
87 | - // aria-attributes |
|
88 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
87 | + // aria-attributes |
|
88 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
89 | 89 | |
90 | - // extra attributes |
|
91 | - if(!empty($args['extra_attributes'])){ |
|
92 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
93 | - } |
|
90 | + // extra attributes |
|
91 | + if(!empty($args['extra_attributes'])){ |
|
92 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
93 | + } |
|
94 | 94 | |
95 | - // onclick, we don't escape this |
|
96 | - if(!empty($args['onclick'])){ |
|
97 | - $output .= ' onclick="'.$args['onclick'].'" '; |
|
98 | - } |
|
95 | + // onclick, we don't escape this |
|
96 | + if(!empty($args['onclick'])){ |
|
97 | + $output .= ' onclick="'.$args['onclick'].'" '; |
|
98 | + } |
|
99 | 99 | |
100 | - // style, we don't escape this |
|
101 | - if(!empty($args['style'])){ |
|
102 | - $output .= ' style="'.$args['style'].'" '; |
|
103 | - } |
|
100 | + // style, we don't escape this |
|
101 | + if(!empty($args['style'])){ |
|
102 | + $output .= ' style="'.$args['style'].'" '; |
|
103 | + } |
|
104 | 104 | |
105 | - // close opening tag |
|
106 | - $output .= ' >'; |
|
105 | + // close opening tag |
|
106 | + $output .= ' >'; |
|
107 | 107 | |
108 | 108 | |
109 | - // hover content |
|
110 | - $hover_content = false; |
|
111 | - if(!empty($args['hover_content']) || !empty($args['hover_icon'])){ |
|
112 | - $output .= "<span class='hover-content'>".AUI_Component_Helper::icon($args['hover_icon'],$args['hover_content']).$args['hover_content']."</span>"; |
|
113 | - $hover_content = true; |
|
114 | - } |
|
109 | + // hover content |
|
110 | + $hover_content = false; |
|
111 | + if(!empty($args['hover_content']) || !empty($args['hover_icon'])){ |
|
112 | + $output .= "<span class='hover-content'>".AUI_Component_Helper::icon($args['hover_icon'],$args['hover_content']).$args['hover_content']."</span>"; |
|
113 | + $hover_content = true; |
|
114 | + } |
|
115 | 115 | |
116 | - // content |
|
117 | - if($hover_content){$output .= "<span class='hover-content-original'>";} |
|
118 | - if(!empty($args['content']) || !empty($args['icon'])){ |
|
119 | - $output .= AUI_Component_Helper::icon($args['icon'],$args['content'],$args['icon_extra_attributes']).$args['content']; |
|
120 | - } |
|
121 | - if($hover_content){$output .= "</span>";} |
|
116 | + // content |
|
117 | + if($hover_content){$output .= "<span class='hover-content-original'>";} |
|
118 | + if(!empty($args['content']) || !empty($args['icon'])){ |
|
119 | + $output .= AUI_Component_Helper::icon($args['icon'],$args['content'],$args['icon_extra_attributes']).$args['content']; |
|
120 | + } |
|
121 | + if($hover_content){$output .= "</span>";} |
|
122 | 122 | |
123 | 123 | |
124 | 124 | |
125 | - // close |
|
126 | - if($type=='a'){ |
|
127 | - $output .= '</a>'; |
|
128 | - }elseif($type=='badge'){ |
|
129 | - $output .= '</span>'; |
|
130 | - }else{ |
|
131 | - $output .= '</button>'; |
|
132 | - } |
|
125 | + // close |
|
126 | + if($type=='a'){ |
|
127 | + $output .= '</a>'; |
|
128 | + }elseif($type=='badge'){ |
|
129 | + $output .= '</span>'; |
|
130 | + }else{ |
|
131 | + $output .= '</button>'; |
|
132 | + } |
|
133 | 133 | |
134 | - // maybe new line after? This adds better spacing between buttons. |
|
135 | - if(!empty($args['new_line_after'])){ |
|
136 | - $output .= PHP_EOL; |
|
137 | - } |
|
134 | + // maybe new line after? This adds better spacing between buttons. |
|
135 | + if(!empty($args['new_line_after'])){ |
|
136 | + $output .= PHP_EOL; |
|
137 | + } |
|
138 | 138 | |
139 | 139 | |
140 | - // wrap |
|
141 | - if(!$args['no_wrap']){ |
|
142 | - $output = AUI_Component_Input::wrap(array( |
|
143 | - 'content' => $output, |
|
144 | - )); |
|
145 | - } |
|
140 | + // wrap |
|
141 | + if(!$args['no_wrap']){ |
|
142 | + $output = AUI_Component_Input::wrap(array( |
|
143 | + 'content' => $output, |
|
144 | + )); |
|
145 | + } |
|
146 | 146 | |
147 | 147 | |
148 | - } |
|
148 | + } |
|
149 | 149 | |
150 | - return $output; |
|
151 | - } |
|
150 | + return $output; |
|
151 | + } |
|
152 | 152 | |
153 | 153 | } |
154 | 154 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | - exit; // Exit if accessed directly |
|
3 | + if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @since 1.0.0 |
11 | 11 | */ |
12 | -class AUI_Component_Helper { |
|
12 | + class AUI_Component_Helper { |
|
13 | 13 | |
14 | - /** |
|
14 | + /** |
|
15 | 15 | * A component helper for generating a input name. |
16 | 16 | * |
17 | 17 | * @param $text |
@@ -19,152 +19,152 @@ discard block |
||
19 | 19 | * |
20 | 20 | * @return string |
21 | 21 | */ |
22 | - public static function name( $text, $multiple = false ) { |
|
23 | - $output = ''; |
|
22 | + public static function name( $text, $multiple = false ) { |
|
23 | + $output = ''; |
|
24 | 24 | |
25 | - if ( $text ) { |
|
26 | - $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | - $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | - } |
|
25 | + if ( $text ) { |
|
26 | + $is_multiple = strpos( $text, '[' ) === false && $multiple ? '[]' : ''; |
|
27 | + $output = ' name="' . esc_attr( $text ) . $is_multiple . '" '; |
|
28 | + } |
|
29 | 29 | |
30 | - return $output; |
|
31 | - } |
|
30 | + return $output; |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
33 | + /** |
|
34 | 34 | * A component helper for generating a item id. |
35 | 35 | * |
36 | 36 | * @param $text string The text to be used as the value. |
37 | 37 | * |
38 | 38 | * @return string The sanitized item. |
39 | 39 | */ |
40 | - public static function id( $text ) { |
|
41 | - $output = ''; |
|
40 | + public static function id( $text ) { |
|
41 | + $output = ''; |
|
42 | 42 | |
43 | - if ( $text ) { |
|
44 | - $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | - } |
|
43 | + if ( $text ) { |
|
44 | + $output = ' id="' . sanitize_html_class( $text ) . '" '; |
|
45 | + } |
|
46 | 46 | |
47 | - return $output; |
|
48 | - } |
|
47 | + return $output; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
50 | + /** |
|
51 | 51 | * A component helper for generating a item title. |
52 | 52 | * |
53 | 53 | * @param $text string The text to be used as the value. |
54 | 54 | * |
55 | 55 | * @return string The sanitized item. |
56 | 56 | */ |
57 | - public static function title( $text ) { |
|
58 | - $output = ''; |
|
57 | + public static function title( $text ) { |
|
58 | + $output = ''; |
|
59 | 59 | |
60 | - if ( $text ) { |
|
61 | - $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | - } |
|
60 | + if ( $text ) { |
|
61 | + $output = ' title="' . esc_attr( $text ) . '" '; |
|
62 | + } |
|
63 | 63 | |
64 | - return $output; |
|
65 | - } |
|
64 | + return $output; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
67 | + /** |
|
68 | 68 | * A component helper for generating a item value. |
69 | 69 | * |
70 | 70 | * @param $text string The text to be used as the value. |
71 | 71 | * |
72 | 72 | * @return string The sanitized item. |
73 | 73 | */ |
74 | - public static function value( $text ) { |
|
75 | - $output = ''; |
|
74 | + public static function value( $text ) { |
|
75 | + $output = ''; |
|
76 | 76 | |
77 | - if ( $text !== null && $text !== false ) { |
|
78 | - $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | - } |
|
77 | + if ( $text !== null && $text !== false ) { |
|
78 | + $output = ' value="' . esc_attr( wp_unslash( $text ) ) . '" '; |
|
79 | + } |
|
80 | 80 | |
81 | - return $output; |
|
82 | - } |
|
81 | + return $output; |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
84 | + /** |
|
85 | 85 | * A component helper for generating a item class attribute. |
86 | 86 | * |
87 | 87 | * @param $text string The text to be used as the value. |
88 | 88 | * |
89 | 89 | * @return string The sanitized item. |
90 | 90 | */ |
91 | - public static function class_attr( $text ) { |
|
92 | - $output = ''; |
|
91 | + public static function class_attr( $text ) { |
|
92 | + $output = ''; |
|
93 | 93 | |
94 | - if ( $text ) { |
|
95 | - $classes = self::esc_classes( $text ); |
|
96 | - if ( ! empty( $classes ) ) { |
|
97 | - $output = ' class="' . $classes . '" '; |
|
98 | - } |
|
99 | - } |
|
94 | + if ( $text ) { |
|
95 | + $classes = self::esc_classes( $text ); |
|
96 | + if ( ! empty( $classes ) ) { |
|
97 | + $output = ' class="' . $classes . '" '; |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | - return $output; |
|
102 | - } |
|
101 | + return $output; |
|
102 | + } |
|
103 | 103 | |
104 | - /** |
|
104 | + /** |
|
105 | 105 | * Escape a string of classes. |
106 | 106 | * |
107 | 107 | * @param $text |
108 | 108 | * |
109 | 109 | * @return string |
110 | 110 | */ |
111 | - public static function esc_classes( $text ) { |
|
112 | - $output = ''; |
|
111 | + public static function esc_classes( $text ) { |
|
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 ); |
|
120 | - } |
|
121 | - } |
|
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 | 122 | |
123 | - return $output; |
|
123 | + return $output; |
|
124 | 124 | |
125 | - } |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
127 | + /** |
|
128 | 128 | * @param $args |
129 | 129 | * |
130 | 130 | * @return string |
131 | 131 | */ |
132 | - public static function data_attributes( $args ) { |
|
133 | - $output = ''; |
|
132 | + public static function data_attributes( $args ) { |
|
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 ) . '" '; |
|
140 | - } |
|
141 | - } |
|
142 | - } |
|
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 | 143 | |
144 | - return $output; |
|
145 | - } |
|
144 | + return $output; |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
147 | + /** |
|
148 | 148 | * @param $args |
149 | 149 | * |
150 | 150 | * @return string |
151 | 151 | */ |
152 | - public static function aria_attributes( $args ) { |
|
153 | - $output = ''; |
|
152 | + public static function aria_attributes( $args ) { |
|
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 ) . '" '; |
|
160 | - } |
|
161 | - } |
|
162 | - } |
|
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 | 163 | |
164 | - return $output; |
|
165 | - } |
|
164 | + return $output; |
|
165 | + } |
|
166 | 166 | |
167 | - /** |
|
167 | + /** |
|
168 | 168 | * Build a font awesome icon from a class. |
169 | 169 | * |
170 | 170 | * @param $class |
@@ -173,91 +173,91 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @return string |
175 | 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 | - /** |
|
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 | 198 | * @param $args |
199 | 199 | * |
200 | 200 | * @return string |
201 | 201 | */ |
202 | - public static function extra_attributes( $args ) { |
|
203 | - $output = ''; |
|
202 | + public static function extra_attributes( $args ) { |
|
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 ) . '" '; |
|
210 | - } |
|
211 | - } else { |
|
212 | - $output .= ' ' . $args . ' '; |
|
213 | - } |
|
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 | 214 | |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - return $output; |
|
218 | - } |
|
217 | + return $output; |
|
218 | + } |
|
219 | 219 | |
220 | - /** |
|
220 | + /** |
|
221 | 221 | * @param $args |
222 | 222 | * |
223 | 223 | * @return string |
224 | 224 | */ |
225 | - public static function help_text( $text ) { |
|
226 | - $output = ''; |
|
225 | + public static function help_text( $text ) { |
|
226 | + $output = ''; |
|
227 | 227 | |
228 | - if ( $text ) { |
|
229 | - $output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>'; |
|
230 | - } |
|
228 | + if ( $text ) { |
|
229 | + $output .= '<small class="form-text text-muted d-block">' . wp_kses_post( $text ) . '</small>'; |
|
230 | + } |
|
231 | 231 | |
232 | 232 | |
233 | - return $output; |
|
234 | - } |
|
233 | + return $output; |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
236 | + /** |
|
237 | 237 | * Replace element require context with JS. |
238 | 238 | * |
239 | 239 | * @param $input |
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( |
|
248 | - "jQuery(form).find('[data-argument=\"", |
|
249 | - "\"]').find('input,select,textarea').val()", |
|
250 | - "\"]').find('input:checked').val()", |
|
251 | - ), $input ) ); |
|
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 | 252 | |
253 | - if ( $output ) { |
|
254 | - $output = ' data-element-require="' . $output . '" '; |
|
255 | - } |
|
253 | + if ( $output ) { |
|
254 | + $output = ' data-element-require="' . $output . '" '; |
|
255 | + } |
|
256 | 256 | |
257 | - return $output; |
|
258 | - } |
|
257 | + return $output; |
|
258 | + } |
|
259 | 259 | |
260 | - /** |
|
260 | + /** |
|
261 | 261 | * Navigates through an array, object, or scalar, and removes slashes from the values. |
262 | 262 | * |
263 | 263 | * @since 0.1.41 |
@@ -267,24 +267,24 @@ discard block |
||
267 | 267 | * |
268 | 268 | * @return mixed Stripped value. |
269 | 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 | - /** |
|
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 | 288 | * Filters content and keeps only allowable HTML elements. |
289 | 289 | * |
290 | 290 | * @since 0.1.41 |
@@ -293,10 +293,10 @@ 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 ); |
|
297 | - } |
|
296 | + return apply_filters( 'ayecode_ui_sanitize_html_field', $value, $original, $input ); |
|
297 | + } |
|
298 | 298 | |
299 | - /** |
|
299 | + /** |
|
300 | 300 | * Filters content and keeps only allowable HTML elements. |
301 | 301 | * |
302 | 302 | * This function makes sure that only the allowed HTML element names, attribute |
@@ -316,25 +316,25 @@ 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 === '' ) { |
|
321 | - return $value; |
|
322 | - } |
|
319 | + public static function _sanitize_html_field( $value, $input = array() ) { |
|
320 | + if ( $value === '' ) { |
|
321 | + return $value; |
|
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' ); |
|
328 | - } |
|
326 | + if ( ! is_array( $allowed_html ) ) { |
|
327 | + $allowed_html = wp_kses_allowed_html( 'post' ); |
|
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 | - return $filtered; |
|
335 | - } |
|
334 | + return $filtered; |
|
335 | + } |
|
336 | 336 | |
337 | - /** |
|
337 | + /** |
|
338 | 338 | * Returns an array of allowed HTML tags and attributes for a given context. |
339 | 339 | * |
340 | 340 | * @since 0.1.41 |
@@ -346,32 +346,32 @@ 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 ); |
|
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 | - /** |
|
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 | 375 | * Filters the allowed html tags. |
376 | 376 | * |
377 | 377 | * @since 0.1.41 |
@@ -380,30 +380,30 @@ 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 ); |
|
384 | - } |
|
383 | + return apply_filters( 'ayecode_ui_kses_allowed_html', $allowed_html, $context, $input ); |
|
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 | - $class = ''; |
|
388 | + $class = ''; |
|
389 | 389 | |
390 | - // set default if empty |
|
391 | - if( $label_number === '' ){ |
|
392 | - $label_number = 2; |
|
393 | - } |
|
390 | + // set default if empty |
|
391 | + if( $label_number === '' ){ |
|
392 | + $label_number = 2; |
|
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 ) ); |
|
400 | - } |
|
401 | - } |
|
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 | 402 | |
403 | - return $class; |
|
404 | - } |
|
403 | + return $class; |
|
404 | + } |
|
405 | 405 | |
406 | - /** |
|
406 | + /** |
|
407 | 407 | * Sanitizes a multiline string from user input or from the database. |
408 | 408 | * |
409 | 409 | * Emulate the WP native sanitize_textarea_field function in a %%variable%% safe way. |
@@ -415,10 +415,10 @@ discard block |
||
415 | 415 | * @param string $str String to sanitize. |
416 | 416 | * @return string Sanitized string. |
417 | 417 | */ |
418 | - public static function sanitize_textarea_field( $str ) { |
|
419 | - $filtered = self::_sanitize_text_fields( $str, true ); |
|
418 | + public static function sanitize_textarea_field( $str ) { |
|
419 | + $filtered = self::_sanitize_text_fields( $str, true ); |
|
420 | 420 | |
421 | - /** |
|
421 | + /** |
|
422 | 422 | * Filters a sanitized textarea field string. |
423 | 423 | * |
424 | 424 | * @see https://core.trac.wordpress.org/browser/trunk/src/wp-includes/formatting.php |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | * @param string $filtered The sanitized string. |
427 | 427 | * @param string $str The string prior to being sanitized. |
428 | 428 | */ |
429 | - return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
430 | - } |
|
429 | + return apply_filters( 'sanitize_textarea_field', $filtered, $str ); |
|
430 | + } |
|
431 | 431 | |
432 | - /** |
|
432 | + /** |
|
433 | 433 | * Internal helper function to sanitize a string from user input or from the db. |
434 | 434 | * |
435 | 435 | * @since 0.1.66 |
@@ -439,42 +439,42 @@ discard block |
||
439 | 439 | * @param bool $keep_newlines Optional. Whether to keep newlines. Default: false. |
440 | 440 | * @return string Sanitized string. |
441 | 441 | */ |
442 | - public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
443 | - if ( is_object( $str ) || is_array( $str ) ) { |
|
444 | - return ''; |
|
445 | - } |
|
446 | - |
|
447 | - $str = (string) $str; |
|
448 | - |
|
449 | - $filtered = wp_check_invalid_utf8( $str ); |
|
450 | - |
|
451 | - if ( strpos( $filtered, '<' ) !== false ) { |
|
452 | - $filtered = wp_pre_kses_less_than( $filtered ); |
|
453 | - // This will strip extra whitespace for us. |
|
454 | - $filtered = wp_strip_all_tags( $filtered, false ); |
|
455 | - |
|
456 | - // Use HTML entities in a special case to make sure no later |
|
457 | - // newline stripping stage could lead to a functional tag. |
|
458 | - $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
459 | - } |
|
460 | - |
|
461 | - if ( ! $keep_newlines ) { |
|
462 | - $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
463 | - } |
|
464 | - $filtered = trim( $filtered ); |
|
465 | - |
|
466 | - $found = false; |
|
467 | - while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
468 | - $filtered = str_replace( $match[1], '', $filtered ); |
|
469 | - $found = true; |
|
470 | - } |
|
471 | - unset( $match ); |
|
472 | - |
|
473 | - if ( $found ) { |
|
474 | - // Strip out the whitespace that may now exist after removing the octets. |
|
475 | - $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
476 | - } |
|
477 | - |
|
478 | - return $filtered; |
|
479 | - } |
|
442 | + public static function _sanitize_text_fields( $str, $keep_newlines = false ) { |
|
443 | + if ( is_object( $str ) || is_array( $str ) ) { |
|
444 | + return ''; |
|
445 | + } |
|
446 | + |
|
447 | + $str = (string) $str; |
|
448 | + |
|
449 | + $filtered = wp_check_invalid_utf8( $str ); |
|
450 | + |
|
451 | + if ( strpos( $filtered, '<' ) !== false ) { |
|
452 | + $filtered = wp_pre_kses_less_than( $filtered ); |
|
453 | + // This will strip extra whitespace for us. |
|
454 | + $filtered = wp_strip_all_tags( $filtered, false ); |
|
455 | + |
|
456 | + // Use HTML entities in a special case to make sure no later |
|
457 | + // newline stripping stage could lead to a functional tag. |
|
458 | + $filtered = str_replace( "<\n", "<\n", $filtered ); |
|
459 | + } |
|
460 | + |
|
461 | + if ( ! $keep_newlines ) { |
|
462 | + $filtered = preg_replace( '/[\r\n\t ]+/', ' ', $filtered ); |
|
463 | + } |
|
464 | + $filtered = trim( $filtered ); |
|
465 | + |
|
466 | + $found = false; |
|
467 | + while ( preg_match( '`[^%](%[a-f0-9]{2})`i', $filtered, $match ) ) { |
|
468 | + $filtered = str_replace( $match[1], '', $filtered ); |
|
469 | + $found = true; |
|
470 | + } |
|
471 | + unset( $match ); |
|
472 | + |
|
473 | + if ( $found ) { |
|
474 | + // Strip out the whitespace that may now exist after removing the octets. |
|
475 | + $filtered = trim( preg_replace( '` +`', ' ', $filtered ) ); |
|
476 | + } |
|
477 | + |
|
478 | + return $filtered; |
|
479 | + } |
|
480 | 480 | } |
481 | 481 | \ No newline at end of file |
@@ -577,40 +577,40 @@ discard block |
||
577 | 577 | |
578 | 578 | switch ( $key ) { |
579 | 579 | |
580 | - case 'total': |
|
581 | - echo '<strong>'; |
|
582 | - wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
583 | - echo '</strong>'; |
|
584 | - break; |
|
585 | - |
|
586 | - case 'relationship': |
|
587 | - echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
588 | - break; |
|
589 | - |
|
590 | - case 'date': |
|
591 | - echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
592 | - break; |
|
593 | - |
|
594 | - case 'status': |
|
595 | - $status = $payment->get_status_nicename(); |
|
596 | - if ( is_admin() ) { |
|
597 | - $status = $payment->get_status_label_html(); |
|
598 | - } |
|
599 | - |
|
600 | - echo wp_kses_post( $status ); |
|
601 | - break; |
|
602 | - |
|
603 | - case 'invoice': |
|
604 | - if ( ! is_admin() ) { |
|
605 | - $link = $payment->get_view_url(); |
|
606 | - } else { |
|
607 | - $link = get_edit_post_link( $payment->get_id() ); |
|
608 | - } |
|
609 | - |
|
610 | - $invoice = esc_html( $payment->get_number() ); |
|
611 | - |
|
612 | - echo wp_kses_post( "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$invoice</a>" ); |
|
613 | - break; |
|
580 | + case 'total': |
|
581 | + echo '<strong>'; |
|
582 | + wpinv_the_price( $payment->get_total(), $payment->get_currency() ); |
|
583 | + echo '</strong>'; |
|
584 | + break; |
|
585 | + |
|
586 | + case 'relationship': |
|
587 | + echo $payment->is_renewal() ? esc_html__( 'Renewal Invoice', 'invoicing' ) : esc_html__( 'Initial Invoice', 'invoicing' ); |
|
588 | + break; |
|
589 | + |
|
590 | + case 'date': |
|
591 | + echo esc_html( getpaid_format_date_value( $payment->get_date_created() ) ); |
|
592 | + break; |
|
593 | + |
|
594 | + case 'status': |
|
595 | + $status = $payment->get_status_nicename(); |
|
596 | + if ( is_admin() ) { |
|
597 | + $status = $payment->get_status_label_html(); |
|
598 | + } |
|
599 | + |
|
600 | + echo wp_kses_post( $status ); |
|
601 | + break; |
|
602 | + |
|
603 | + case 'invoice': |
|
604 | + if ( ! is_admin() ) { |
|
605 | + $link = $payment->get_view_url(); |
|
606 | + } else { |
|
607 | + $link = get_edit_post_link( $payment->get_id() ); |
|
608 | + } |
|
609 | + |
|
610 | + $invoice = esc_html( $payment->get_number() ); |
|
611 | + |
|
612 | + echo wp_kses_post( "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$invoice</a>" ); |
|
613 | + break; |
|
614 | 614 | } |
615 | 615 | |
616 | 616 | echo '</td>'; |
@@ -705,37 +705,37 @@ discard block |
||
705 | 705 | |
706 | 706 | switch ( $key ) { |
707 | 707 | |
708 | - case 'item_name': |
|
709 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
710 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
708 | + case 'item_name': |
|
709 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
710 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
711 | 711 | |
712 | - if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
713 | - echo esc_html( $item_name ); |
|
714 | - } else { |
|
715 | - printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
716 | - } |
|
712 | + if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) { |
|
713 | + echo esc_html( $item_name ); |
|
714 | + } else { |
|
715 | + printf( '%1$s x %2$d', esc_html( $item_name ), (float) $subscription_group_item['quantity'] ); |
|
716 | + } |
|
717 | 717 | |
718 | - break; |
|
718 | + break; |
|
719 | 719 | |
720 | - case 'price': |
|
721 | - wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
722 | - break; |
|
720 | + case 'price': |
|
721 | + wpinv_the_price( $subscription_group_item['item_price'], $invoice->get_currency() ); |
|
722 | + break; |
|
723 | 723 | |
724 | - case 'tax': |
|
725 | - wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
726 | - break; |
|
724 | + case 'tax': |
|
725 | + wpinv_the_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
726 | + break; |
|
727 | 727 | |
728 | - case 'discount': |
|
729 | - wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
730 | - break; |
|
728 | + case 'discount': |
|
729 | + wpinv_the_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
730 | + break; |
|
731 | 731 | |
732 | - case 'initial': |
|
733 | - wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
734 | - break; |
|
732 | + case 'initial': |
|
733 | + wpinv_the_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ); |
|
734 | + break; |
|
735 | 735 | |
736 | - case 'recurring': |
|
737 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
738 | - break; |
|
736 | + case 'recurring': |
|
737 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>' ); |
|
738 | + break; |
|
739 | 739 | |
740 | 740 | } |
741 | 741 | |
@@ -759,29 +759,29 @@ discard block |
||
759 | 759 | |
760 | 760 | switch ( $key ) { |
761 | 761 | |
762 | - case 'item_name': |
|
763 | - echo esc_html( $subscription_group_fee['name'] ); |
|
764 | - break; |
|
762 | + case 'item_name': |
|
763 | + echo esc_html( $subscription_group_fee['name'] ); |
|
764 | + break; |
|
765 | 765 | |
766 | - case 'price': |
|
767 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
768 | - break; |
|
766 | + case 'price': |
|
767 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
768 | + break; |
|
769 | 769 | |
770 | - case 'tax': |
|
771 | - echo '—'; |
|
772 | - break; |
|
770 | + case 'tax': |
|
771 | + echo '—'; |
|
772 | + break; |
|
773 | 773 | |
774 | - case 'discount': |
|
775 | - echo '—'; |
|
776 | - break; |
|
774 | + case 'discount': |
|
775 | + echo '—'; |
|
776 | + break; |
|
777 | 777 | |
778 | - case 'initial': |
|
779 | - wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
780 | - break; |
|
778 | + case 'initial': |
|
779 | + wpinv_the_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() ); |
|
780 | + break; |
|
781 | 781 | |
782 | - case 'recurring': |
|
783 | - echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
784 | - break; |
|
782 | + case 'recurring': |
|
783 | + echo wp_kses_post( '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>' ); |
|
784 | + break; |
|
785 | 785 | |
786 | 786 | } |
787 | 787 | |
@@ -886,39 +886,39 @@ discard block |
||
886 | 886 | |
887 | 887 | switch ( $key ) { |
888 | 888 | |
889 | - case 'status': |
|
890 | - echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
891 | - break; |
|
892 | - |
|
893 | - case 'item': |
|
894 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
895 | - echo wp_kses_post( implode( ' | ', $markup ) ); |
|
896 | - break; |
|
897 | - |
|
898 | - case 'renewals': |
|
899 | - $max_bills = $_suscription->get_bill_times(); |
|
900 | - echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
901 | - break; |
|
902 | - |
|
903 | - case 'renewal_date': |
|
904 | - echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
905 | - break; |
|
906 | - |
|
907 | - case 'start_date': |
|
908 | - echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
909 | - break; |
|
910 | - |
|
911 | - case 'subscription': |
|
912 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
913 | - printf( |
|
914 | - '%1$s#%2$s%3$s', |
|
915 | - '<a href="' . esc_url( $url ) . '">', |
|
916 | - '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
917 | - '</a>' |
|
918 | - ); |
|
919 | - |
|
920 | - echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
921 | - break; |
|
889 | + case 'status': |
|
890 | + echo wp_kses_post( $_suscription->get_status_label_html() ); |
|
891 | + break; |
|
892 | + |
|
893 | + case 'item': |
|
894 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
895 | + echo wp_kses_post( implode( ' | ', $markup ) ); |
|
896 | + break; |
|
897 | + |
|
898 | + case 'renewals': |
|
899 | + $max_bills = $_suscription->get_bill_times(); |
|
900 | + echo ( (int) $_suscription->get_times_billed() ) . ' / ' . ( empty( $max_bills ) ? '∞' : (int) $max_bills ); |
|
901 | + break; |
|
902 | + |
|
903 | + case 'renewal_date': |
|
904 | + echo $_suscription->is_active() ? esc_html( getpaid_format_date_value( $_suscription->get_expiration() ) ) : '—'; |
|
905 | + break; |
|
906 | + |
|
907 | + case 'start_date': |
|
908 | + echo 'pending' == $_suscription->get_status() ? '—' : esc_html( getpaid_format_date_value( $_suscription->get_date_created() ) ); |
|
909 | + break; |
|
910 | + |
|
911 | + case 'subscription': |
|
912 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
913 | + printf( |
|
914 | + '%1$s#%2$s%3$s', |
|
915 | + '<a href="' . esc_url( $url ) . '">', |
|
916 | + '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
917 | + '</a>' |
|
918 | + ); |
|
919 | + |
|
920 | + echo wp_kses_post( WPInv_Subscriptions_List_Table::column_amount( $_suscription ) ); |
|
921 | + break; |
|
922 | 922 | |
923 | 923 | } |
924 | 924 |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php |
|
1 | + <?php |
|
2 | 2 | |
3 | -if ( ! defined( 'ABSPATH' ) ) { |
|
4 | - exit; // Exit if accessed directly |
|
3 | + if ( ! defined( 'ABSPATH' ) ) { |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -9,1307 +9,1307 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @since 1.0.0 |
11 | 11 | */ |
12 | -class AUI_Component_Input { |
|
12 | + class AUI_Component_Input { |
|
13 | 13 | |
14 | - /** |
|
14 | + /** |
|
15 | 15 | * Build the component. |
16 | 16 | * |
17 | 17 | * @param array $args |
18 | 18 | * |
19 | 19 | * @return string The rendered component. |
20 | 20 | */ |
21 | - public static function input( $args = array() ) { |
|
22 | - global $aui_bs5; |
|
23 | - |
|
24 | - $defaults = array( |
|
25 | - 'type' => 'text', |
|
26 | - 'name' => '', |
|
27 | - 'class' => '', |
|
28 | - 'wrap_class' => '', |
|
29 | - 'id' => '', |
|
30 | - 'placeholder' => '', |
|
31 | - 'title' => '', |
|
32 | - 'value' => '', |
|
33 | - 'required' => false, |
|
34 | - 'size' => '', // sm, lg, small, large |
|
35 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
36 | - 'with_hidden' => false, // Append hidden field for single checkbox. |
|
37 | - 'label' => '', |
|
38 | - 'label_after' => false, |
|
39 | - 'label_class' => '', |
|
40 | - 'label_col' => '2', |
|
41 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
42 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
43 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
44 | - 'help_text' => '', |
|
45 | - 'validation_text' => '', |
|
46 | - 'validation_pattern' => '', |
|
47 | - 'no_wrap' => false, |
|
48 | - 'input_group_right' => '', |
|
49 | - 'input_group_left' => '', |
|
50 | - 'input_group_right_inside' => false, |
|
51 | - // forces the input group inside the input |
|
52 | - 'input_group_left_inside' => false, |
|
53 | - // forces the input group inside the input |
|
54 | - 'form_group_class' => '', |
|
55 | - 'step' => '', |
|
56 | - 'switch' => false, |
|
57 | - // to show checkbox as a switch |
|
58 | - 'checked' => false, |
|
59 | - // set a checkbox or radio as selected |
|
60 | - 'password_toggle' => true, |
|
61 | - // toggle view/hide password |
|
62 | - 'element_require' => '', |
|
63 | - // [%element_id%] == "1" |
|
64 | - 'extra_attributes' => array(), |
|
65 | - // an array of extra attributes |
|
66 | - 'wrap_attributes' => array() |
|
67 | - ); |
|
68 | - |
|
69 | - /** |
|
21 | + public static function input( $args = array() ) { |
|
22 | + global $aui_bs5; |
|
23 | + |
|
24 | + $defaults = array( |
|
25 | + 'type' => 'text', |
|
26 | + 'name' => '', |
|
27 | + 'class' => '', |
|
28 | + 'wrap_class' => '', |
|
29 | + 'id' => '', |
|
30 | + 'placeholder' => '', |
|
31 | + 'title' => '', |
|
32 | + 'value' => '', |
|
33 | + 'required' => false, |
|
34 | + 'size' => '', // sm, lg, small, large |
|
35 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
36 | + 'with_hidden' => false, // Append hidden field for single checkbox. |
|
37 | + 'label' => '', |
|
38 | + 'label_after' => false, |
|
39 | + 'label_class' => '', |
|
40 | + 'label_col' => '2', |
|
41 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
42 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
43 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
44 | + 'help_text' => '', |
|
45 | + 'validation_text' => '', |
|
46 | + 'validation_pattern' => '', |
|
47 | + 'no_wrap' => false, |
|
48 | + 'input_group_right' => '', |
|
49 | + 'input_group_left' => '', |
|
50 | + 'input_group_right_inside' => false, |
|
51 | + // forces the input group inside the input |
|
52 | + 'input_group_left_inside' => false, |
|
53 | + // forces the input group inside the input |
|
54 | + 'form_group_class' => '', |
|
55 | + 'step' => '', |
|
56 | + 'switch' => false, |
|
57 | + // to show checkbox as a switch |
|
58 | + 'checked' => false, |
|
59 | + // set a checkbox or radio as selected |
|
60 | + 'password_toggle' => true, |
|
61 | + // toggle view/hide password |
|
62 | + 'element_require' => '', |
|
63 | + // [%element_id%] == "1" |
|
64 | + 'extra_attributes' => array(), |
|
65 | + // an array of extra attributes |
|
66 | + 'wrap_attributes' => array() |
|
67 | + ); |
|
68 | + |
|
69 | + /** |
|
70 | 70 | * Parse incoming $args into an array and merge it with $defaults |
71 | 71 | */ |
72 | - $args = wp_parse_args( $args, $defaults ); |
|
73 | - $output = ''; |
|
74 | - if ( ! empty( $args['type'] ) ) { |
|
75 | - // hidden label option needs to be empty |
|
76 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
77 | - |
|
78 | - $type = sanitize_html_class( $args['type'] ); |
|
79 | - |
|
80 | - $help_text = ''; |
|
81 | - $label = ''; |
|
82 | - $label_after = $args['label_after']; |
|
83 | - $label_args = array( |
|
84 | - 'title' => $args['label'], |
|
85 | - 'for' => $args['id'], |
|
86 | - 'class' => $args['label_class'] . " ", |
|
87 | - 'label_type' => $args['label_type'], |
|
88 | - 'label_col' => $args['label_col'] |
|
89 | - ); |
|
90 | - |
|
91 | - // floating labels need label after |
|
92 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
93 | - $label_after = true; |
|
94 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
95 | - } |
|
96 | - |
|
97 | - // size |
|
98 | - $size = ''; |
|
99 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
100 | - $size = 'lg'; |
|
101 | - $args['class'] .= ' form-control-lg'; |
|
102 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
103 | - $size = 'sm'; |
|
104 | - $args['class'] .= ' form-control-sm'; |
|
105 | - } |
|
106 | - |
|
107 | - // clear function |
|
108 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
109 | - |
|
110 | - // Some special sauce for files |
|
111 | - if ( $type == 'file' ) { |
|
112 | - $label_after = true; // if type file we need the label after |
|
113 | - $args['class'] .= ' custom-file-input '; |
|
114 | - } elseif ( $type == 'checkbox' ) { |
|
115 | - $label_after = true; // if type file we need the label after |
|
116 | - $args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer '; |
|
117 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
118 | - $orig_type = $type; |
|
119 | - $type = 'text'; |
|
120 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
121 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
122 | - |
|
123 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
124 | - |
|
125 | - // Disable native datetime inputs. |
|
126 | - $disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true'; |
|
127 | - $disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args ); |
|
128 | - |
|
129 | - $args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr; |
|
130 | - |
|
131 | - // set a way to clear field if empty |
|
132 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
133 | - $args['input_group_right_inside'] = true; |
|
134 | - $args['clear_icon'] = true; |
|
135 | - } |
|
136 | - |
|
137 | - // enqueue the script |
|
138 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
139 | - $aui_settings->enqueue_flatpickr(); |
|
140 | - } elseif ( $type == 'iconpicker' ) { |
|
141 | - $type = 'text'; |
|
142 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
143 | -// $args['class'] .= ' bg-initial '; |
|
144 | - |
|
145 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
146 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
147 | - |
|
148 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
149 | -// $args['input_group_right_inside'] = true; |
|
150 | - // enqueue the script |
|
151 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
152 | - $aui_settings->enqueue_iconpicker(); |
|
153 | - } |
|
154 | - |
|
155 | - if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
156 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
157 | - } |
|
158 | - |
|
159 | - // allow clear icon |
|
160 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
161 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
162 | - $args['input_group_right_inside'] = true; |
|
163 | - $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
164 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
165 | - } |
|
166 | - |
|
167 | - // open/type |
|
168 | - $output .= '<input type="' . $type . '" '; |
|
169 | - |
|
170 | - // name |
|
171 | - if ( ! empty( $args['name'] ) ) { |
|
172 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
173 | - } |
|
174 | - |
|
175 | - // id |
|
176 | - if ( ! empty( $args['id'] ) ) { |
|
177 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
178 | - } |
|
179 | - |
|
180 | - // placeholder |
|
181 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
182 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
183 | - } |
|
184 | - |
|
185 | - // title |
|
186 | - if ( ! empty( $args['title'] ) ) { |
|
187 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
188 | - } |
|
189 | - |
|
190 | - // value |
|
191 | - if ( ! empty( $args['value'] ) ) { |
|
192 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
193 | - } |
|
194 | - |
|
195 | - // checked, for radio and checkboxes |
|
196 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
197 | - $output .= ' checked '; |
|
198 | - } |
|
199 | - |
|
200 | - // validation text |
|
201 | - if ( ! empty( $args['validation_text'] ) ) { |
|
202 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
203 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
204 | - } |
|
205 | - |
|
206 | - // validation_pattern |
|
207 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
208 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
209 | - } |
|
210 | - |
|
211 | - // step (for numbers) |
|
212 | - if ( ! empty( $args['step'] ) ) { |
|
213 | - $output .= ' step="' . $args['step'] . '" '; |
|
214 | - } |
|
215 | - |
|
216 | - // required |
|
217 | - if ( ! empty( $args['required'] ) ) { |
|
218 | - $output .= ' required '; |
|
219 | - } |
|
220 | - |
|
221 | - // class |
|
222 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
223 | - $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
224 | - |
|
225 | - // data-attributes |
|
226 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
227 | - |
|
228 | - // extra attributes |
|
229 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
230 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
231 | - } |
|
232 | - |
|
233 | - // close |
|
234 | - $output .= ' >'; |
|
235 | - |
|
236 | - // help text |
|
237 | - if ( ! empty( $args['help_text'] ) ) { |
|
238 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
239 | - } |
|
240 | - |
|
241 | - // label |
|
242 | - if ( ! empty( $args['label'] ) ) { |
|
243 | - $label_base_class = ''; |
|
244 | - if ( $type == 'file' ) { |
|
245 | - $label_base_class = ' custom-file-label'; |
|
246 | - } elseif ( $type == 'checkbox' ) { |
|
247 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
248 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
249 | - $help_text = ''; |
|
250 | - //$label_args['class'] .= ' d-inline '; |
|
251 | - $args['wrap_class'] .= ' align-items-center '; |
|
252 | - }else{ |
|
253 | - |
|
254 | - } |
|
255 | - |
|
256 | - $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
257 | - } |
|
258 | - $label_args['class'] .= $label_base_class; |
|
259 | - $temp_label_args = $label_args; |
|
260 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
261 | - $label = self::label( $temp_label_args, $type ); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - // set help text in the correct position |
|
268 | - if ( $label_after ) { |
|
269 | - $output .= $label . $help_text; |
|
270 | - } |
|
271 | - |
|
272 | - // some input types need a separate wrap |
|
273 | - if ( $type == 'file' ) { |
|
274 | - $output = self::wrap( array( |
|
275 | - 'content' => $output, |
|
276 | - 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
277 | - ) ); |
|
278 | - } elseif ( $type == 'checkbox' ) { |
|
279 | - |
|
280 | - $label_args['title'] = $args['label']; |
|
281 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
282 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
283 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
284 | - if ( $aui_bs5 ) { |
|
285 | - $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
286 | - }else{ |
|
287 | - $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
288 | - } |
|
289 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
290 | - $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
291 | - $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
292 | - } |
|
293 | - $output = self::wrap( array( |
|
294 | - 'content' => $output, |
|
295 | - 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
296 | - ) ); |
|
297 | - |
|
298 | - if ( $args['label_type'] == 'horizontal' ) { |
|
299 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
300 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
301 | - } |
|
302 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
303 | - |
|
304 | - |
|
305 | - // allow password field to toggle view |
|
306 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
72 | + $args = wp_parse_args( $args, $defaults ); |
|
73 | + $output = ''; |
|
74 | + if ( ! empty( $args['type'] ) ) { |
|
75 | + // hidden label option needs to be empty |
|
76 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
77 | + |
|
78 | + $type = sanitize_html_class( $args['type'] ); |
|
79 | + |
|
80 | + $help_text = ''; |
|
81 | + $label = ''; |
|
82 | + $label_after = $args['label_after']; |
|
83 | + $label_args = array( |
|
84 | + 'title' => $args['label'], |
|
85 | + 'for' => $args['id'], |
|
86 | + 'class' => $args['label_class'] . " ", |
|
87 | + 'label_type' => $args['label_type'], |
|
88 | + 'label_col' => $args['label_col'] |
|
89 | + ); |
|
90 | + |
|
91 | + // floating labels need label after |
|
92 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
93 | + $label_after = true; |
|
94 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
95 | + } |
|
96 | + |
|
97 | + // size |
|
98 | + $size = ''; |
|
99 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
100 | + $size = 'lg'; |
|
101 | + $args['class'] .= ' form-control-lg'; |
|
102 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
103 | + $size = 'sm'; |
|
104 | + $args['class'] .= ' form-control-sm'; |
|
105 | + } |
|
106 | + |
|
107 | + // clear function |
|
108 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
109 | + |
|
110 | + // Some special sauce for files |
|
111 | + if ( $type == 'file' ) { |
|
112 | + $label_after = true; // if type file we need the label after |
|
113 | + $args['class'] .= ' custom-file-input '; |
|
114 | + } elseif ( $type == 'checkbox' ) { |
|
115 | + $label_after = true; // if type file we need the label after |
|
116 | + $args['class'] .= $aui_bs5 ? ' form-check-input c-pointer ' : ' custom-control-input c-pointer '; |
|
117 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
118 | + $orig_type = $type; |
|
119 | + $type = 'text'; |
|
120 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
121 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
122 | + |
|
123 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
124 | + |
|
125 | + // Disable native datetime inputs. |
|
126 | + $disable_mobile_attr = isset( $args['extra_attributes']['data-disable-mobile'] ) ? $args['extra_attributes']['data-disable-mobile'] : 'true'; |
|
127 | + $disable_mobile_attr = apply_filters( 'aui_flatpickr_disable_disable_mobile_attr', $disable_mobile_attr, $args ); |
|
128 | + |
|
129 | + $args['extra_attributes']['data-disable-mobile'] = $disable_mobile_attr; |
|
130 | + |
|
131 | + // set a way to clear field if empty |
|
132 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
133 | + $args['input_group_right_inside'] = true; |
|
134 | + $args['clear_icon'] = true; |
|
135 | + } |
|
136 | + |
|
137 | + // enqueue the script |
|
138 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
139 | + $aui_settings->enqueue_flatpickr(); |
|
140 | + } elseif ( $type == 'iconpicker' ) { |
|
141 | + $type = 'text'; |
|
142 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
143 | + // $args['class'] .= ' bg-initial '; |
|
144 | + |
|
145 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
146 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
147 | + |
|
148 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
149 | + // $args['input_group_right_inside'] = true; |
|
150 | + // enqueue the script |
|
151 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
152 | + $aui_settings->enqueue_iconpicker(); |
|
153 | + } |
|
154 | + |
|
155 | + if ( $type == 'checkbox' && ( ( ! empty( $args['name'] ) && strpos( $args['name'], '[' ) === false ) || ! empty( $args['with_hidden'] ) ) ) { |
|
156 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
157 | + } |
|
158 | + |
|
159 | + // allow clear icon |
|
160 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
161 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
162 | + $args['input_group_right_inside'] = true; |
|
163 | + $align_class = $aui_bs5 ? ' h-100 py-0' : ''; |
|
164 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none ' . $align_class . '" onclick="' . $clear_function . '"><span style="font-size: ' . $font_size . 'rem" aria-hidden="true" class="' . ( $aui_bs5 ? 'btn-close' : 'close' ) . '">' . ( $aui_bs5 ? '' : '×' ) . '</span></span>'; |
|
165 | + } |
|
166 | + |
|
167 | + // open/type |
|
168 | + $output .= '<input type="' . $type . '" '; |
|
169 | + |
|
170 | + // name |
|
171 | + if ( ! empty( $args['name'] ) ) { |
|
172 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
173 | + } |
|
174 | + |
|
175 | + // id |
|
176 | + if ( ! empty( $args['id'] ) ) { |
|
177 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
178 | + } |
|
179 | + |
|
180 | + // placeholder |
|
181 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
182 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
183 | + } |
|
184 | + |
|
185 | + // title |
|
186 | + if ( ! empty( $args['title'] ) ) { |
|
187 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
188 | + } |
|
189 | + |
|
190 | + // value |
|
191 | + if ( ! empty( $args['value'] ) ) { |
|
192 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
193 | + } |
|
194 | + |
|
195 | + // checked, for radio and checkboxes |
|
196 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
197 | + $output .= ' checked '; |
|
198 | + } |
|
199 | + |
|
200 | + // validation text |
|
201 | + if ( ! empty( $args['validation_text'] ) ) { |
|
202 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
203 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
204 | + } |
|
205 | + |
|
206 | + // validation_pattern |
|
207 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
208 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
209 | + } |
|
210 | + |
|
211 | + // step (for numbers) |
|
212 | + if ( ! empty( $args['step'] ) ) { |
|
213 | + $output .= ' step="' . $args['step'] . '" '; |
|
214 | + } |
|
215 | + |
|
216 | + // required |
|
217 | + if ( ! empty( $args['required'] ) ) { |
|
218 | + $output .= ' required '; |
|
219 | + } |
|
220 | + |
|
221 | + // class |
|
222 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
223 | + $output .= $aui_bs5 && $type == 'checkbox' ? ' class="' . $class . '" ' : ' class="form-control ' . $class . '" '; |
|
224 | + |
|
225 | + // data-attributes |
|
226 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
227 | + |
|
228 | + // extra attributes |
|
229 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
230 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
231 | + } |
|
232 | + |
|
233 | + // close |
|
234 | + $output .= ' >'; |
|
235 | + |
|
236 | + // help text |
|
237 | + if ( ! empty( $args['help_text'] ) ) { |
|
238 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
239 | + } |
|
240 | + |
|
241 | + // label |
|
242 | + if ( ! empty( $args['label'] ) ) { |
|
243 | + $label_base_class = ''; |
|
244 | + if ( $type == 'file' ) { |
|
245 | + $label_base_class = ' custom-file-label'; |
|
246 | + } elseif ( $type == 'checkbox' ) { |
|
247 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
248 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
249 | + $help_text = ''; |
|
250 | + //$label_args['class'] .= ' d-inline '; |
|
251 | + $args['wrap_class'] .= ' align-items-center '; |
|
252 | + }else{ |
|
253 | + |
|
254 | + } |
|
255 | + |
|
256 | + $label_base_class = $aui_bs5 ? ' form-check-label' : ' custom-control-label'; |
|
257 | + } |
|
258 | + $label_args['class'] .= $label_base_class; |
|
259 | + $temp_label_args = $label_args; |
|
260 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
261 | + $label = self::label( $temp_label_args, $type ); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + // set help text in the correct position |
|
268 | + if ( $label_after ) { |
|
269 | + $output .= $label . $help_text; |
|
270 | + } |
|
271 | + |
|
272 | + // some input types need a separate wrap |
|
273 | + if ( $type == 'file' ) { |
|
274 | + $output = self::wrap( array( |
|
275 | + 'content' => $output, |
|
276 | + 'class' => $aui_bs5 ? 'mb-3 custom-file' : 'form-group custom-file' |
|
277 | + ) ); |
|
278 | + } elseif ( $type == 'checkbox' ) { |
|
279 | + |
|
280 | + $label_args['title'] = $args['label']; |
|
281 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
282 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
283 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
284 | + if ( $aui_bs5 ) { |
|
285 | + $wrap_class = $args['switch'] ? 'form-check form-switch' . $switch_size_class : 'form-check'; |
|
286 | + }else{ |
|
287 | + $wrap_class = $args['switch'] ? 'custom-switch' . $switch_size_class : 'custom-checkbox' ; |
|
288 | + } |
|
289 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
290 | + $wrap_class .= $aui_bs5 ? '' : ' d-flex align-content-center'; |
|
291 | + $label = str_replace(array("form-check-label","custom-control-label"),"", self::label( $label_args, 'cb' ) ); |
|
292 | + } |
|
293 | + $output = self::wrap( array( |
|
294 | + 'content' => $output, |
|
295 | + 'class' => $aui_bs5 ? $wrap_class : 'custom-control ' . $wrap_class |
|
296 | + ) ); |
|
297 | + |
|
298 | + if ( $args['label_type'] == 'horizontal' ) { |
|
299 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
300 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
301 | + } |
|
302 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
303 | + |
|
304 | + |
|
305 | + // allow password field to toggle view |
|
306 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
307 | 307 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
308 | 308 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
309 | 309 | if($el.hasClass(\'fa-eye\')) |
310 | 310 | {$eli.attr(\'type\',\'text\');} |
311 | 311 | else{$eli.attr(\'type\',\'password\');}" |
312 | 312 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
313 | - } |
|
314 | - |
|
315 | - // input group wraps |
|
316 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
317 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
318 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
319 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
320 | - |
|
321 | - if ( $args['input_group_left'] ) { |
|
322 | - $output = self::wrap( array( |
|
323 | - 'content' => $output, |
|
324 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
325 | - 'input_group_left' => $args['input_group_left'], |
|
326 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
327 | - ) ); |
|
328 | - } |
|
329 | - if ( $args['input_group_right'] ) { |
|
330 | - $output = self::wrap( array( |
|
331 | - 'content' => $output, |
|
332 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
333 | - 'input_group_right' => $args['input_group_right'], |
|
334 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
335 | - ) ); |
|
336 | - } |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - if ( ! $label_after ) { |
|
341 | - $output .= $help_text; |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
346 | - $output = self::wrap( array( |
|
347 | - 'content' => $output, |
|
348 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
349 | - ) ); |
|
350 | - } |
|
351 | - |
|
352 | - if ( ! $label_after ) { |
|
353 | - $output = $label . $output; |
|
354 | - } |
|
355 | - |
|
356 | - // wrap |
|
357 | - if ( ! $args['no_wrap'] ) { |
|
358 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
359 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
360 | - }else{ |
|
361 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
362 | - } |
|
363 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
364 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
365 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
366 | - $output = self::wrap( array( |
|
367 | - 'content' => $output, |
|
368 | - 'class' => $wrap_class, |
|
369 | - 'element_require' => $args['element_require'], |
|
370 | - 'argument_id' => $args['id'], |
|
371 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
372 | - ) ); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - return $output; |
|
377 | - } |
|
378 | - |
|
379 | - public static function label( $args = array(), $type = '' ) { |
|
380 | - global $aui_bs5; |
|
381 | - //<label for="exampleInputEmail1">Email address</label> |
|
382 | - $defaults = array( |
|
383 | - 'title' => 'div', |
|
384 | - 'for' => '', |
|
385 | - 'class' => '', |
|
386 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
387 | - 'label_col' => '', |
|
388 | - ); |
|
389 | - |
|
390 | - /** |
|
313 | + } |
|
314 | + |
|
315 | + // input group wraps |
|
316 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
317 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
318 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
319 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
320 | + |
|
321 | + if ( $args['input_group_left'] ) { |
|
322 | + $output = self::wrap( array( |
|
323 | + 'content' => $output, |
|
324 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
325 | + 'input_group_left' => $args['input_group_left'], |
|
326 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
327 | + ) ); |
|
328 | + } |
|
329 | + if ( $args['input_group_right'] ) { |
|
330 | + $output = self::wrap( array( |
|
331 | + 'content' => $output, |
|
332 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
333 | + 'input_group_right' => $args['input_group_right'], |
|
334 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
335 | + ) ); |
|
336 | + } |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + if ( ! $label_after ) { |
|
341 | + $output .= $help_text; |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
346 | + $output = self::wrap( array( |
|
347 | + 'content' => $output, |
|
348 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
349 | + ) ); |
|
350 | + } |
|
351 | + |
|
352 | + if ( ! $label_after ) { |
|
353 | + $output = $label . $output; |
|
354 | + } |
|
355 | + |
|
356 | + // wrap |
|
357 | + if ( ! $args['no_wrap'] ) { |
|
358 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
359 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
360 | + }else{ |
|
361 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
362 | + } |
|
363 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : $fg_class; |
|
364 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
365 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
366 | + $output = self::wrap( array( |
|
367 | + 'content' => $output, |
|
368 | + 'class' => $wrap_class, |
|
369 | + 'element_require' => $args['element_require'], |
|
370 | + 'argument_id' => $args['id'], |
|
371 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
372 | + ) ); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + return $output; |
|
377 | + } |
|
378 | + |
|
379 | + public static function label( $args = array(), $type = '' ) { |
|
380 | + global $aui_bs5; |
|
381 | + //<label for="exampleInputEmail1">Email address</label> |
|
382 | + $defaults = array( |
|
383 | + 'title' => 'div', |
|
384 | + 'for' => '', |
|
385 | + 'class' => '', |
|
386 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
387 | + 'label_col' => '', |
|
388 | + ); |
|
389 | + |
|
390 | + /** |
|
391 | 391 | * Parse incoming $args into an array and merge it with $defaults |
392 | 392 | */ |
393 | - $args = wp_parse_args( $args, $defaults ); |
|
394 | - $output = ''; |
|
393 | + $args = wp_parse_args( $args, $defaults ); |
|
394 | + $output = ''; |
|
395 | 395 | |
396 | - if ( $args['title'] ) { |
|
396 | + if ( $args['title'] ) { |
|
397 | 397 | |
398 | - // maybe hide labels //@todo set a global option for visibility class |
|
399 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
400 | - $class = $args['class']; |
|
401 | - } else { |
|
402 | - $class = 'sr-only ' . $args['class']; |
|
403 | - } |
|
398 | + // maybe hide labels //@todo set a global option for visibility class |
|
399 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
400 | + $class = $args['class']; |
|
401 | + } else { |
|
402 | + $class = 'sr-only ' . $args['class']; |
|
403 | + } |
|
404 | 404 | |
405 | - // maybe horizontal |
|
406 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
407 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
408 | - } |
|
405 | + // maybe horizontal |
|
406 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
407 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label '.$type; |
|
408 | + } |
|
409 | 409 | |
410 | - if( $aui_bs5 ){ $class .= ' form-label'; } |
|
410 | + if( $aui_bs5 ){ $class .= ' form-label'; } |
|
411 | 411 | |
412 | - // open |
|
413 | - $output .= '<label '; |
|
412 | + // open |
|
413 | + $output .= '<label '; |
|
414 | 414 | |
415 | - // for |
|
416 | - if ( ! empty( $args['for'] ) ) { |
|
417 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
418 | - } |
|
415 | + // for |
|
416 | + if ( ! empty( $args['for'] ) ) { |
|
417 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
418 | + } |
|
419 | 419 | |
420 | - // class |
|
421 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
422 | - $output .= ' class="' . $class . '" '; |
|
420 | + // class |
|
421 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
422 | + $output .= ' class="' . $class . '" '; |
|
423 | 423 | |
424 | - // close |
|
425 | - $output .= '>'; |
|
424 | + // close |
|
425 | + $output .= '>'; |
|
426 | 426 | |
427 | 427 | |
428 | - // title, don't escape fully as can contain html |
|
429 | - if ( ! empty( $args['title'] ) ) { |
|
430 | - $output .= wp_kses_post( $args['title'] ); |
|
431 | - } |
|
428 | + // title, don't escape fully as can contain html |
|
429 | + if ( ! empty( $args['title'] ) ) { |
|
430 | + $output .= wp_kses_post( $args['title'] ); |
|
431 | + } |
|
432 | 432 | |
433 | - // close wrap |
|
434 | - $output .= '</label>'; |
|
433 | + // close wrap |
|
434 | + $output .= '</label>'; |
|
435 | 435 | |
436 | 436 | |
437 | - } |
|
437 | + } |
|
438 | 438 | |
439 | 439 | |
440 | - return $output; |
|
441 | - } |
|
440 | + return $output; |
|
441 | + } |
|
442 | 442 | |
443 | - /** |
|
443 | + /** |
|
444 | 444 | * Wrap some content in a HTML wrapper. |
445 | 445 | * |
446 | 446 | * @param array $args |
447 | 447 | * |
448 | 448 | * @return string |
449 | 449 | */ |
450 | - public static function wrap( $args = array() ) { |
|
451 | - global $aui_bs5; |
|
452 | - $defaults = array( |
|
453 | - 'type' => 'div', |
|
454 | - 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
455 | - 'content' => '', |
|
456 | - 'input_group_left' => '', |
|
457 | - 'input_group_right' => '', |
|
458 | - 'input_group_left_inside' => false, |
|
459 | - 'input_group_right_inside' => false, |
|
460 | - 'element_require' => '', |
|
461 | - 'argument_id' => '', |
|
462 | - 'wrap_attributes' => array() |
|
463 | - ); |
|
464 | - |
|
465 | - /** |
|
450 | + public static function wrap( $args = array() ) { |
|
451 | + global $aui_bs5; |
|
452 | + $defaults = array( |
|
453 | + 'type' => 'div', |
|
454 | + 'class' => $aui_bs5 ? 'mb-3' : 'form-group', |
|
455 | + 'content' => '', |
|
456 | + 'input_group_left' => '', |
|
457 | + 'input_group_right' => '', |
|
458 | + 'input_group_left_inside' => false, |
|
459 | + 'input_group_right_inside' => false, |
|
460 | + 'element_require' => '', |
|
461 | + 'argument_id' => '', |
|
462 | + 'wrap_attributes' => array() |
|
463 | + ); |
|
464 | + |
|
465 | + /** |
|
466 | 466 | * Parse incoming $args into an array and merge it with $defaults |
467 | 467 | */ |
468 | - $args = wp_parse_args( $args, $defaults ); |
|
469 | - $output = ''; |
|
470 | - if ( $args['type'] ) { |
|
468 | + $args = wp_parse_args( $args, $defaults ); |
|
469 | + $output = ''; |
|
470 | + if ( $args['type'] ) { |
|
471 | 471 | |
472 | - // open |
|
473 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
472 | + // open |
|
473 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
474 | 474 | |
475 | - // element require |
|
476 | - if ( ! empty( $args['element_require'] ) ) { |
|
477 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
478 | - $args['class'] .= " aui-conditional-field"; |
|
479 | - } |
|
475 | + // element require |
|
476 | + if ( ! empty( $args['element_require'] ) ) { |
|
477 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
478 | + $args['class'] .= " aui-conditional-field"; |
|
479 | + } |
|
480 | 480 | |
481 | - // argument_id |
|
482 | - if ( ! empty( $args['argument_id'] ) ) { |
|
483 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
484 | - } |
|
481 | + // argument_id |
|
482 | + if ( ! empty( $args['argument_id'] ) ) { |
|
483 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
484 | + } |
|
485 | 485 | |
486 | - // class |
|
487 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
488 | - $output .= ' class="' . $class . '" '; |
|
486 | + // class |
|
487 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
488 | + $output .= ' class="' . $class . '" '; |
|
489 | 489 | |
490 | - // Attributes |
|
491 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
492 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
493 | - } |
|
490 | + // Attributes |
|
491 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
492 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
493 | + } |
|
494 | 494 | |
495 | - // close wrap |
|
496 | - $output .= ' >'; |
|
495 | + // close wrap |
|
496 | + $output .= ' >'; |
|
497 | 497 | |
498 | 498 | |
499 | - // Input group left |
|
500 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
501 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
502 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
503 | - $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
504 | -// $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
505 | - } |
|
499 | + // Input group left |
|
500 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
501 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
502 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
503 | + $output .= $aui_bs5 ? $input_group_left : '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
504 | + // $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
505 | + } |
|
506 | 506 | |
507 | - // content |
|
508 | - $output .= $args['content']; |
|
507 | + // content |
|
508 | + $output .= $args['content']; |
|
509 | 509 | |
510 | - // Input group right |
|
511 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
512 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
513 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
514 | - $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
515 | -// $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
516 | - } |
|
510 | + // Input group right |
|
511 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
512 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
513 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
514 | + $output .= $aui_bs5 ? str_replace( 'input-group-text','input-group-text top-0 end-0', $input_group_right ) : '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
515 | + // $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
516 | + } |
|
517 | 517 | |
518 | 518 | |
519 | - // close wrap |
|
520 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
519 | + // close wrap |
|
520 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
521 | 521 | |
522 | 522 | |
523 | - } else { |
|
524 | - $output = $args['content']; |
|
525 | - } |
|
523 | + } else { |
|
524 | + $output = $args['content']; |
|
525 | + } |
|
526 | 526 | |
527 | - return $output; |
|
528 | - } |
|
527 | + return $output; |
|
528 | + } |
|
529 | 529 | |
530 | - /** |
|
530 | + /** |
|
531 | 531 | * Build the component. |
532 | 532 | * |
533 | 533 | * @param array $args |
534 | 534 | * |
535 | 535 | * @return string The rendered component. |
536 | 536 | */ |
537 | - public static function textarea( $args = array() ) { |
|
538 | - global $aui_bs5; |
|
539 | - |
|
540 | - $defaults = array( |
|
541 | - 'name' => '', |
|
542 | - 'class' => '', |
|
543 | - 'wrap_class' => '', |
|
544 | - 'id' => '', |
|
545 | - 'placeholder' => '', |
|
546 | - 'title' => '', |
|
547 | - 'value' => '', |
|
548 | - 'required' => false, |
|
549 | - 'label' => '', |
|
550 | - 'label_after' => false, |
|
551 | - 'label_class' => '', |
|
552 | - 'label_type' => '', |
|
553 | - 'label_col' => '', |
|
554 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
555 | - 'input_group_right' => '', |
|
556 | - 'input_group_left' => '', |
|
557 | - 'input_group_right_inside' => false, |
|
558 | - 'form_group_class' => '', |
|
559 | - 'help_text' => '', |
|
560 | - 'validation_text' => '', |
|
561 | - 'validation_pattern' => '', |
|
562 | - 'no_wrap' => false, |
|
563 | - 'rows' => '', |
|
564 | - 'wysiwyg' => false, |
|
565 | - 'allow_tags' => false, |
|
566 | - // Allow HTML tags |
|
567 | - 'element_require' => '', |
|
568 | - // [%element_id%] == "1" |
|
569 | - 'extra_attributes' => array(), |
|
570 | - // an array of extra attributes |
|
571 | - 'wrap_attributes' => array(), |
|
572 | - ); |
|
573 | - |
|
574 | - /** |
|
537 | + public static function textarea( $args = array() ) { |
|
538 | + global $aui_bs5; |
|
539 | + |
|
540 | + $defaults = array( |
|
541 | + 'name' => '', |
|
542 | + 'class' => '', |
|
543 | + 'wrap_class' => '', |
|
544 | + 'id' => '', |
|
545 | + 'placeholder' => '', |
|
546 | + 'title' => '', |
|
547 | + 'value' => '', |
|
548 | + 'required' => false, |
|
549 | + 'label' => '', |
|
550 | + 'label_after' => false, |
|
551 | + 'label_class' => '', |
|
552 | + 'label_type' => '', |
|
553 | + 'label_col' => '', |
|
554 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
555 | + 'input_group_right' => '', |
|
556 | + 'input_group_left' => '', |
|
557 | + 'input_group_right_inside' => false, |
|
558 | + 'form_group_class' => '', |
|
559 | + 'help_text' => '', |
|
560 | + 'validation_text' => '', |
|
561 | + 'validation_pattern' => '', |
|
562 | + 'no_wrap' => false, |
|
563 | + 'rows' => '', |
|
564 | + 'wysiwyg' => false, |
|
565 | + 'allow_tags' => false, |
|
566 | + // Allow HTML tags |
|
567 | + 'element_require' => '', |
|
568 | + // [%element_id%] == "1" |
|
569 | + 'extra_attributes' => array(), |
|
570 | + // an array of extra attributes |
|
571 | + 'wrap_attributes' => array(), |
|
572 | + ); |
|
573 | + |
|
574 | + /** |
|
575 | 575 | * Parse incoming $args into an array and merge it with $defaults |
576 | 576 | */ |
577 | - $args = wp_parse_args( $args, $defaults ); |
|
578 | - $output = ''; |
|
579 | - $label = ''; |
|
580 | - |
|
581 | - // hidden label option needs to be empty |
|
582 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
583 | - |
|
584 | - // floating labels don't work with wysiwyg so set it as top |
|
585 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
586 | - $args['label_type'] = 'top'; |
|
587 | - } |
|
588 | - |
|
589 | - $label_after = $args['label_after']; |
|
590 | - |
|
591 | - // floating labels need label after |
|
592 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
593 | - $label_after = true; |
|
594 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
595 | - } |
|
596 | - |
|
597 | - // label |
|
598 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
599 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
600 | - $label_args = array( |
|
601 | - 'title' => $args['label'], |
|
602 | - 'for' => $args['id'], |
|
603 | - 'class' => $args['label_class'] . " ", |
|
604 | - 'label_type' => $args['label_type'], |
|
605 | - 'label_col' => $args['label_col'] |
|
606 | - ); |
|
607 | - $label .= self::label( $label_args ); |
|
608 | - } |
|
609 | - |
|
610 | - // maybe horizontal label |
|
611 | - if ( $args['label_type'] == 'horizontal' ) { |
|
612 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
613 | - $label .= '<div class="' . $input_col . '">'; |
|
614 | - } |
|
615 | - |
|
616 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
617 | - ob_start(); |
|
618 | - $content = $args['value']; |
|
619 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
620 | - $settings = array( |
|
621 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
622 | - 'quicktags' => false, |
|
623 | - 'media_buttons' => false, |
|
624 | - 'editor_class' => 'form-control', |
|
625 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
626 | - 'teeny' => true, |
|
627 | - ); |
|
628 | - |
|
629 | - // maybe set settings if array |
|
630 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
631 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
632 | - } |
|
633 | - |
|
634 | - wp_editor( $content, $editor_id, $settings ); |
|
635 | - $output .= ob_get_clean(); |
|
636 | - } else { |
|
637 | - |
|
638 | - // open |
|
639 | - $output .= '<textarea '; |
|
640 | - |
|
641 | - // name |
|
642 | - if ( ! empty( $args['name'] ) ) { |
|
643 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
644 | - } |
|
645 | - |
|
646 | - // id |
|
647 | - if ( ! empty( $args['id'] ) ) { |
|
648 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
649 | - } |
|
650 | - |
|
651 | - // placeholder |
|
652 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
653 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
654 | - } |
|
655 | - |
|
656 | - // title |
|
657 | - if ( ! empty( $args['title'] ) ) { |
|
658 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
659 | - } |
|
660 | - |
|
661 | - // validation text |
|
662 | - if ( ! empty( $args['validation_text'] ) ) { |
|
663 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
664 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
665 | - } |
|
666 | - |
|
667 | - // validation_pattern |
|
668 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
669 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
670 | - } |
|
671 | - |
|
672 | - // required |
|
673 | - if ( ! empty( $args['required'] ) ) { |
|
674 | - $output .= ' required '; |
|
675 | - } |
|
676 | - |
|
677 | - // rows |
|
678 | - if ( ! empty( $args['rows'] ) ) { |
|
679 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - // class |
|
684 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
685 | - $output .= ' class="form-control ' . $class . '" '; |
|
686 | - |
|
687 | - // extra attributes |
|
688 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
689 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
690 | - } |
|
691 | - |
|
692 | - // close tag |
|
693 | - $output .= ' >'; |
|
694 | - |
|
695 | - // value |
|
696 | - if ( ! empty( $args['value'] ) ) { |
|
697 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
698 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
699 | - } else { |
|
700 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
701 | - } |
|
702 | - } |
|
703 | - |
|
704 | - // closing tag |
|
705 | - $output .= '</textarea>'; |
|
706 | - |
|
707 | - |
|
708 | - // input group wraps |
|
709 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
710 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
711 | - if ( $args['input_group_left'] ) { |
|
712 | - $output = self::wrap( array( |
|
713 | - 'content' => $output, |
|
714 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
715 | - 'input_group_left' => $args['input_group_left'], |
|
716 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
717 | - ) ); |
|
718 | - } |
|
719 | - if ( $args['input_group_right'] ) { |
|
720 | - $output = self::wrap( array( |
|
721 | - 'content' => $output, |
|
722 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
723 | - 'input_group_right' => $args['input_group_right'], |
|
724 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
725 | - ) ); |
|
726 | - } |
|
727 | - |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - } |
|
732 | - |
|
733 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
734 | - $label_args = array( |
|
735 | - 'title' => $args['label'], |
|
736 | - 'for' => $args['id'], |
|
737 | - 'class' => $args['label_class'] . " ", |
|
738 | - 'label_type' => $args['label_type'], |
|
739 | - 'label_col' => $args['label_col'] |
|
740 | - ); |
|
741 | - $output .= self::label( $label_args ); |
|
742 | - } |
|
743 | - |
|
744 | - // help text |
|
745 | - if ( ! empty( $args['help_text'] ) ) { |
|
746 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
747 | - } |
|
748 | - |
|
749 | - if ( ! $label_after ) { |
|
750 | - $output = $label . $output; |
|
751 | - } |
|
752 | - |
|
753 | - // maybe horizontal label |
|
754 | - if ( $args['label_type'] == 'horizontal' ) { |
|
755 | - $output .= '</div>'; |
|
756 | - } |
|
757 | - |
|
758 | - |
|
759 | - // wrap |
|
760 | - if ( ! $args['no_wrap'] ) { |
|
761 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
762 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
763 | - }else{ |
|
764 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
765 | - } |
|
766 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
767 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
768 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
769 | - $output = self::wrap( array( |
|
770 | - 'content' => $output, |
|
771 | - 'class' => $wrap_class, |
|
772 | - 'element_require' => $args['element_require'], |
|
773 | - 'argument_id' => $args['id'], |
|
774 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
775 | - ) ); |
|
776 | - } |
|
777 | - |
|
778 | - |
|
779 | - return $output; |
|
780 | - } |
|
781 | - |
|
782 | - /** |
|
577 | + $args = wp_parse_args( $args, $defaults ); |
|
578 | + $output = ''; |
|
579 | + $label = ''; |
|
580 | + |
|
581 | + // hidden label option needs to be empty |
|
582 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
583 | + |
|
584 | + // floating labels don't work with wysiwyg so set it as top |
|
585 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
586 | + $args['label_type'] = 'top'; |
|
587 | + } |
|
588 | + |
|
589 | + $label_after = $args['label_after']; |
|
590 | + |
|
591 | + // floating labels need label after |
|
592 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
593 | + $label_after = true; |
|
594 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
595 | + } |
|
596 | + |
|
597 | + // label |
|
598 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
599 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
600 | + $label_args = array( |
|
601 | + 'title' => $args['label'], |
|
602 | + 'for' => $args['id'], |
|
603 | + 'class' => $args['label_class'] . " ", |
|
604 | + 'label_type' => $args['label_type'], |
|
605 | + 'label_col' => $args['label_col'] |
|
606 | + ); |
|
607 | + $label .= self::label( $label_args ); |
|
608 | + } |
|
609 | + |
|
610 | + // maybe horizontal label |
|
611 | + if ( $args['label_type'] == 'horizontal' ) { |
|
612 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
613 | + $label .= '<div class="' . $input_col . '">'; |
|
614 | + } |
|
615 | + |
|
616 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
617 | + ob_start(); |
|
618 | + $content = $args['value']; |
|
619 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
620 | + $settings = array( |
|
621 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
622 | + 'quicktags' => false, |
|
623 | + 'media_buttons' => false, |
|
624 | + 'editor_class' => 'form-control', |
|
625 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
626 | + 'teeny' => true, |
|
627 | + ); |
|
628 | + |
|
629 | + // maybe set settings if array |
|
630 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
631 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
632 | + } |
|
633 | + |
|
634 | + wp_editor( $content, $editor_id, $settings ); |
|
635 | + $output .= ob_get_clean(); |
|
636 | + } else { |
|
637 | + |
|
638 | + // open |
|
639 | + $output .= '<textarea '; |
|
640 | + |
|
641 | + // name |
|
642 | + if ( ! empty( $args['name'] ) ) { |
|
643 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
644 | + } |
|
645 | + |
|
646 | + // id |
|
647 | + if ( ! empty( $args['id'] ) ) { |
|
648 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
649 | + } |
|
650 | + |
|
651 | + // placeholder |
|
652 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
653 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
654 | + } |
|
655 | + |
|
656 | + // title |
|
657 | + if ( ! empty( $args['title'] ) ) { |
|
658 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
659 | + } |
|
660 | + |
|
661 | + // validation text |
|
662 | + if ( ! empty( $args['validation_text'] ) ) { |
|
663 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( addslashes( $args['validation_text'] ) ) . '\')" '; |
|
664 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
665 | + } |
|
666 | + |
|
667 | + // validation_pattern |
|
668 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
669 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
670 | + } |
|
671 | + |
|
672 | + // required |
|
673 | + if ( ! empty( $args['required'] ) ) { |
|
674 | + $output .= ' required '; |
|
675 | + } |
|
676 | + |
|
677 | + // rows |
|
678 | + if ( ! empty( $args['rows'] ) ) { |
|
679 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + // class |
|
684 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
685 | + $output .= ' class="form-control ' . $class . '" '; |
|
686 | + |
|
687 | + // extra attributes |
|
688 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
689 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
690 | + } |
|
691 | + |
|
692 | + // close tag |
|
693 | + $output .= ' >'; |
|
694 | + |
|
695 | + // value |
|
696 | + if ( ! empty( $args['value'] ) ) { |
|
697 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
698 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
699 | + } else { |
|
700 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
701 | + } |
|
702 | + } |
|
703 | + |
|
704 | + // closing tag |
|
705 | + $output .= '</textarea>'; |
|
706 | + |
|
707 | + |
|
708 | + // input group wraps |
|
709 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
710 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
711 | + if ( $args['input_group_left'] ) { |
|
712 | + $output = self::wrap( array( |
|
713 | + 'content' => $output, |
|
714 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
715 | + 'input_group_left' => $args['input_group_left'], |
|
716 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
717 | + ) ); |
|
718 | + } |
|
719 | + if ( $args['input_group_right'] ) { |
|
720 | + $output = self::wrap( array( |
|
721 | + 'content' => $output, |
|
722 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
723 | + 'input_group_right' => $args['input_group_right'], |
|
724 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
725 | + ) ); |
|
726 | + } |
|
727 | + |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + } |
|
732 | + |
|
733 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
734 | + $label_args = array( |
|
735 | + 'title' => $args['label'], |
|
736 | + 'for' => $args['id'], |
|
737 | + 'class' => $args['label_class'] . " ", |
|
738 | + 'label_type' => $args['label_type'], |
|
739 | + 'label_col' => $args['label_col'] |
|
740 | + ); |
|
741 | + $output .= self::label( $label_args ); |
|
742 | + } |
|
743 | + |
|
744 | + // help text |
|
745 | + if ( ! empty( $args['help_text'] ) ) { |
|
746 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
747 | + } |
|
748 | + |
|
749 | + if ( ! $label_after ) { |
|
750 | + $output = $label . $output; |
|
751 | + } |
|
752 | + |
|
753 | + // maybe horizontal label |
|
754 | + if ( $args['label_type'] == 'horizontal' ) { |
|
755 | + $output .= '</div>'; |
|
756 | + } |
|
757 | + |
|
758 | + |
|
759 | + // wrap |
|
760 | + if ( ! $args['no_wrap'] ) { |
|
761 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
762 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
763 | + }else{ |
|
764 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
765 | + } |
|
766 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : $fg_class; |
|
767 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
768 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
769 | + $output = self::wrap( array( |
|
770 | + 'content' => $output, |
|
771 | + 'class' => $wrap_class, |
|
772 | + 'element_require' => $args['element_require'], |
|
773 | + 'argument_id' => $args['id'], |
|
774 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
775 | + ) ); |
|
776 | + } |
|
777 | + |
|
778 | + |
|
779 | + return $output; |
|
780 | + } |
|
781 | + |
|
782 | + /** |
|
783 | 783 | * Build the component. |
784 | 784 | * |
785 | 785 | * @param array $args |
786 | 786 | * |
787 | 787 | * @return string The rendered component. |
788 | 788 | */ |
789 | - public static function select( $args = array() ) { |
|
790 | - global $aui_bs5, $aui_has_select2, $aui_select2_enqueued; |
|
791 | - |
|
792 | - $defaults = array( |
|
793 | - 'class' => '', |
|
794 | - 'wrap_class' => '', |
|
795 | - 'id' => '', |
|
796 | - 'title' => '', |
|
797 | - 'value' => '', |
|
798 | - // can be an array or a string |
|
799 | - 'required' => false, |
|
800 | - 'label' => '', |
|
801 | - 'label_after' => false, |
|
802 | - 'label_type' => '', |
|
803 | - 'label_col' => '', |
|
804 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
805 | - 'label_class' => '', |
|
806 | - 'help_text' => '', |
|
807 | - 'placeholder' => '', |
|
808 | - 'options' => array(), |
|
809 | - // array or string |
|
810 | - 'icon' => '', |
|
811 | - 'multiple' => false, |
|
812 | - 'select2' => false, |
|
813 | - 'no_wrap' => false, |
|
814 | - 'input_group_right' => '', |
|
815 | - 'input_group_left' => '', |
|
816 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
817 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
818 | - 'form_group_class' => '', |
|
819 | - 'element_require' => '', |
|
820 | - // [%element_id%] == "1" |
|
821 | - 'extra_attributes' => array(), |
|
822 | - // an array of extra attributes |
|
823 | - 'wrap_attributes' => array(), |
|
824 | - ); |
|
825 | - |
|
826 | - /** |
|
789 | + public static function select( $args = array() ) { |
|
790 | + global $aui_bs5, $aui_has_select2, $aui_select2_enqueued; |
|
791 | + |
|
792 | + $defaults = array( |
|
793 | + 'class' => '', |
|
794 | + 'wrap_class' => '', |
|
795 | + 'id' => '', |
|
796 | + 'title' => '', |
|
797 | + 'value' => '', |
|
798 | + // can be an array or a string |
|
799 | + 'required' => false, |
|
800 | + 'label' => '', |
|
801 | + 'label_after' => false, |
|
802 | + 'label_type' => '', |
|
803 | + 'label_col' => '', |
|
804 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
805 | + 'label_class' => '', |
|
806 | + 'help_text' => '', |
|
807 | + 'placeholder' => '', |
|
808 | + 'options' => array(), |
|
809 | + // array or string |
|
810 | + 'icon' => '', |
|
811 | + 'multiple' => false, |
|
812 | + 'select2' => false, |
|
813 | + 'no_wrap' => false, |
|
814 | + 'input_group_right' => '', |
|
815 | + 'input_group_left' => '', |
|
816 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
817 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
818 | + 'form_group_class' => '', |
|
819 | + 'element_require' => '', |
|
820 | + // [%element_id%] == "1" |
|
821 | + 'extra_attributes' => array(), |
|
822 | + // an array of extra attributes |
|
823 | + 'wrap_attributes' => array(), |
|
824 | + ); |
|
825 | + |
|
826 | + /** |
|
827 | 827 | * Parse incoming $args into an array and merge it with $defaults |
828 | 828 | */ |
829 | - $args = wp_parse_args( $args, $defaults ); |
|
830 | - $output = ''; |
|
831 | - |
|
832 | - // for now lets hide floating labels |
|
833 | - if ( $args['label_type'] == 'floating' ) { |
|
834 | - $args['label_type'] = 'hidden'; |
|
835 | - } |
|
836 | - |
|
837 | - // hidden label option needs to be empty |
|
838 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
839 | - |
|
840 | - |
|
841 | - $label_after = $args['label_after']; |
|
842 | - |
|
843 | - // floating labels need label after |
|
844 | - if ( $args['label_type'] == 'floating' ) { |
|
845 | - $label_after = true; |
|
846 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
847 | - } |
|
848 | - |
|
849 | - // Maybe setup select2 |
|
850 | - $is_select2 = false; |
|
851 | - if ( ! empty( $args['select2'] ) ) { |
|
852 | - $args['class'] .= ' aui-select2'; |
|
853 | - $is_select2 = true; |
|
854 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
855 | - $is_select2 = true; |
|
856 | - } |
|
857 | - |
|
858 | - if ( $is_select2 && ! $aui_has_select2 ) { |
|
859 | - $aui_has_select2 = true; |
|
860 | - $conditional_select2 = apply_filters( 'aui_is_conditional_select2', true ); |
|
861 | - |
|
862 | - // Enqueue the script, |
|
863 | - if ( empty( $aui_select2_enqueued ) && $conditional_select2 === true ) { |
|
864 | - $aui_select2_enqueued = true; |
|
865 | - |
|
866 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
867 | - $aui_settings->enqueue_select2(); |
|
868 | - } |
|
869 | - } |
|
870 | - |
|
871 | - // select2 tags |
|
872 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
873 | - $args['data-tags'] = 'true'; |
|
874 | - $args['data-token-separators'] = "[',']"; |
|
875 | - $args['multiple'] = true; |
|
876 | - } |
|
877 | - |
|
878 | - // select2 placeholder |
|
879 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
880 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
881 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
882 | - } |
|
883 | - |
|
884 | - // Set hidden input to save empty value for multiselect. |
|
885 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
886 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
887 | - } |
|
888 | - |
|
889 | - // open/type |
|
890 | - $output .= '<select '; |
|
891 | - |
|
892 | - // style |
|
893 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
894 | - $output .= " style='width:100%;' "; |
|
895 | - } |
|
896 | - |
|
897 | - // element require |
|
898 | - if ( ! empty( $args['element_require'] ) ) { |
|
899 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
900 | - $args['class'] .= " aui-conditional-field"; |
|
901 | - } |
|
902 | - |
|
903 | - // class |
|
904 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
905 | - $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
906 | - $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
907 | - |
|
908 | - // name |
|
909 | - if ( ! empty( $args['name'] ) ) { |
|
910 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
911 | - } |
|
912 | - |
|
913 | - // id |
|
914 | - if ( ! empty( $args['id'] ) ) { |
|
915 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
916 | - } |
|
917 | - |
|
918 | - // title |
|
919 | - if ( ! empty( $args['title'] ) ) { |
|
920 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
921 | - } |
|
922 | - |
|
923 | - // data-attributes |
|
924 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
925 | - |
|
926 | - // aria-attributes |
|
927 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
928 | - |
|
929 | - // extra attributes |
|
930 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
931 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
932 | - } |
|
933 | - |
|
934 | - // required |
|
935 | - if ( ! empty( $args['required'] ) ) { |
|
936 | - $output .= ' required '; |
|
937 | - } |
|
938 | - |
|
939 | - // multiple |
|
940 | - if ( ! empty( $args['multiple'] ) ) { |
|
941 | - $output .= ' multiple '; |
|
942 | - } |
|
943 | - |
|
944 | - // close opening tag |
|
945 | - $output .= ' >'; |
|
946 | - |
|
947 | - // placeholder |
|
948 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
949 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
950 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
951 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
952 | - } |
|
953 | - |
|
954 | - // Options |
|
955 | - if ( ! empty( $args['options'] ) ) { |
|
956 | - |
|
957 | - if ( ! is_array( $args['options'] ) ) { |
|
958 | - $output .= $args['options']; // not the preferred way but an option |
|
959 | - } else { |
|
960 | - foreach ( $args['options'] as $val => $name ) { |
|
961 | - $selected = ''; |
|
962 | - if ( is_array( $name ) ) { |
|
963 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
964 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
965 | - |
|
966 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
967 | - } else { |
|
968 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
969 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
970 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
971 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
972 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
973 | - } elseif ( ! empty( $args['value'] ) ) { |
|
974 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
975 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
976 | - $selected = selected( $option_value, $args['value'], false ); |
|
977 | - } |
|
978 | - |
|
979 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
980 | - } |
|
981 | - } else { |
|
982 | - if ( ! empty( $args['value'] ) ) { |
|
983 | - if ( is_array( $args['value'] ) ) { |
|
984 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
985 | - } elseif ( ! empty( $args['value'] ) ) { |
|
986 | - $selected = selected( $args['value'], $val, false ); |
|
987 | - } |
|
988 | - } elseif ( $args['value'] === $val ) { |
|
989 | - $selected = selected( $args['value'], $val, false ); |
|
990 | - } |
|
991 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
992 | - } |
|
993 | - } |
|
994 | - } |
|
995 | - |
|
996 | - } |
|
997 | - |
|
998 | - // closing tag |
|
999 | - $output .= '</select>'; |
|
1000 | - |
|
1001 | - $label = ''; |
|
1002 | - $help_text = ''; |
|
1003 | - // label |
|
1004 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1005 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
1006 | - $label_args = array( |
|
1007 | - 'title' => $args['label'], |
|
1008 | - 'for' => $args['id'], |
|
1009 | - 'class' => $args['label_class'] . " ", |
|
1010 | - 'label_type' => $args['label_type'], |
|
1011 | - 'label_col' => $args['label_col'] |
|
1012 | - ); |
|
1013 | - $label = self::label( $label_args ); |
|
1014 | - } |
|
1015 | - |
|
1016 | - // help text |
|
1017 | - if ( ! empty( $args['help_text'] ) ) { |
|
1018 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - // input group wraps |
|
1022 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
1023 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
1024 | - if ( $args['input_group_left'] ) { |
|
1025 | - $output = self::wrap( array( |
|
1026 | - 'content' => $output, |
|
1027 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1028 | - 'input_group_left' => $args['input_group_left'], |
|
1029 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
1030 | - ) ); |
|
1031 | - } |
|
1032 | - if ( $args['input_group_right'] ) { |
|
1033 | - $output = self::wrap( array( |
|
1034 | - 'content' => $output, |
|
1035 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1036 | - 'input_group_right' => $args['input_group_right'], |
|
1037 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
1038 | - ) ); |
|
1039 | - } |
|
1040 | - |
|
1041 | - } |
|
1042 | - |
|
1043 | - if ( ! $label_after ) { |
|
1044 | - $output .= $help_text; |
|
1045 | - } |
|
1046 | - |
|
1047 | - |
|
1048 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1049 | - $output = self::wrap( array( |
|
1050 | - 'content' => $output, |
|
1051 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1052 | - ) ); |
|
1053 | - } |
|
1054 | - |
|
1055 | - if ( ! $label_after ) { |
|
1056 | - $output = $label . $output; |
|
1057 | - } |
|
1058 | - |
|
1059 | - // maybe horizontal label |
|
1060 | -// if ( $args['label_type'] == 'horizontal' ) { |
|
1061 | -// $output .= '</div>'; |
|
1062 | -// } |
|
1063 | - |
|
1064 | - |
|
1065 | - // wrap |
|
1066 | - if ( ! $args['no_wrap'] ) { |
|
1067 | - if ( ! empty( $args['form_group_class'] ) ) { |
|
1068 | - $fg_class = esc_attr( $args['form_group_class'] ); |
|
1069 | - }else{ |
|
1070 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1071 | - } |
|
1072 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1073 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1074 | - $output = self::wrap( array( |
|
1075 | - 'content' => $output, |
|
1076 | - 'class' => $wrap_class, |
|
1077 | - 'element_require' => $args['element_require'], |
|
1078 | - 'argument_id' => $args['id'], |
|
1079 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1080 | - ) ); |
|
1081 | - } |
|
1082 | - |
|
1083 | - |
|
1084 | - return $output; |
|
1085 | - } |
|
1086 | - |
|
1087 | - /** |
|
829 | + $args = wp_parse_args( $args, $defaults ); |
|
830 | + $output = ''; |
|
831 | + |
|
832 | + // for now lets hide floating labels |
|
833 | + if ( $args['label_type'] == 'floating' ) { |
|
834 | + $args['label_type'] = 'hidden'; |
|
835 | + } |
|
836 | + |
|
837 | + // hidden label option needs to be empty |
|
838 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
839 | + |
|
840 | + |
|
841 | + $label_after = $args['label_after']; |
|
842 | + |
|
843 | + // floating labels need label after |
|
844 | + if ( $args['label_type'] == 'floating' ) { |
|
845 | + $label_after = true; |
|
846 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
847 | + } |
|
848 | + |
|
849 | + // Maybe setup select2 |
|
850 | + $is_select2 = false; |
|
851 | + if ( ! empty( $args['select2'] ) ) { |
|
852 | + $args['class'] .= ' aui-select2'; |
|
853 | + $is_select2 = true; |
|
854 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
855 | + $is_select2 = true; |
|
856 | + } |
|
857 | + |
|
858 | + if ( $is_select2 && ! $aui_has_select2 ) { |
|
859 | + $aui_has_select2 = true; |
|
860 | + $conditional_select2 = apply_filters( 'aui_is_conditional_select2', true ); |
|
861 | + |
|
862 | + // Enqueue the script, |
|
863 | + if ( empty( $aui_select2_enqueued ) && $conditional_select2 === true ) { |
|
864 | + $aui_select2_enqueued = true; |
|
865 | + |
|
866 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
867 | + $aui_settings->enqueue_select2(); |
|
868 | + } |
|
869 | + } |
|
870 | + |
|
871 | + // select2 tags |
|
872 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
873 | + $args['data-tags'] = 'true'; |
|
874 | + $args['data-token-separators'] = "[',']"; |
|
875 | + $args['multiple'] = true; |
|
876 | + } |
|
877 | + |
|
878 | + // select2 placeholder |
|
879 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
880 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
881 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
882 | + } |
|
883 | + |
|
884 | + // Set hidden input to save empty value for multiselect. |
|
885 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
886 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
887 | + } |
|
888 | + |
|
889 | + // open/type |
|
890 | + $output .= '<select '; |
|
891 | + |
|
892 | + // style |
|
893 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
894 | + $output .= " style='width:100%;' "; |
|
895 | + } |
|
896 | + |
|
897 | + // element require |
|
898 | + if ( ! empty( $args['element_require'] ) ) { |
|
899 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
900 | + $args['class'] .= " aui-conditional-field"; |
|
901 | + } |
|
902 | + |
|
903 | + // class |
|
904 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
905 | + $select_class = $aui_bs5 ? 'form-select ' : 'custom-select '; |
|
906 | + $output .= AUI_Component_Helper::class_attr( $select_class . $class ); |
|
907 | + |
|
908 | + // name |
|
909 | + if ( ! empty( $args['name'] ) ) { |
|
910 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
911 | + } |
|
912 | + |
|
913 | + // id |
|
914 | + if ( ! empty( $args['id'] ) ) { |
|
915 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
916 | + } |
|
917 | + |
|
918 | + // title |
|
919 | + if ( ! empty( $args['title'] ) ) { |
|
920 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
921 | + } |
|
922 | + |
|
923 | + // data-attributes |
|
924 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
925 | + |
|
926 | + // aria-attributes |
|
927 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
928 | + |
|
929 | + // extra attributes |
|
930 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
931 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
932 | + } |
|
933 | + |
|
934 | + // required |
|
935 | + if ( ! empty( $args['required'] ) ) { |
|
936 | + $output .= ' required '; |
|
937 | + } |
|
938 | + |
|
939 | + // multiple |
|
940 | + if ( ! empty( $args['multiple'] ) ) { |
|
941 | + $output .= ' multiple '; |
|
942 | + } |
|
943 | + |
|
944 | + // close opening tag |
|
945 | + $output .= ' >'; |
|
946 | + |
|
947 | + // placeholder |
|
948 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
949 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
950 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
951 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
952 | + } |
|
953 | + |
|
954 | + // Options |
|
955 | + if ( ! empty( $args['options'] ) ) { |
|
956 | + |
|
957 | + if ( ! is_array( $args['options'] ) ) { |
|
958 | + $output .= $args['options']; // not the preferred way but an option |
|
959 | + } else { |
|
960 | + foreach ( $args['options'] as $val => $name ) { |
|
961 | + $selected = ''; |
|
962 | + if ( is_array( $name ) ) { |
|
963 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
964 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
965 | + |
|
966 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
967 | + } else { |
|
968 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
969 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
970 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
971 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
972 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
973 | + } elseif ( ! empty( $args['value'] ) ) { |
|
974 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
975 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
976 | + $selected = selected( $option_value, $args['value'], false ); |
|
977 | + } |
|
978 | + |
|
979 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
980 | + } |
|
981 | + } else { |
|
982 | + if ( ! empty( $args['value'] ) ) { |
|
983 | + if ( is_array( $args['value'] ) ) { |
|
984 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
985 | + } elseif ( ! empty( $args['value'] ) ) { |
|
986 | + $selected = selected( $args['value'], $val, false ); |
|
987 | + } |
|
988 | + } elseif ( $args['value'] === $val ) { |
|
989 | + $selected = selected( $args['value'], $val, false ); |
|
990 | + } |
|
991 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
992 | + } |
|
993 | + } |
|
994 | + } |
|
995 | + |
|
996 | + } |
|
997 | + |
|
998 | + // closing tag |
|
999 | + $output .= '</select>'; |
|
1000 | + |
|
1001 | + $label = ''; |
|
1002 | + $help_text = ''; |
|
1003 | + // label |
|
1004 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1005 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
1006 | + $label_args = array( |
|
1007 | + 'title' => $args['label'], |
|
1008 | + 'for' => $args['id'], |
|
1009 | + 'class' => $args['label_class'] . " ", |
|
1010 | + 'label_type' => $args['label_type'], |
|
1011 | + 'label_col' => $args['label_col'] |
|
1012 | + ); |
|
1013 | + $label = self::label( $label_args ); |
|
1014 | + } |
|
1015 | + |
|
1016 | + // help text |
|
1017 | + if ( ! empty( $args['help_text'] ) ) { |
|
1018 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + // input group wraps |
|
1022 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
1023 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
1024 | + if ( $args['input_group_left'] ) { |
|
1025 | + $output = self::wrap( array( |
|
1026 | + 'content' => $output, |
|
1027 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1028 | + 'input_group_left' => $args['input_group_left'], |
|
1029 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
1030 | + ) ); |
|
1031 | + } |
|
1032 | + if ( $args['input_group_right'] ) { |
|
1033 | + $output = self::wrap( array( |
|
1034 | + 'content' => $output, |
|
1035 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
1036 | + 'input_group_right' => $args['input_group_right'], |
|
1037 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
1038 | + ) ); |
|
1039 | + } |
|
1040 | + |
|
1041 | + } |
|
1042 | + |
|
1043 | + if ( ! $label_after ) { |
|
1044 | + $output .= $help_text; |
|
1045 | + } |
|
1046 | + |
|
1047 | + |
|
1048 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1049 | + $output = self::wrap( array( |
|
1050 | + 'content' => $output, |
|
1051 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
1052 | + ) ); |
|
1053 | + } |
|
1054 | + |
|
1055 | + if ( ! $label_after ) { |
|
1056 | + $output = $label . $output; |
|
1057 | + } |
|
1058 | + |
|
1059 | + // maybe horizontal label |
|
1060 | + // if ( $args['label_type'] == 'horizontal' ) { |
|
1061 | + // $output .= '</div>'; |
|
1062 | + // } |
|
1063 | + |
|
1064 | + |
|
1065 | + // wrap |
|
1066 | + if ( ! $args['no_wrap'] ) { |
|
1067 | + if ( ! empty( $args['form_group_class'] ) ) { |
|
1068 | + $fg_class = esc_attr( $args['form_group_class'] ); |
|
1069 | + }else{ |
|
1070 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1071 | + } |
|
1072 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1073 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1074 | + $output = self::wrap( array( |
|
1075 | + 'content' => $output, |
|
1076 | + 'class' => $wrap_class, |
|
1077 | + 'element_require' => $args['element_require'], |
|
1078 | + 'argument_id' => $args['id'], |
|
1079 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1080 | + ) ); |
|
1081 | + } |
|
1082 | + |
|
1083 | + |
|
1084 | + return $output; |
|
1085 | + } |
|
1086 | + |
|
1087 | + /** |
|
1088 | 1088 | * Build the component. |
1089 | 1089 | * |
1090 | 1090 | * @param array $args |
1091 | 1091 | * |
1092 | 1092 | * @return string The rendered component. |
1093 | 1093 | */ |
1094 | - public static function radio( $args = array() ) { |
|
1095 | - global $aui_bs5; |
|
1096 | - |
|
1097 | - $defaults = array( |
|
1098 | - 'class' => '', |
|
1099 | - 'wrap_class' => '', |
|
1100 | - 'id' => '', |
|
1101 | - 'title' => '', |
|
1102 | - 'horizontal' => false, |
|
1103 | - // sets the lable horizontal |
|
1104 | - 'value' => '', |
|
1105 | - 'label' => '', |
|
1106 | - 'label_class' => '', |
|
1107 | - 'label_type' => '', |
|
1108 | - 'label_col' => '', |
|
1109 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1110 | - 'help_text' => '', |
|
1111 | - 'inline' => true, |
|
1112 | - 'required' => false, |
|
1113 | - 'options' => array(), |
|
1114 | - 'icon' => '', |
|
1115 | - 'no_wrap' => false, |
|
1116 | - 'element_require' => '', |
|
1117 | - // [%element_id%] == "1" |
|
1118 | - 'extra_attributes' => array(), |
|
1119 | - // an array of extra attributes |
|
1120 | - 'wrap_attributes' => array() |
|
1121 | - ); |
|
1122 | - |
|
1123 | - /** |
|
1094 | + public static function radio( $args = array() ) { |
|
1095 | + global $aui_bs5; |
|
1096 | + |
|
1097 | + $defaults = array( |
|
1098 | + 'class' => '', |
|
1099 | + 'wrap_class' => '', |
|
1100 | + 'id' => '', |
|
1101 | + 'title' => '', |
|
1102 | + 'horizontal' => false, |
|
1103 | + // sets the lable horizontal |
|
1104 | + 'value' => '', |
|
1105 | + 'label' => '', |
|
1106 | + 'label_class' => '', |
|
1107 | + 'label_type' => '', |
|
1108 | + 'label_col' => '', |
|
1109 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1110 | + 'help_text' => '', |
|
1111 | + 'inline' => true, |
|
1112 | + 'required' => false, |
|
1113 | + 'options' => array(), |
|
1114 | + 'icon' => '', |
|
1115 | + 'no_wrap' => false, |
|
1116 | + 'element_require' => '', |
|
1117 | + // [%element_id%] == "1" |
|
1118 | + 'extra_attributes' => array(), |
|
1119 | + // an array of extra attributes |
|
1120 | + 'wrap_attributes' => array() |
|
1121 | + ); |
|
1122 | + |
|
1123 | + /** |
|
1124 | 1124 | * Parse incoming $args into an array and merge it with $defaults |
1125 | 1125 | */ |
1126 | - $args = wp_parse_args( $args, $defaults ); |
|
1127 | - |
|
1128 | - // for now lets use horizontal for floating |
|
1129 | - if ( $args['label_type'] == 'floating' ) { |
|
1130 | - $args['label_type'] = 'horizontal'; |
|
1131 | - } |
|
1132 | - |
|
1133 | - $label_args = array( |
|
1134 | - 'title' => $args['label'], |
|
1135 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1136 | - 'label_type' => $args['label_type'], |
|
1137 | - 'label_col' => $args['label_col'] |
|
1138 | - ); |
|
1139 | - |
|
1140 | - if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) { |
|
1141 | - $label_args['class'] .= 'd-block '; |
|
1142 | - |
|
1143 | - if ( $args['label_type'] == 'hidden' ) { |
|
1144 | - $label_args['class'] .= 'sr-only '; |
|
1145 | - } |
|
1146 | - } |
|
1147 | - |
|
1148 | - $output = ''; |
|
1149 | - |
|
1150 | - // label before |
|
1151 | - if ( ! empty( $args['label'] ) ) { |
|
1152 | - $output .= self::label( $label_args, 'radio' ); |
|
1153 | - } |
|
1154 | - |
|
1155 | - // maybe horizontal label |
|
1156 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1157 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1158 | - $output .= '<div class="' . $input_col . '">'; |
|
1159 | - } |
|
1160 | - |
|
1161 | - if ( ! empty( $args['options'] ) ) { |
|
1162 | - $count = 0; |
|
1163 | - foreach ( $args['options'] as $value => $label ) { |
|
1164 | - $option_args = $args; |
|
1165 | - $option_args['value'] = $value; |
|
1166 | - $option_args['label'] = $label; |
|
1167 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1168 | - $output .= self::radio_option( $option_args, $count ); |
|
1169 | - $count ++; |
|
1170 | - } |
|
1171 | - } |
|
1172 | - |
|
1173 | - // help text |
|
1174 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1175 | - $output .= $help_text; |
|
1176 | - |
|
1177 | - // maybe horizontal label |
|
1178 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1179 | - $output .= '</div>'; |
|
1180 | - } |
|
1181 | - |
|
1182 | - // wrap |
|
1183 | - $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1184 | - $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1185 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1186 | - $output = self::wrap( array( |
|
1187 | - 'content' => $output, |
|
1188 | - 'class' => $wrap_class, |
|
1189 | - 'element_require' => $args['element_require'], |
|
1190 | - 'argument_id' => $args['id'], |
|
1191 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1192 | - ) ); |
|
1193 | - |
|
1194 | - |
|
1195 | - return $output; |
|
1196 | - } |
|
1197 | - |
|
1198 | - /** |
|
1126 | + $args = wp_parse_args( $args, $defaults ); |
|
1127 | + |
|
1128 | + // for now lets use horizontal for floating |
|
1129 | + if ( $args['label_type'] == 'floating' ) { |
|
1130 | + $args['label_type'] = 'horizontal'; |
|
1131 | + } |
|
1132 | + |
|
1133 | + $label_args = array( |
|
1134 | + 'title' => $args['label'], |
|
1135 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1136 | + 'label_type' => $args['label_type'], |
|
1137 | + 'label_col' => $args['label_col'] |
|
1138 | + ); |
|
1139 | + |
|
1140 | + if ( $args['label_type'] == 'top' || $args['label_type'] == 'hidden' ) { |
|
1141 | + $label_args['class'] .= 'd-block '; |
|
1142 | + |
|
1143 | + if ( $args['label_type'] == 'hidden' ) { |
|
1144 | + $label_args['class'] .= 'sr-only '; |
|
1145 | + } |
|
1146 | + } |
|
1147 | + |
|
1148 | + $output = ''; |
|
1149 | + |
|
1150 | + // label before |
|
1151 | + if ( ! empty( $args['label'] ) ) { |
|
1152 | + $output .= self::label( $label_args, 'radio' ); |
|
1153 | + } |
|
1154 | + |
|
1155 | + // maybe horizontal label |
|
1156 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1157 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1158 | + $output .= '<div class="' . $input_col . '">'; |
|
1159 | + } |
|
1160 | + |
|
1161 | + if ( ! empty( $args['options'] ) ) { |
|
1162 | + $count = 0; |
|
1163 | + foreach ( $args['options'] as $value => $label ) { |
|
1164 | + $option_args = $args; |
|
1165 | + $option_args['value'] = $value; |
|
1166 | + $option_args['label'] = $label; |
|
1167 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1168 | + $output .= self::radio_option( $option_args, $count ); |
|
1169 | + $count ++; |
|
1170 | + } |
|
1171 | + } |
|
1172 | + |
|
1173 | + // help text |
|
1174 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1175 | + $output .= $help_text; |
|
1176 | + |
|
1177 | + // maybe horizontal label |
|
1178 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1179 | + $output .= '</div>'; |
|
1180 | + } |
|
1181 | + |
|
1182 | + // wrap |
|
1183 | + $fg_class = $aui_bs5 ? 'mb-3' : 'form-group'; |
|
1184 | + $wrap_class = $args['label_type'] == 'horizontal' ? $fg_class . ' row' : $fg_class; |
|
1185 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1186 | + $output = self::wrap( array( |
|
1187 | + 'content' => $output, |
|
1188 | + 'class' => $wrap_class, |
|
1189 | + 'element_require' => $args['element_require'], |
|
1190 | + 'argument_id' => $args['id'], |
|
1191 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1192 | + ) ); |
|
1193 | + |
|
1194 | + |
|
1195 | + return $output; |
|
1196 | + } |
|
1197 | + |
|
1198 | + /** |
|
1199 | 1199 | * Build the component. |
1200 | 1200 | * |
1201 | 1201 | * @param array $args |
1202 | 1202 | * |
1203 | 1203 | * @return string The rendered component. |
1204 | 1204 | */ |
1205 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1206 | - $defaults = array( |
|
1207 | - 'class' => '', |
|
1208 | - 'id' => '', |
|
1209 | - 'title' => '', |
|
1210 | - 'value' => '', |
|
1211 | - 'required' => false, |
|
1212 | - 'inline' => true, |
|
1213 | - 'label' => '', |
|
1214 | - 'options' => array(), |
|
1215 | - 'icon' => '', |
|
1216 | - 'no_wrap' => false, |
|
1217 | - 'extra_attributes' => array() // an array of extra attributes |
|
1218 | - ); |
|
1219 | - |
|
1220 | - /** |
|
1205 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1206 | + $defaults = array( |
|
1207 | + 'class' => '', |
|
1208 | + 'id' => '', |
|
1209 | + 'title' => '', |
|
1210 | + 'value' => '', |
|
1211 | + 'required' => false, |
|
1212 | + 'inline' => true, |
|
1213 | + 'label' => '', |
|
1214 | + 'options' => array(), |
|
1215 | + 'icon' => '', |
|
1216 | + 'no_wrap' => false, |
|
1217 | + 'extra_attributes' => array() // an array of extra attributes |
|
1218 | + ); |
|
1219 | + |
|
1220 | + /** |
|
1221 | 1221 | * Parse incoming $args into an array and merge it with $defaults |
1222 | 1222 | */ |
1223 | - $args = wp_parse_args( $args, $defaults ); |
|
1224 | - |
|
1225 | - $output = ''; |
|
1226 | - |
|
1227 | - // open/type |
|
1228 | - $output .= '<input type="radio"'; |
|
1229 | - |
|
1230 | - // class |
|
1231 | - $output .= ' class="form-check-input" '; |
|
1232 | - |
|
1233 | - // name |
|
1234 | - if ( ! empty( $args['name'] ) ) { |
|
1235 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1236 | - } |
|
1237 | - |
|
1238 | - // id |
|
1239 | - if ( ! empty( $args['id'] ) ) { |
|
1240 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1241 | - } |
|
1242 | - |
|
1243 | - // title |
|
1244 | - if ( ! empty( $args['title'] ) ) { |
|
1245 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1246 | - } |
|
1247 | - |
|
1248 | - // value |
|
1249 | - if ( isset( $args['value'] ) ) { |
|
1250 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1251 | - } |
|
1252 | - |
|
1253 | - // checked, for radio and checkboxes |
|
1254 | - if ( $args['checked'] ) { |
|
1255 | - $output .= ' checked '; |
|
1256 | - } |
|
1257 | - |
|
1258 | - // data-attributes |
|
1259 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1260 | - |
|
1261 | - // aria-attributes |
|
1262 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1263 | - |
|
1264 | - // extra attributes |
|
1265 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1266 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1267 | - } |
|
1268 | - |
|
1269 | - // required |
|
1270 | - if ( ! empty( $args['required'] ) ) { |
|
1271 | - $output .= ' required '; |
|
1272 | - } |
|
1273 | - |
|
1274 | - // close opening tag |
|
1275 | - $output .= ' >'; |
|
1276 | - |
|
1277 | - // label |
|
1278 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1279 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1280 | - $output .= self::label( array( |
|
1281 | - 'title' => $args['label'], |
|
1282 | - 'for' => $args['id'] . $count, |
|
1283 | - 'class' => 'form-check-label' |
|
1284 | - ), 'radio' ); |
|
1285 | - } |
|
1286 | - |
|
1287 | - // wrap |
|
1288 | - if ( ! $args['no_wrap'] ) { |
|
1289 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1290 | - |
|
1291 | - // Unique wrap class |
|
1292 | - $uniq_class = 'fwrap'; |
|
1293 | - if ( ! empty( $args['name'] ) ) { |
|
1294 | - $uniq_class .= '-' . $args['name']; |
|
1295 | - } else if ( ! empty( $args['id'] ) ) { |
|
1296 | - $uniq_class .= '-' . $args['id']; |
|
1297 | - } |
|
1298 | - |
|
1299 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1300 | - $uniq_class .= '-' . $args['value']; |
|
1301 | - } else { |
|
1302 | - $uniq_class .= '-' . $count; |
|
1303 | - } |
|
1304 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1305 | - |
|
1306 | - $output = self::wrap( array( |
|
1307 | - 'content' => $output, |
|
1308 | - 'class' => $wrap_class |
|
1309 | - ) ); |
|
1310 | - } |
|
1311 | - |
|
1312 | - return $output; |
|
1313 | - } |
|
1223 | + $args = wp_parse_args( $args, $defaults ); |
|
1224 | + |
|
1225 | + $output = ''; |
|
1226 | + |
|
1227 | + // open/type |
|
1228 | + $output .= '<input type="radio"'; |
|
1229 | + |
|
1230 | + // class |
|
1231 | + $output .= ' class="form-check-input" '; |
|
1232 | + |
|
1233 | + // name |
|
1234 | + if ( ! empty( $args['name'] ) ) { |
|
1235 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1236 | + } |
|
1237 | + |
|
1238 | + // id |
|
1239 | + if ( ! empty( $args['id'] ) ) { |
|
1240 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1241 | + } |
|
1242 | + |
|
1243 | + // title |
|
1244 | + if ( ! empty( $args['title'] ) ) { |
|
1245 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1246 | + } |
|
1247 | + |
|
1248 | + // value |
|
1249 | + if ( isset( $args['value'] ) ) { |
|
1250 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1251 | + } |
|
1252 | + |
|
1253 | + // checked, for radio and checkboxes |
|
1254 | + if ( $args['checked'] ) { |
|
1255 | + $output .= ' checked '; |
|
1256 | + } |
|
1257 | + |
|
1258 | + // data-attributes |
|
1259 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1260 | + |
|
1261 | + // aria-attributes |
|
1262 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1263 | + |
|
1264 | + // extra attributes |
|
1265 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1266 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1267 | + } |
|
1268 | + |
|
1269 | + // required |
|
1270 | + if ( ! empty( $args['required'] ) ) { |
|
1271 | + $output .= ' required '; |
|
1272 | + } |
|
1273 | + |
|
1274 | + // close opening tag |
|
1275 | + $output .= ' >'; |
|
1276 | + |
|
1277 | + // label |
|
1278 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1279 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1280 | + $output .= self::label( array( |
|
1281 | + 'title' => $args['label'], |
|
1282 | + 'for' => $args['id'] . $count, |
|
1283 | + 'class' => 'form-check-label' |
|
1284 | + ), 'radio' ); |
|
1285 | + } |
|
1286 | + |
|
1287 | + // wrap |
|
1288 | + if ( ! $args['no_wrap'] ) { |
|
1289 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1290 | + |
|
1291 | + // Unique wrap class |
|
1292 | + $uniq_class = 'fwrap'; |
|
1293 | + if ( ! empty( $args['name'] ) ) { |
|
1294 | + $uniq_class .= '-' . $args['name']; |
|
1295 | + } else if ( ! empty( $args['id'] ) ) { |
|
1296 | + $uniq_class .= '-' . $args['id']; |
|
1297 | + } |
|
1298 | + |
|
1299 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1300 | + $uniq_class .= '-' . $args['value']; |
|
1301 | + } else { |
|
1302 | + $uniq_class .= '-' . $count; |
|
1303 | + } |
|
1304 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1305 | + |
|
1306 | + $output = self::wrap( array( |
|
1307 | + 'content' => $output, |
|
1308 | + 'class' => $wrap_class |
|
1309 | + ) ); |
|
1310 | + } |
|
1311 | + |
|
1312 | + return $output; |
|
1313 | + } |
|
1314 | 1314 | |
1315 | 1315 | } |
1316 | 1316 | \ No newline at end of file |