@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | */ |
51 | 51 | function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) { |
52 | 52 | $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id ); |
53 | - $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
53 | + $matching_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
54 | 54 | return reset( $matching_group ); |
55 | 55 | } |
56 | 56 | |
@@ -63,11 +63,11 @@ discard block |
||
63 | 63 | */ |
64 | 64 | function getpaid_get_subscription( $subscription ) { |
65 | 65 | |
66 | - if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
67 | - $subscription = new WPInv_Subscription( $subscription ); |
|
68 | - } |
|
66 | + if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
67 | + $subscription = new WPInv_Subscription( $subscription ); |
|
68 | + } |
|
69 | 69 | |
70 | - return $subscription->exists() ? $subscription : false; |
|
70 | + return $subscription->exists() ? $subscription : false; |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -81,28 +81,28 @@ discard block |
||
81 | 81 | */ |
82 | 82 | function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
83 | 83 | |
84 | - // Do not retrieve all fields if we just want the count. |
|
85 | - if ( 'count' == $return ) { |
|
86 | - $args['fields'] = 'id'; |
|
87 | - $args['number'] = 1; |
|
88 | - } |
|
84 | + // Do not retrieve all fields if we just want the count. |
|
85 | + if ( 'count' == $return ) { |
|
86 | + $args['fields'] = 'id'; |
|
87 | + $args['number'] = 1; |
|
88 | + } |
|
89 | 89 | |
90 | - // Do not count all matches if we just want the results. |
|
91 | - if ( 'results' == $return ) { |
|
92 | - $args['count_total'] = false; |
|
93 | - } |
|
90 | + // Do not count all matches if we just want the results. |
|
91 | + if ( 'results' == $return ) { |
|
92 | + $args['count_total'] = false; |
|
93 | + } |
|
94 | 94 | |
95 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
95 | + $query = new GetPaid_Subscriptions_Query( $args ); |
|
96 | 96 | |
97 | - if ( 'results' == $return ) { |
|
98 | - return $query->get_results(); |
|
99 | - } |
|
97 | + if ( 'results' == $return ) { |
|
98 | + return $query->get_results(); |
|
99 | + } |
|
100 | 100 | |
101 | - if ( 'count' == $return ) { |
|
102 | - return $query->get_total(); |
|
103 | - } |
|
101 | + if ( 'count' == $return ) { |
|
102 | + return $query->get_total(); |
|
103 | + } |
|
104 | 104 | |
105 | - return $query; |
|
105 | + return $query; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -112,18 +112,18 @@ discard block |
||
112 | 112 | */ |
113 | 113 | function getpaid_get_subscription_statuses() { |
114 | 114 | |
115 | - return apply_filters( |
|
116 | - 'getpaid_get_subscription_statuses', |
|
117 | - array( |
|
118 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
119 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
120 | - 'active' => __( 'Active', 'invoicing' ), |
|
121 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
122 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
123 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
124 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
125 | - ) |
|
126 | - ); |
|
115 | + return apply_filters( |
|
116 | + 'getpaid_get_subscription_statuses', |
|
117 | + array( |
|
118 | + 'pending' => __( 'Pending', 'invoicing' ), |
|
119 | + 'trialling' => __( 'Trialing', 'invoicing' ), |
|
120 | + 'active' => __( 'Active', 'invoicing' ), |
|
121 | + 'failing' => __( 'Failing', 'invoicing' ), |
|
122 | + 'expired' => __( 'Expired', 'invoicing' ), |
|
123 | + 'completed' => __( 'Complete', 'invoicing' ), |
|
124 | + 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
125 | + ) |
|
126 | + ); |
|
127 | 127 | |
128 | 128 | } |
129 | 129 | |
@@ -133,8 +133,8 @@ discard block |
||
133 | 133 | * @return string |
134 | 134 | */ |
135 | 135 | function getpaid_get_subscription_status_label( $status ) { |
136 | - $statuses = getpaid_get_subscription_statuses(); |
|
137 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
136 | + $statuses = getpaid_get_subscription_statuses(); |
|
137 | + return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
138 | 138 | } |
139 | 139 | |
140 | 140 | /** |
@@ -144,18 +144,18 @@ discard block |
||
144 | 144 | */ |
145 | 145 | function getpaid_get_subscription_status_classes() { |
146 | 146 | |
147 | - return apply_filters( |
|
148 | - 'getpaid_get_subscription_status_classes', |
|
149 | - array( |
|
150 | - 'pending' => 'badge-dark', |
|
151 | - 'trialling' => 'badge-info', |
|
152 | - 'active' => 'badge-success', |
|
153 | - 'failing' => 'badge-warning', |
|
154 | - 'expired' => 'badge-danger', |
|
155 | - 'completed' => 'badge-primary', |
|
156 | - 'cancelled' => 'badge-secondary', |
|
157 | - ) |
|
158 | - ); |
|
147 | + return apply_filters( |
|
148 | + 'getpaid_get_subscription_status_classes', |
|
149 | + array( |
|
150 | + 'pending' => 'badge-dark', |
|
151 | + 'trialling' => 'badge-info', |
|
152 | + 'active' => 'badge-success', |
|
153 | + 'failing' => 'badge-warning', |
|
154 | + 'expired' => 'badge-danger', |
|
155 | + 'completed' => 'badge-primary', |
|
156 | + 'cancelled' => 'badge-secondary', |
|
157 | + ) |
|
158 | + ); |
|
159 | 159 | |
160 | 160 | } |
161 | 161 | |
@@ -166,15 +166,15 @@ discard block |
||
166 | 166 | */ |
167 | 167 | function getpaid_get_subscription_status_counts( $args = array() ) { |
168 | 168 | |
169 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
170 | - $counts = array(); |
|
169 | + $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
170 | + $counts = array(); |
|
171 | 171 | |
172 | - foreach ( $statuses as $status ) { |
|
173 | - $_args = wp_parse_args( "status=$status", $args ); |
|
174 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
175 | - } |
|
172 | + foreach ( $statuses as $status ) { |
|
173 | + $_args = wp_parse_args( "status=$status", $args ); |
|
174 | + $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
175 | + } |
|
176 | 176 | |
177 | - return $counts; |
|
177 | + return $counts; |
|
178 | 178 | |
179 | 179 | } |
180 | 180 | |
@@ -185,32 +185,32 @@ discard block |
||
185 | 185 | */ |
186 | 186 | function getpaid_get_subscription_periods() { |
187 | 187 | |
188 | - return apply_filters( |
|
189 | - 'getpaid_get_subscription_periods', |
|
190 | - array( |
|
188 | + return apply_filters( |
|
189 | + 'getpaid_get_subscription_periods', |
|
190 | + array( |
|
191 | 191 | |
192 | - 'day' => array( |
|
193 | - 'singular' => __( '%s day', 'invoicing' ), |
|
194 | - 'plural' => __( '%d days', 'invoicing' ), |
|
195 | - ), |
|
192 | + 'day' => array( |
|
193 | + 'singular' => __( '%s day', 'invoicing' ), |
|
194 | + 'plural' => __( '%d days', 'invoicing' ), |
|
195 | + ), |
|
196 | 196 | |
197 | - 'week' => array( |
|
198 | - 'singular' => __( '%s week', 'invoicing' ), |
|
199 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
200 | - ), |
|
197 | + 'week' => array( |
|
198 | + 'singular' => __( '%s week', 'invoicing' ), |
|
199 | + 'plural' => __( '%d weeks', 'invoicing' ), |
|
200 | + ), |
|
201 | 201 | |
202 | - 'month' => array( |
|
203 | - 'singular' => __( '%s month', 'invoicing' ), |
|
204 | - 'plural' => __( '%d months', 'invoicing' ), |
|
205 | - ), |
|
202 | + 'month' => array( |
|
203 | + 'singular' => __( '%s month', 'invoicing' ), |
|
204 | + 'plural' => __( '%d months', 'invoicing' ), |
|
205 | + ), |
|
206 | 206 | |
207 | - 'year' => array( |
|
208 | - 'singular' => __( '%s year', 'invoicing' ), |
|
209 | - 'plural' => __( '%d years', 'invoicing' ), |
|
210 | - ), |
|
207 | + 'year' => array( |
|
208 | + 'singular' => __( '%s year', 'invoicing' ), |
|
209 | + 'plural' => __( '%d years', 'invoicing' ), |
|
210 | + ), |
|
211 | 211 | |
212 | - ) |
|
213 | - ); |
|
212 | + ) |
|
213 | + ); |
|
214 | 214 | |
215 | 215 | } |
216 | 216 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | * @return int |
222 | 222 | */ |
223 | 223 | function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
224 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
224 | + return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | /** |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @return string |
232 | 232 | */ |
233 | 233 | function getpaid_get_subscription_trial_period_period( $trial_period ) { |
234 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
234 | + return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /** |
@@ -242,8 +242,8 @@ discard block |
||
242 | 242 | * @return string |
243 | 243 | */ |
244 | 244 | function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
245 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
246 | - return strtolower( sanitize_text_field( $label ) ); |
|
245 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
246 | + return strtolower( sanitize_text_field( $label ) ); |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -254,22 +254,22 @@ discard block |
||
254 | 254 | */ |
255 | 255 | function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
256 | 256 | |
257 | - $periods = getpaid_get_subscription_periods(); |
|
258 | - $period = strtolower( $period ); |
|
257 | + $periods = getpaid_get_subscription_periods(); |
|
258 | + $period = strtolower( $period ); |
|
259 | 259 | |
260 | - if ( isset( $periods[ $period ] ) ) { |
|
261 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
262 | - } |
|
260 | + if ( isset( $periods[ $period ] ) ) { |
|
261 | + return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
262 | + } |
|
263 | 263 | |
264 | - // Backwards compatibility. |
|
265 | - foreach ( $periods as $key => $data ) { |
|
266 | - if ( strpos( $key, $period ) === 0 ) { |
|
267 | - return sprintf( $data['singular'], $singular_prefix ); |
|
268 | - } |
|
269 | - } |
|
264 | + // Backwards compatibility. |
|
265 | + foreach ( $periods as $key => $data ) { |
|
266 | + if ( strpos( $key, $period ) === 0 ) { |
|
267 | + return sprintf( $data['singular'], $singular_prefix ); |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | - // Invalid string. |
|
272 | - return ''; |
|
271 | + // Invalid string. |
|
272 | + return ''; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | /** |
@@ -281,22 +281,22 @@ discard block |
||
281 | 281 | */ |
282 | 282 | function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
283 | 283 | |
284 | - $periods = getpaid_get_subscription_periods(); |
|
285 | - $period = strtolower( $period ); |
|
284 | + $periods = getpaid_get_subscription_periods(); |
|
285 | + $period = strtolower( $period ); |
|
286 | 286 | |
287 | - if ( isset( $periods[ $period ] ) ) { |
|
288 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
289 | - } |
|
287 | + if ( isset( $periods[ $period ] ) ) { |
|
288 | + return sprintf( $periods[ $period ]['plural'], $interval ); |
|
289 | + } |
|
290 | 290 | |
291 | - // Backwards compatibility. |
|
292 | - foreach ( $periods as $key => $data ) { |
|
293 | - if ( strpos( $key, $period ) === 0 ) { |
|
294 | - return sprintf( $data['plural'], $interval ); |
|
295 | - } |
|
296 | - } |
|
291 | + // Backwards compatibility. |
|
292 | + foreach ( $periods as $key => $data ) { |
|
293 | + if ( strpos( $key, $period ) === 0 ) { |
|
294 | + return sprintf( $data['plural'], $interval ); |
|
295 | + } |
|
296 | + } |
|
297 | 297 | |
298 | - // Invalid string. |
|
299 | - return ''; |
|
298 | + // Invalid string. |
|
299 | + return ''; |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -307,92 +307,92 @@ discard block |
||
307 | 307 | */ |
308 | 308 | function getpaid_get_formatted_subscription_amount( $subscription ) { |
309 | 309 | |
310 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
311 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
312 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
313 | - $bill_times = $subscription->get_bill_times(); |
|
314 | - $bill_times_less = $bill_times - 1; |
|
315 | - |
|
316 | - if ( ! empty( $bill_times ) ) { |
|
317 | - $bill_times = $subscription->get_frequency() * $bill_times; |
|
318 | - $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
319 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
320 | - } |
|
321 | - |
|
322 | - // Trial periods. |
|
323 | - if ( $subscription->has_trial_period() ) { |
|
324 | - |
|
325 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
326 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
327 | - |
|
328 | - if ( empty( $bill_times ) ) { |
|
329 | - |
|
330 | - return sprintf( |
|
331 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
332 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
333 | - $initial, |
|
334 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
335 | - $recurring, |
|
336 | - $period |
|
337 | - ); |
|
338 | - |
|
339 | - } |
|
340 | - |
|
341 | - return sprintf( |
|
342 | - // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
343 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
344 | - $initial, |
|
345 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
346 | - $recurring, |
|
347 | - $period, |
|
348 | - $bill_times |
|
349 | - ); |
|
350 | - |
|
351 | - } |
|
352 | - |
|
353 | - if ( $initial != $recurring ) { |
|
354 | - |
|
355 | - if ( empty( $bill_times ) ) { |
|
356 | - |
|
357 | - return sprintf( |
|
358 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
359 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
360 | - $initial, |
|
361 | - $recurring, |
|
362 | - $period |
|
363 | - ); |
|
364 | - |
|
365 | - } |
|
366 | - |
|
367 | - return sprintf( |
|
368 | - // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
369 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
370 | - $initial, |
|
371 | - $recurring, |
|
372 | - $period, |
|
373 | - $bill_times_less |
|
374 | - ); |
|
375 | - |
|
376 | - } |
|
377 | - |
|
378 | - if ( empty( $bill_times ) ) { |
|
379 | - |
|
380 | - return sprintf( |
|
381 | - // translators: $1: is the recurring amount, $2: is the recurring period |
|
382 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
383 | - $initial, |
|
384 | - $period |
|
385 | - ); |
|
386 | - |
|
387 | - } |
|
388 | - |
|
389 | - return sprintf( |
|
390 | - // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
391 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
392 | - $bill_times, |
|
393 | - $initial, |
|
394 | - $period |
|
395 | - ); |
|
310 | + $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
311 | + $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
312 | + $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
313 | + $bill_times = $subscription->get_bill_times(); |
|
314 | + $bill_times_less = $bill_times - 1; |
|
315 | + |
|
316 | + if ( ! empty( $bill_times ) ) { |
|
317 | + $bill_times = $subscription->get_frequency() * $bill_times; |
|
318 | + $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() ); |
|
319 | + $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
320 | + } |
|
321 | + |
|
322 | + // Trial periods. |
|
323 | + if ( $subscription->has_trial_period() ) { |
|
324 | + |
|
325 | + $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
326 | + $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
327 | + |
|
328 | + if ( empty( $bill_times ) ) { |
|
329 | + |
|
330 | + return sprintf( |
|
331 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
|
332 | + _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
333 | + $initial, |
|
334 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
335 | + $recurring, |
|
336 | + $period |
|
337 | + ); |
|
338 | + |
|
339 | + } |
|
340 | + |
|
341 | + return sprintf( |
|
342 | + // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
|
343 | + _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
344 | + $initial, |
|
345 | + getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
346 | + $recurring, |
|
347 | + $period, |
|
348 | + $bill_times |
|
349 | + ); |
|
350 | + |
|
351 | + } |
|
352 | + |
|
353 | + if ( $initial != $recurring ) { |
|
354 | + |
|
355 | + if ( empty( $bill_times ) ) { |
|
356 | + |
|
357 | + return sprintf( |
|
358 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
|
359 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
360 | + $initial, |
|
361 | + $recurring, |
|
362 | + $period |
|
363 | + ); |
|
364 | + |
|
365 | + } |
|
366 | + |
|
367 | + return sprintf( |
|
368 | + // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
|
369 | + _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
370 | + $initial, |
|
371 | + $recurring, |
|
372 | + $period, |
|
373 | + $bill_times_less |
|
374 | + ); |
|
375 | + |
|
376 | + } |
|
377 | + |
|
378 | + if ( empty( $bill_times ) ) { |
|
379 | + |
|
380 | + return sprintf( |
|
381 | + // translators: $1: is the recurring amount, $2: is the recurring period |
|
382 | + _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
383 | + $initial, |
|
384 | + $period |
|
385 | + ); |
|
386 | + |
|
387 | + } |
|
388 | + |
|
389 | + return sprintf( |
|
390 | + // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
|
391 | + _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
392 | + $bill_times, |
|
393 | + $initial, |
|
394 | + $period |
|
395 | + ); |
|
396 | 396 | |
397 | 397 | } |
398 | 398 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | * @return WPInv_Subscription|false |
404 | 404 | */ |
405 | 405 | function getpaid_get_invoice_subscription( $invoice ) { |
406 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
406 | + return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | /** |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | * @param WPInv_Invoice $invoice |
413 | 413 | */ |
414 | 414 | function getpaid_activate_invoice_subscription( $invoice ) { |
415 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
416 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
417 | - $subscription->activate(); |
|
418 | - } |
|
415 | + $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
416 | + if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
417 | + $subscription->activate(); |
|
418 | + } |
|
419 | 419 | } |
420 | 420 | |
421 | 421 | /** |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @return WPInv_Subscriptions |
425 | 425 | */ |
426 | 426 | function getpaid_subscriptions() { |
427 | - return getpaid()->get( 'subscriptions' ); |
|
427 | + return getpaid()->get( 'subscriptions' ); |
|
428 | 428 | } |
429 | 429 | |
430 | 430 | /** |
@@ -443,15 +443,15 @@ discard block |
||
443 | 443 | return false; |
444 | 444 | } |
445 | 445 | |
446 | - // Fetch the invoice subscription. |
|
447 | - $subscription = getpaid_get_subscriptions( |
|
448 | - array( |
|
449 | - 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
450 | - 'number' => 1, |
|
451 | - ) |
|
452 | - ); |
|
446 | + // Fetch the invoice subscription. |
|
447 | + $subscription = getpaid_get_subscriptions( |
|
448 | + array( |
|
449 | + 'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(), |
|
450 | + 'number' => 1, |
|
451 | + ) |
|
452 | + ); |
|
453 | 453 | |
454 | - return empty( $subscription ) ? false : $subscription[0]; |
|
454 | + return empty( $subscription ) ? false : $subscription[0]; |
|
455 | 455 | |
456 | 456 | } |
457 | 457 | |
@@ -468,48 +468,48 @@ discard block |
||
468 | 468 | */ |
469 | 469 | function getpaid_get_recurring_item_key( $cart_item ) { |
470 | 470 | |
471 | - $cart_key = 'renews_'; |
|
472 | - $interval = $cart_item->get_recurring_interval(); |
|
473 | - $period = $cart_item->get_recurring_period( true ); |
|
474 | - $length = $cart_item->get_recurring_limit() * $interval; |
|
475 | - $trial_period = $cart_item->get_trial_period( true ); |
|
476 | - $trial_length = $cart_item->get_trial_interval(); |
|
477 | - |
|
478 | - // First start with the billing interval and period |
|
479 | - switch ( $interval ) { |
|
480 | - case 1: |
|
481 | - if ( 'day' == $period ) { |
|
482 | - $cart_key .= 'daily'; |
|
483 | - } else { |
|
484 | - $cart_key .= sprintf( '%sly', $period ); |
|
485 | - } |
|
486 | - break; |
|
487 | - case 2: |
|
488 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
489 | - break; |
|
490 | - case 3: |
|
491 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
492 | - break; |
|
493 | - default: |
|
494 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
495 | - break; |
|
496 | - } |
|
497 | - |
|
498 | - // Maybe add the optional maximum billing periods... |
|
499 | - if ( $length > 0 ) { |
|
500 | - $cart_key .= '_for_'; |
|
501 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
502 | - if ( $length > 1 ) { |
|
503 | - $cart_key .= 's'; |
|
504 | - } |
|
505 | - } |
|
506 | - |
|
507 | - // And an optional free trial. |
|
508 | - if ( $cart_item->has_free_trial() ) { |
|
509 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
510 | - } |
|
511 | - |
|
512 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
471 | + $cart_key = 'renews_'; |
|
472 | + $interval = $cart_item->get_recurring_interval(); |
|
473 | + $period = $cart_item->get_recurring_period( true ); |
|
474 | + $length = $cart_item->get_recurring_limit() * $interval; |
|
475 | + $trial_period = $cart_item->get_trial_period( true ); |
|
476 | + $trial_length = $cart_item->get_trial_interval(); |
|
477 | + |
|
478 | + // First start with the billing interval and period |
|
479 | + switch ( $interval ) { |
|
480 | + case 1: |
|
481 | + if ( 'day' == $period ) { |
|
482 | + $cart_key .= 'daily'; |
|
483 | + } else { |
|
484 | + $cart_key .= sprintf( '%sly', $period ); |
|
485 | + } |
|
486 | + break; |
|
487 | + case 2: |
|
488 | + $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
489 | + break; |
|
490 | + case 3: |
|
491 | + $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
492 | + break; |
|
493 | + default: |
|
494 | + $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
495 | + break; |
|
496 | + } |
|
497 | + |
|
498 | + // Maybe add the optional maximum billing periods... |
|
499 | + if ( $length > 0 ) { |
|
500 | + $cart_key .= '_for_'; |
|
501 | + $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
502 | + if ( $length > 1 ) { |
|
503 | + $cart_key .= 's'; |
|
504 | + } |
|
505 | + } |
|
506 | + |
|
507 | + // And an optional free trial. |
|
508 | + if ( $cart_item->has_free_trial() ) { |
|
509 | + $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
510 | + } |
|
511 | + |
|
512 | + return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
513 | 513 | } |
514 | 514 | |
515 | 515 | /** |
@@ -520,16 +520,16 @@ discard block |
||
520 | 520 | */ |
521 | 521 | function getpaid_get_subscription_groups( $invoice ) { |
522 | 522 | |
523 | - // Generate subscription groups. |
|
524 | - $subscription_groups = array(); |
|
525 | - foreach ( $invoice->get_items() as $item ) { |
|
523 | + // Generate subscription groups. |
|
524 | + $subscription_groups = array(); |
|
525 | + foreach ( $invoice->get_items() as $item ) { |
|
526 | 526 | |
527 | - if ( $item->is_recurring() ) { |
|
528 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
529 | - } |
|
527 | + if ( $item->is_recurring() ) { |
|
528 | + $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
529 | + } |
|
530 | 530 | } |
531 | 531 | |
532 | - return $subscription_groups; |
|
532 | + return $subscription_groups; |
|
533 | 533 | } |
534 | 534 | |
535 | 535 | /** |
@@ -543,56 +543,56 @@ discard block |
||
543 | 543 | */ |
544 | 544 | function getpaid_calculate_subscription_totals( $invoice ) { |
545 | 545 | |
546 | - // Generate subscription groups. |
|
547 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
546 | + // Generate subscription groups. |
|
547 | + $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
548 | 548 | |
549 | - // Now let's calculate the totals for each group of subscriptions |
|
550 | - $subscription_totals = array(); |
|
549 | + // Now let's calculate the totals for each group of subscriptions |
|
550 | + $subscription_totals = array(); |
|
551 | 551 | |
552 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
552 | + foreach ( $subscription_groups as $subscription_key => $items ) { |
|
553 | 553 | |
554 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
554 | + if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
555 | 555 | |
556 | - $subscription_totals[ $subscription_key ] = array( |
|
557 | - 'initial_total' => 0, |
|
558 | - 'recurring_total' => 0, |
|
559 | - 'items' => array(), |
|
560 | - 'trialling' => false, |
|
561 | - ); |
|
556 | + $subscription_totals[ $subscription_key ] = array( |
|
557 | + 'initial_total' => 0, |
|
558 | + 'recurring_total' => 0, |
|
559 | + 'items' => array(), |
|
560 | + 'trialling' => false, |
|
561 | + ); |
|
562 | 562 | |
563 | - } |
|
563 | + } |
|
564 | 564 | |
565 | - /** |
|
566 | - * Get the totals of the group. |
|
567 | - * @var GetPaid_Form_Item $item |
|
568 | - */ |
|
569 | - foreach ( $items as $item ) { |
|
565 | + /** |
|
566 | + * Get the totals of the group. |
|
567 | + * @var GetPaid_Form_Item $item |
|
568 | + */ |
|
569 | + foreach ( $items as $item ) { |
|
570 | 570 | |
571 | - $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
572 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
573 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
574 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
575 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
576 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
577 | - $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
571 | + $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ] = $item->prepare_data_for_saving(); |
|
572 | + $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
573 | + $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
574 | + $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
575 | + $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total() + $item->item_tax - $item->item_discount; |
|
576 | + $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount; |
|
577 | + $subscription_totals[ $subscription_key ]['recurring_limit'] = $item->get_recurring_limit(); |
|
578 | 578 | |
579 | - // Calculate the next renewal date. |
|
580 | - $period = $item->get_recurring_period( true ); |
|
581 | - $interval = $item->get_recurring_interval(); |
|
579 | + // Calculate the next renewal date. |
|
580 | + $period = $item->get_recurring_period( true ); |
|
581 | + $interval = $item->get_recurring_interval(); |
|
582 | 582 | |
583 | - // If the subscription item has a trial period... |
|
584 | - if ( $item->has_free_trial() ) { |
|
585 | - $period = $item->get_trial_period( true ); |
|
586 | - $interval = $item->get_trial_interval(); |
|
587 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
588 | - } |
|
583 | + // If the subscription item has a trial period... |
|
584 | + if ( $item->has_free_trial() ) { |
|
585 | + $period = $item->get_trial_period( true ); |
|
586 | + $interval = $item->get_trial_interval(); |
|
587 | + $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
588 | + } |
|
589 | 589 | |
590 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
590 | + $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
591 | 591 | |
592 | - } |
|
592 | + } |
|
593 | 593 | } |
594 | 594 | |
595 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
595 | + return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
596 | 596 | } |
597 | 597 | |
598 | 598 | /** |
@@ -603,16 +603,16 @@ discard block |
||
603 | 603 | */ |
604 | 604 | function getpaid_should_group_subscriptions( $invoice ) { |
605 | 605 | |
606 | - $recurring_items = 0; |
|
606 | + $recurring_items = 0; |
|
607 | 607 | |
608 | - foreach ( $invoice->get_items() as $item ) { |
|
608 | + foreach ( $invoice->get_items() as $item ) { |
|
609 | 609 | |
610 | - if ( $item->is_recurring() ) { |
|
611 | - $recurring_items ++; |
|
612 | - } |
|
610 | + if ( $item->is_recurring() ) { |
|
611 | + $recurring_items ++; |
|
612 | + } |
|
613 | 613 | } |
614 | 614 | |
615 | - return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
615 | + return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice ); |
|
616 | 616 | } |
617 | 617 | |
618 | 618 | /** |
@@ -623,39 +623,39 @@ discard block |
||
623 | 623 | * @return int |
624 | 624 | */ |
625 | 625 | function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) { |
626 | - global $wpdb; |
|
626 | + global $wpdb; |
|
627 | 627 | |
628 | - $parent_invoice_id = (int) $parent_invoice_id; |
|
628 | + $parent_invoice_id = (int) $parent_invoice_id; |
|
629 | 629 | |
630 | - if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
630 | + if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) { |
|
631 | 631 | |
632 | - return (int) $wpdb->get_var( |
|
633 | - $wpdb->prepare( |
|
634 | - "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
635 | - $parent_invoice_id, |
|
636 | - $parent_invoice_id |
|
637 | - ) |
|
638 | - ); |
|
632 | + return (int) $wpdb->get_var( |
|
633 | + $wpdb->prepare( |
|
634 | + "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
635 | + $parent_invoice_id, |
|
636 | + $parent_invoice_id |
|
637 | + ) |
|
638 | + ); |
|
639 | 639 | |
640 | - } |
|
640 | + } |
|
641 | 641 | |
642 | - $invoice_ids = $wpdb->get_col( |
|
643 | - $wpdb->prepare( |
|
644 | - "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
645 | - $parent_invoice_id, |
|
646 | - $parent_invoice_id |
|
647 | - ) |
|
648 | - ); |
|
642 | + $invoice_ids = $wpdb->get_col( |
|
643 | + $wpdb->prepare( |
|
644 | + "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )", |
|
645 | + $parent_invoice_id, |
|
646 | + $parent_invoice_id |
|
647 | + ) |
|
648 | + ); |
|
649 | 649 | |
650 | - $count = 0; |
|
650 | + $count = 0; |
|
651 | 651 | |
652 | - foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
652 | + foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) { |
|
653 | 653 | |
654 | - if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
655 | - $count ++; |
|
656 | - continue; |
|
657 | - } |
|
654 | + if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) { |
|
655 | + $count ++; |
|
656 | + continue; |
|
657 | + } |
|
658 | 658 | } |
659 | 659 | |
660 | - return $count; |
|
660 | + return $count; |
|
661 | 661 | } |
@@ -57,16 +57,16 @@ discard block |
||
57 | 57 | $args = wp_parse_args( |
58 | 58 | $args, |
59 | 59 | array( |
60 | - 'status' => array( 'publish' ), |
|
61 | - 'limit' => get_option( 'posts_per_page' ), |
|
62 | - 'page' => 1, |
|
63 | - 'exclude' => array(), |
|
64 | - 'orderby' => 'date', |
|
65 | - 'order' => 'DESC', |
|
66 | - 'type' => wpinv_item_types(), |
|
67 | - 'meta_query' => array(), |
|
68 | - 'return' => 'objects', |
|
69 | - 'paginate' => false, |
|
60 | + 'status' => array( 'publish' ), |
|
61 | + 'limit' => get_option( 'posts_per_page' ), |
|
62 | + 'page' => 1, |
|
63 | + 'exclude' => array(), |
|
64 | + 'orderby' => 'date', |
|
65 | + 'order' => 'DESC', |
|
66 | + 'type' => wpinv_item_types(), |
|
67 | + 'meta_query' => array(), |
|
68 | + 'return' => 'objects', |
|
69 | + 'paginate' => false, |
|
70 | 70 | ) |
71 | 71 | ); |
72 | 72 | |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | |
207 | 207 | function wpinv_get_item_types() { |
208 | 208 | $item_types = array( |
209 | - 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | - 'fee' => __( 'Fee', 'invoicing' ), |
|
211 | - ); |
|
209 | + 'custom' => __( 'Standard', 'invoicing' ), |
|
210 | + 'fee' => __( 'Fee', 'invoicing' ), |
|
211 | + ); |
|
212 | 212 | return apply_filters( 'wpinv_get_item_types', $item_types ); |
213 | 213 | } |
214 | 214 | |
@@ -249,17 +249,17 @@ discard block |
||
249 | 249 | function wpinv_get_random_items( $num = 3, $post_ids = true ) { |
250 | 250 | if ( $post_ids ) { |
251 | 251 | $args = array( |
252 | - 'post_type' => 'wpi_item', |
|
253 | - 'orderby' => 'rand', |
|
254 | - 'post_count' => $num, |
|
255 | - 'fields' => 'ids', |
|
256 | - ); |
|
252 | + 'post_type' => 'wpi_item', |
|
253 | + 'orderby' => 'rand', |
|
254 | + 'post_count' => $num, |
|
255 | + 'fields' => 'ids', |
|
256 | + ); |
|
257 | 257 | } else { |
258 | 258 | $args = array( |
259 | - 'post_type' => 'wpi_item', |
|
260 | - 'orderby' => 'rand', |
|
261 | - 'post_count' => $num, |
|
262 | - ); |
|
259 | + 'post_type' => 'wpi_item', |
|
260 | + 'orderby' => 'rand', |
|
261 | + 'post_count' => $num, |
|
262 | + ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $args = apply_filters( 'wpinv_get_random_items', $args ); |
@@ -427,10 +427,10 @@ discard block |
||
427 | 427 | $bill_times_less = $bill_times - 1; |
428 | 428 | |
429 | 429 | if ( ! empty( $bill_times ) ) { |
430 | - $bill_times = $item->get_recurring_interval() * $bill_times; |
|
430 | + $bill_times = $item->get_recurring_interval() * $bill_times; |
|
431 | 431 | $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() ); |
432 | - $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
433 | - } |
|
432 | + $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
|
433 | + } |
|
434 | 434 | |
435 | 435 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
436 | 436 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
@@ -12,59 +12,59 @@ |
||
12 | 12 | $label = empty( $label ) ? '' : wp_kses_post( $label ); |
13 | 13 | $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) ); |
14 | 14 | if ( ! empty( $required ) ) { |
15 | - $label .= "<span class='text-danger'> *</span>"; |
|
15 | + $label .= "<span class='text-danger'> *</span>"; |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | $disable_dates = array(); |
19 | 19 | |
20 | 20 | if ( ! empty( $disabled_dates ) ) { |
21 | - $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | - $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | - $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
21 | + $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates ); |
|
22 | + $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates ); |
|
23 | + $disabled_dates = array_filter( explode( ',', $disabled_dates ) ); |
|
24 | 24 | |
25 | - foreach ( $disabled_dates as $disabled_date ) { |
|
25 | + foreach ( $disabled_dates as $disabled_date ) { |
|
26 | 26 | |
27 | - $disabled_date = trim( $disabled_date ); |
|
27 | + $disabled_date = trim( $disabled_date ); |
|
28 | 28 | |
29 | - if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | - $disable_dates[] = $disabled_date; |
|
31 | - continue; |
|
32 | - } |
|
29 | + if ( false === strpos( $disabled_date, '|' ) ) { |
|
30 | + $disable_dates[] = $disabled_date; |
|
31 | + continue; |
|
32 | + } |
|
33 | 33 | |
34 | - $disabled_date = explode( '|', $disabled_date ); |
|
35 | - $disable_dates[] = array( |
|
36 | - 'from' => trim( $disabled_date[0] ), |
|
37 | - 'to' => trim( $disabled_date[1] ), |
|
38 | - ); |
|
34 | + $disabled_date = explode( '|', $disabled_date ); |
|
35 | + $disable_dates[] = array( |
|
36 | + 'from' => trim( $disabled_date[0] ), |
|
37 | + 'to' => trim( $disabled_date[1] ), |
|
38 | + ); |
|
39 | 39 | |
40 | - } |
|
40 | + } |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | $options = array( |
44 | - 'data-default-date' => empty( $default_date ) ? false : $default_date, |
|
45 | - 'data-min-date' => empty( $min_date ) ? false : $min_date, |
|
46 | - 'data-max-date' => empty( $max_date ) ? false : $max_date, |
|
47 | - 'data-mode' => empty( $mode ) ? 'single' : $mode, |
|
48 | - 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
49 | - 'data-date-format' => 'Y-m-d', |
|
50 | - 'data-alt-input' => 'true', |
|
51 | - 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
52 | - 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
44 | + 'data-default-date' => empty( $default_date ) ? false : $default_date, |
|
45 | + 'data-min-date' => empty( $min_date ) ? false : $min_date, |
|
46 | + 'data-max-date' => empty( $max_date ) ? false : $max_date, |
|
47 | + 'data-mode' => empty( $mode ) ? 'single' : $mode, |
|
48 | + 'data-alt-format' => get_option( 'date_format', 'F j, Y' ), |
|
49 | + 'data-date-format' => 'Y-m-d', |
|
50 | + 'data-alt-input' => 'true', |
|
51 | + 'data-disable_alt' => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ), |
|
52 | + 'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ), |
|
53 | 53 | ); |
54 | 54 | |
55 | 55 | aui()->input( |
56 | - array( |
|
57 | - 'name' => esc_attr( $id ), |
|
58 | - 'id' => esc_attr( $element_id ), |
|
59 | - 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
60 | - 'required' => ! empty( $required ), |
|
61 | - 'label' => $label, |
|
62 | - 'label_type' => 'vertical', |
|
63 | - 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
64 | - 'type' => 'datepicker', |
|
65 | - 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
66 | - 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
67 | - 'value' => $query_value, |
|
68 | - ), |
|
69 | - true |
|
56 | + array( |
|
57 | + 'name' => esc_attr( $id ), |
|
58 | + 'id' => esc_attr( $element_id ), |
|
59 | + 'placeholder' => empty( $placeholder ) ? '' : esc_attr( $placeholder ), |
|
60 | + 'required' => ! empty( $required ), |
|
61 | + 'label' => $label, |
|
62 | + 'label_type' => 'vertical', |
|
63 | + 'help_text' => empty( $description ) ? '' : wp_kses_post( $description ), |
|
64 | + 'type' => 'datepicker', |
|
65 | + 'class' => $label_class . ' getpaid-init-flatpickr flatpickr-input', |
|
66 | + 'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ), |
|
67 | + 'value' => $query_value, |
|
68 | + ), |
|
69 | + true |
|
70 | 70 | ); |
@@ -20,237 +20,237 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class GetPaid_Installer { |
22 | 22 | |
23 | - /** |
|
24 | - * Upgrades the install. |
|
25 | - * |
|
26 | - * @param string $upgrade_from The current invoicing version. |
|
27 | - */ |
|
28 | - public function upgrade_db( $upgrade_from ) { |
|
29 | - |
|
30 | - // Save the current invoicing version. |
|
31 | - update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | - |
|
33 | - // Setup the invoice Custom Post Type. |
|
34 | - GetPaid_Post_Types::register_post_types(); |
|
35 | - |
|
36 | - // Clear the permalinks |
|
37 | - flush_rewrite_rules(); |
|
38 | - |
|
39 | - // Maybe create new/missing pages. |
|
40 | - $this->create_pages(); |
|
41 | - |
|
42 | - // Maybe re(add) admin capabilities. |
|
43 | - $this->add_capabilities(); |
|
44 | - |
|
45 | - // Maybe create the default payment form. |
|
46 | - wpinv_get_default_payment_form(); |
|
47 | - |
|
48 | - // Create any missing database tables. |
|
49 | - $method = "upgrade_from_$upgrade_from"; |
|
50 | - |
|
51 | - $installed = get_option( 'gepaid_installed_on' ); |
|
52 | - |
|
53 | - if ( empty( $installed ) ) { |
|
54 | - update_option( 'gepaid_installed_on', time() ); |
|
55 | - } |
|
56 | - |
|
57 | - if ( method_exists( $this, $method ) ) { |
|
58 | - $this->$method(); |
|
59 | - } |
|
60 | - |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Do a fresh install. |
|
65 | - * |
|
66 | - */ |
|
67 | - public function upgrade_from_0() { |
|
68 | - $this->create_subscriptions_table(); |
|
69 | - $this->create_invoices_table(); |
|
70 | - $this->create_invoice_items_table(); |
|
71 | - |
|
72 | - // Save default tax rates. |
|
73 | - update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Upgrade to 0.0.5 |
|
78 | - * |
|
79 | - */ |
|
80 | - public function upgrade_from_004() { |
|
81 | - global $wpdb; |
|
82 | - |
|
83 | - // Invoices. |
|
84 | - $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | - if ( ! empty( $results ) ) { |
|
86 | - $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | - |
|
88 | - // Clean post cache |
|
89 | - foreach ( $results as $row ) { |
|
90 | - clean_post_cache( $row->ID ); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - // Item meta key changes |
|
95 | - $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
96 | - $results = $wpdb->get_results( $query ); |
|
97 | - |
|
98 | - if ( ! empty( $results ) ) { |
|
99 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
100 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
101 | - $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
102 | - |
|
103 | - foreach ( $results as $row ) { |
|
104 | - clean_post_cache( $row->post_id ); |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - $this->upgrade_from_102(); |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Upgrade to 1.0.3 |
|
113 | - * |
|
114 | - */ |
|
115 | - public function upgrade_from_102() { |
|
116 | - $this->create_subscriptions_table(); |
|
117 | - $this->upgrade_from_118(); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Upgrade to version 2.0.0. |
|
122 | - * |
|
123 | - */ |
|
124 | - public function upgrade_from_118() { |
|
125 | - $this->create_invoices_table(); |
|
126 | - $this->create_invoice_items_table(); |
|
127 | - $this->migrate_old_invoices(); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Upgrade to version 2.0.8. |
|
132 | - * |
|
133 | - */ |
|
134 | - public function upgrade_from_207() { |
|
135 | - global $wpdb; |
|
136 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
137 | - $this->upgrade_from_2615(); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Upgrade to version 2.6.16. |
|
142 | - * |
|
143 | - */ |
|
144 | - public function upgrade_from_2615() { |
|
145 | - global $wpdb; |
|
146 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
147 | - $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Give administrators the capability to manage GetPaid. |
|
152 | - * |
|
153 | - */ |
|
154 | - public function add_capabilities() { |
|
155 | - $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Retreives GetPaid pages. |
|
160 | - * |
|
161 | - */ |
|
162 | - public static function get_pages() { |
|
163 | - |
|
164 | - return apply_filters( |
|
165 | - 'wpinv_create_pages', |
|
166 | - array( |
|
167 | - |
|
168 | - // Checkout page. |
|
169 | - 'checkout_page' => array( |
|
170 | - 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
171 | - 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
172 | - 'content' => ' |
|
23 | + /** |
|
24 | + * Upgrades the install. |
|
25 | + * |
|
26 | + * @param string $upgrade_from The current invoicing version. |
|
27 | + */ |
|
28 | + public function upgrade_db( $upgrade_from ) { |
|
29 | + |
|
30 | + // Save the current invoicing version. |
|
31 | + update_option( 'wpinv_version', WPINV_VERSION ); |
|
32 | + |
|
33 | + // Setup the invoice Custom Post Type. |
|
34 | + GetPaid_Post_Types::register_post_types(); |
|
35 | + |
|
36 | + // Clear the permalinks |
|
37 | + flush_rewrite_rules(); |
|
38 | + |
|
39 | + // Maybe create new/missing pages. |
|
40 | + $this->create_pages(); |
|
41 | + |
|
42 | + // Maybe re(add) admin capabilities. |
|
43 | + $this->add_capabilities(); |
|
44 | + |
|
45 | + // Maybe create the default payment form. |
|
46 | + wpinv_get_default_payment_form(); |
|
47 | + |
|
48 | + // Create any missing database tables. |
|
49 | + $method = "upgrade_from_$upgrade_from"; |
|
50 | + |
|
51 | + $installed = get_option( 'gepaid_installed_on' ); |
|
52 | + |
|
53 | + if ( empty( $installed ) ) { |
|
54 | + update_option( 'gepaid_installed_on', time() ); |
|
55 | + } |
|
56 | + |
|
57 | + if ( method_exists( $this, $method ) ) { |
|
58 | + $this->$method(); |
|
59 | + } |
|
60 | + |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Do a fresh install. |
|
65 | + * |
|
66 | + */ |
|
67 | + public function upgrade_from_0() { |
|
68 | + $this->create_subscriptions_table(); |
|
69 | + $this->create_invoices_table(); |
|
70 | + $this->create_invoice_items_table(); |
|
71 | + |
|
72 | + // Save default tax rates. |
|
73 | + update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) ); |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Upgrade to 0.0.5 |
|
78 | + * |
|
79 | + */ |
|
80 | + public function upgrade_from_004() { |
|
81 | + global $wpdb; |
|
82 | + |
|
83 | + // Invoices. |
|
84 | + $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
85 | + if ( ! empty( $results ) ) { |
|
86 | + $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" ); |
|
87 | + |
|
88 | + // Clean post cache |
|
89 | + foreach ( $results as $row ) { |
|
90 | + clean_post_cache( $row->ID ); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + // Item meta key changes |
|
95 | + $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )"; |
|
96 | + $results = $wpdb->get_results( $query ); |
|
97 | + |
|
98 | + if ( ! empty( $results ) ) { |
|
99 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" ); |
|
100 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" ); |
|
101 | + $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" ); |
|
102 | + |
|
103 | + foreach ( $results as $row ) { |
|
104 | + clean_post_cache( $row->post_id ); |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + $this->upgrade_from_102(); |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Upgrade to 1.0.3 |
|
113 | + * |
|
114 | + */ |
|
115 | + public function upgrade_from_102() { |
|
116 | + $this->create_subscriptions_table(); |
|
117 | + $this->upgrade_from_118(); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Upgrade to version 2.0.0. |
|
122 | + * |
|
123 | + */ |
|
124 | + public function upgrade_from_118() { |
|
125 | + $this->create_invoices_table(); |
|
126 | + $this->create_invoice_items_table(); |
|
127 | + $this->migrate_old_invoices(); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Upgrade to version 2.0.8. |
|
132 | + * |
|
133 | + */ |
|
134 | + public function upgrade_from_207() { |
|
135 | + global $wpdb; |
|
136 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" ); |
|
137 | + $this->upgrade_from_2615(); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Upgrade to version 2.6.16. |
|
142 | + * |
|
143 | + */ |
|
144 | + public function upgrade_from_2615() { |
|
145 | + global $wpdb; |
|
146 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
147 | + $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" ); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Give administrators the capability to manage GetPaid. |
|
152 | + * |
|
153 | + */ |
|
154 | + public function add_capabilities() { |
|
155 | + $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' ); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Retreives GetPaid pages. |
|
160 | + * |
|
161 | + */ |
|
162 | + public static function get_pages() { |
|
163 | + |
|
164 | + return apply_filters( |
|
165 | + 'wpinv_create_pages', |
|
166 | + array( |
|
167 | + |
|
168 | + // Checkout page. |
|
169 | + 'checkout_page' => array( |
|
170 | + 'name' => _x( 'gp-checkout', 'Page slug', 'invoicing' ), |
|
171 | + 'title' => _x( 'Checkout', 'Page title', 'invoicing' ), |
|
172 | + 'content' => ' |
|
173 | 173 | <!-- wp:shortcode --> |
174 | 174 | [wpinv_checkout] |
175 | 175 | <!-- /wp:shortcode --> |
176 | 176 | ', |
177 | - 'parent' => '', |
|
178 | - ), |
|
179 | - |
|
180 | - // Invoice history page. |
|
181 | - 'invoice_history_page' => array( |
|
182 | - 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
183 | - 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
184 | - 'content' => ' |
|
177 | + 'parent' => '', |
|
178 | + ), |
|
179 | + |
|
180 | + // Invoice history page. |
|
181 | + 'invoice_history_page' => array( |
|
182 | + 'name' => _x( 'gp-invoices', 'Page slug', 'invoicing' ), |
|
183 | + 'title' => _x( 'My Invoices', 'Page title', 'invoicing' ), |
|
184 | + 'content' => ' |
|
185 | 185 | <!-- wp:shortcode --> |
186 | 186 | [wpinv_history] |
187 | 187 | <!-- /wp:shortcode --> |
188 | 188 | ', |
189 | - 'parent' => '', |
|
190 | - ), |
|
191 | - |
|
192 | - // Success page content. |
|
193 | - 'success_page' => array( |
|
194 | - 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
195 | - 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
196 | - 'content' => ' |
|
189 | + 'parent' => '', |
|
190 | + ), |
|
191 | + |
|
192 | + // Success page content. |
|
193 | + 'success_page' => array( |
|
194 | + 'name' => _x( 'gp-receipt', 'Page slug', 'invoicing' ), |
|
195 | + 'title' => _x( 'Payment Confirmation', 'Page title', 'invoicing' ), |
|
196 | + 'content' => ' |
|
197 | 197 | <!-- wp:shortcode --> |
198 | 198 | [wpinv_receipt] |
199 | 199 | <!-- /wp:shortcode --> |
200 | 200 | ', |
201 | - 'parent' => 'gp-checkout', |
|
202 | - ), |
|
203 | - |
|
204 | - // Failure page content. |
|
205 | - 'failure_page' => array( |
|
206 | - 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
207 | - 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
208 | - 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
209 | - 'parent' => 'gp-checkout', |
|
210 | - ), |
|
211 | - |
|
212 | - // Subscriptions history page. |
|
213 | - 'invoice_subscription_page' => array( |
|
214 | - 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
215 | - 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
216 | - 'content' => ' |
|
201 | + 'parent' => 'gp-checkout', |
|
202 | + ), |
|
203 | + |
|
204 | + // Failure page content. |
|
205 | + 'failure_page' => array( |
|
206 | + 'name' => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ), |
|
207 | + 'title' => _x( 'Transaction Failed', 'Page title', 'invoicing' ), |
|
208 | + 'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ), |
|
209 | + 'parent' => 'gp-checkout', |
|
210 | + ), |
|
211 | + |
|
212 | + // Subscriptions history page. |
|
213 | + 'invoice_subscription_page' => array( |
|
214 | + 'name' => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ), |
|
215 | + 'title' => _x( 'My Subscriptions', 'Page title', 'invoicing' ), |
|
216 | + 'content' => ' |
|
217 | 217 | <!-- wp:shortcode --> |
218 | 218 | [wpinv_subscriptions] |
219 | 219 | <!-- /wp:shortcode --> |
220 | 220 | ', |
221 | - 'parent' => '', |
|
222 | - ), |
|
221 | + 'parent' => '', |
|
222 | + ), |
|
223 | 223 | |
224 | - ) |
|
225 | - ); |
|
224 | + ) |
|
225 | + ); |
|
226 | 226 | |
227 | - } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * Re-create GetPaid pages. |
|
231 | - * |
|
232 | - */ |
|
233 | - public function create_pages() { |
|
229 | + /** |
|
230 | + * Re-create GetPaid pages. |
|
231 | + * |
|
232 | + */ |
|
233 | + public function create_pages() { |
|
234 | 234 | |
235 | - foreach ( self::get_pages() as $key => $page ) { |
|
236 | - wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
237 | - } |
|
235 | + foreach ( self::get_pages() as $key => $page ) { |
|
236 | + wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] ); |
|
237 | + } |
|
238 | 238 | |
239 | - } |
|
239 | + } |
|
240 | 240 | |
241 | - /** |
|
242 | - * Create subscriptions table. |
|
243 | - * |
|
244 | - */ |
|
245 | - public function create_subscriptions_table() { |
|
241 | + /** |
|
242 | + * Create subscriptions table. |
|
243 | + * |
|
244 | + */ |
|
245 | + public function create_subscriptions_table() { |
|
246 | 246 | |
247 | - global $wpdb; |
|
247 | + global $wpdb; |
|
248 | 248 | |
249 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
249 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
250 | 250 | |
251 | - // Create tables. |
|
252 | - $charset_collate = $wpdb->get_charset_collate(); |
|
253 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
251 | + // Create tables. |
|
252 | + $charset_collate = $wpdb->get_charset_collate(); |
|
253 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions ( |
|
254 | 254 | id bigint(20) unsigned NOT NULL auto_increment, |
255 | 255 | customer_id bigint(20) NOT NULL, |
256 | 256 | frequency int(11) NOT NULL DEFAULT '1', |
@@ -273,22 +273,22 @@ discard block |
||
273 | 273 | KEY customer_and_status (customer_id, status) |
274 | 274 | ) $charset_collate;"; |
275 | 275 | |
276 | - dbDelta( $sql ); |
|
276 | + dbDelta( $sql ); |
|
277 | 277 | |
278 | - } |
|
278 | + } |
|
279 | 279 | |
280 | - /** |
|
281 | - * Create invoices table. |
|
282 | - * |
|
283 | - */ |
|
284 | - public function create_invoices_table() { |
|
285 | - global $wpdb; |
|
280 | + /** |
|
281 | + * Create invoices table. |
|
282 | + * |
|
283 | + */ |
|
284 | + public function create_invoices_table() { |
|
285 | + global $wpdb; |
|
286 | 286 | |
287 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
287 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
288 | 288 | |
289 | - // Create tables. |
|
290 | - $charset_collate = $wpdb->get_charset_collate(); |
|
291 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
289 | + // Create tables. |
|
290 | + $charset_collate = $wpdb->get_charset_collate(); |
|
291 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices ( |
|
292 | 292 | post_id BIGINT(20) NOT NULL, |
293 | 293 | `number` VARCHAR(100), |
294 | 294 | `key` VARCHAR(100), |
@@ -324,22 +324,22 @@ discard block |
||
324 | 324 | KEY `key` (`key`) |
325 | 325 | ) $charset_collate;"; |
326 | 326 | |
327 | - dbDelta( $sql ); |
|
327 | + dbDelta( $sql ); |
|
328 | 328 | |
329 | - } |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * Create invoice items table. |
|
333 | - * |
|
334 | - */ |
|
335 | - public function create_invoice_items_table() { |
|
336 | - global $wpdb; |
|
331 | + /** |
|
332 | + * Create invoice items table. |
|
333 | + * |
|
334 | + */ |
|
335 | + public function create_invoice_items_table() { |
|
336 | + global $wpdb; |
|
337 | 337 | |
338 | - require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
338 | + require_once ABSPATH . 'wp-admin/includes/upgrade.php'; |
|
339 | 339 | |
340 | - // Create tables. |
|
341 | - $charset_collate = $wpdb->get_charset_collate(); |
|
342 | - $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
340 | + // Create tables. |
|
341 | + $charset_collate = $wpdb->get_charset_collate(); |
|
342 | + $sql = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items ( |
|
343 | 343 | ID BIGINT(20) NOT NULL AUTO_INCREMENT, |
344 | 344 | post_id BIGINT(20) NOT NULL, |
345 | 345 | item_id BIGINT(20) NOT NULL, |
@@ -361,159 +361,159 @@ discard block |
||
361 | 361 | KEY post_id (post_id) |
362 | 362 | ) $charset_collate;"; |
363 | 363 | |
364 | - dbDelta( $sql ); |
|
365 | - |
|
366 | - } |
|
367 | - |
|
368 | - /** |
|
369 | - * Migrates old invoices to new invoices. |
|
370 | - * |
|
371 | - */ |
|
372 | - public function migrate_old_invoices() { |
|
373 | - global $wpdb; |
|
374 | - |
|
375 | - $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
376 | - $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
377 | - $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
378 | - $invoices = array_unique( |
|
379 | - get_posts( |
|
380 | - array( |
|
381 | - 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
382 | - 'posts_per_page' => -1, |
|
383 | - 'fields' => 'ids', |
|
384 | - 'post_status' => array_keys( get_post_stati() ), |
|
385 | - 'exclude' => (array) $migrated, |
|
386 | - ) |
|
387 | - ) |
|
388 | - ); |
|
389 | - |
|
390 | - // Abort if we do not have any invoices. |
|
391 | - if ( empty( $invoices ) ) { |
|
392 | - return; |
|
393 | - } |
|
394 | - |
|
395 | - require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
396 | - |
|
397 | - $invoice_rows = array(); |
|
398 | - foreach ( $invoices as $invoice ) { |
|
399 | - |
|
400 | - $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
401 | - |
|
402 | - if ( empty( $invoice->ID ) ) { |
|
403 | - return; |
|
404 | - } |
|
405 | - |
|
406 | - $fields = array( |
|
407 | - 'post_id' => $invoice->ID, |
|
408 | - 'number' => $invoice->get_number(), |
|
409 | - 'key' => $invoice->get_key(), |
|
410 | - 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
411 | - 'mode' => $invoice->mode, |
|
412 | - 'user_ip' => $invoice->get_ip(), |
|
413 | - 'first_name' => $invoice->get_first_name(), |
|
414 | - 'last_name' => $invoice->get_last_name(), |
|
415 | - 'address' => $invoice->get_address(), |
|
416 | - 'city' => $invoice->city, |
|
417 | - 'state' => $invoice->state, |
|
418 | - 'country' => $invoice->country, |
|
419 | - 'zip' => $invoice->zip, |
|
420 | - 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
421 | - 'gateway' => $invoice->get_gateway(), |
|
422 | - 'transaction_id' => $invoice->get_transaction_id(), |
|
423 | - 'currency' => $invoice->get_currency(), |
|
424 | - 'subtotal' => $invoice->get_subtotal(), |
|
425 | - 'tax' => $invoice->get_tax(), |
|
426 | - 'fees_total' => $invoice->get_fees_total(), |
|
427 | - 'total' => $invoice->get_total(), |
|
428 | - 'discount' => $invoice->get_discount(), |
|
429 | - 'discount_code' => $invoice->get_discount_code(), |
|
430 | - 'disable_taxes' => $invoice->disable_taxes, |
|
431 | - 'due_date' => $invoice->get_due_date(), |
|
432 | - 'completed_date' => $invoice->get_completed_date(), |
|
433 | - 'company' => $invoice->company, |
|
434 | - 'vat_number' => $invoice->vat_number, |
|
435 | - 'vat_rate' => $invoice->vat_rate, |
|
436 | - 'custom_meta' => $invoice->payment_meta, |
|
437 | - ); |
|
438 | - |
|
439 | - foreach ( $fields as $key => $val ) { |
|
440 | - if ( is_null( $val ) ) { |
|
441 | - $val = ''; |
|
442 | - } |
|
443 | - $val = maybe_serialize( $val ); |
|
444 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
445 | - } |
|
446 | - |
|
447 | - $fields = implode( ', ', $fields ); |
|
448 | - $invoice_rows[] = "($fields)"; |
|
449 | - |
|
450 | - $item_rows = array(); |
|
451 | - $item_columns = array(); |
|
452 | - foreach ( $invoice->get_cart_details() as $details ) { |
|
453 | - $fields = array( |
|
454 | - 'post_id' => $invoice->ID, |
|
455 | - 'item_id' => $details['id'], |
|
456 | - 'item_name' => $details['name'], |
|
457 | - 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
458 | - 'vat_rate' => $details['vat_rate'], |
|
459 | - 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
460 | - 'tax' => $details['tax'], |
|
461 | - 'item_price' => $details['item_price'], |
|
462 | - 'custom_price' => $details['custom_price'], |
|
463 | - 'quantity' => $details['quantity'], |
|
464 | - 'discount' => $details['discount'], |
|
465 | - 'subtotal' => $details['subtotal'], |
|
466 | - 'price' => $details['price'], |
|
467 | - 'meta' => $details['meta'], |
|
468 | - 'fees' => $details['fees'], |
|
469 | - ); |
|
470 | - |
|
471 | - $item_columns = array_keys( $fields ); |
|
472 | - |
|
473 | - foreach ( $fields as $key => $val ) { |
|
474 | - if ( is_null( $val ) ) { |
|
475 | - $val = ''; |
|
476 | - } |
|
477 | - $val = maybe_serialize( $val ); |
|
478 | - $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
479 | - } |
|
480 | - |
|
481 | - $fields = implode( ', ', $fields ); |
|
482 | - $item_rows[] = "($fields)"; |
|
483 | - } |
|
484 | - |
|
485 | - $item_rows = implode( ', ', $item_rows ); |
|
486 | - $item_columns = implode( ', ', $item_columns ); |
|
487 | - $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
488 | - } |
|
489 | - |
|
490 | - if ( empty( $invoice_rows ) ) { |
|
491 | - return; |
|
492 | - } |
|
493 | - |
|
494 | - $invoice_rows = implode( ', ', $invoice_rows ); |
|
495 | - $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
496 | - |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Migrates old invoices to new invoices. |
|
501 | - * |
|
502 | - */ |
|
503 | - public static function rename_gateways_label() { |
|
504 | - global $wpdb; |
|
505 | - |
|
506 | - foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
507 | - |
|
508 | - $wpdb->update( |
|
509 | - $wpdb->prefix . 'getpaid_invoices', |
|
510 | - array( 'gateway' => $gateway ), |
|
511 | - array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
512 | - '%s', |
|
513 | - '%s' |
|
514 | - ); |
|
515 | - |
|
516 | - } |
|
517 | - } |
|
364 | + dbDelta( $sql ); |
|
365 | + |
|
366 | + } |
|
367 | + |
|
368 | + /** |
|
369 | + * Migrates old invoices to new invoices. |
|
370 | + * |
|
371 | + */ |
|
372 | + public function migrate_old_invoices() { |
|
373 | + global $wpdb; |
|
374 | + |
|
375 | + $invoices_table = $wpdb->prefix . 'getpaid_invoices'; |
|
376 | + $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items'; |
|
377 | + $migrated = $wpdb->get_col( "SELECT post_id FROM $invoices_table" ); |
|
378 | + $invoices = array_unique( |
|
379 | + get_posts( |
|
380 | + array( |
|
381 | + 'post_type' => array( 'wpi_invoice', 'wpi_quote' ), |
|
382 | + 'posts_per_page' => -1, |
|
383 | + 'fields' => 'ids', |
|
384 | + 'post_status' => array_keys( get_post_stati() ), |
|
385 | + 'exclude' => (array) $migrated, |
|
386 | + ) |
|
387 | + ) |
|
388 | + ); |
|
389 | + |
|
390 | + // Abort if we do not have any invoices. |
|
391 | + if ( empty( $invoices ) ) { |
|
392 | + return; |
|
393 | + } |
|
394 | + |
|
395 | + require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php'; |
|
396 | + |
|
397 | + $invoice_rows = array(); |
|
398 | + foreach ( $invoices as $invoice ) { |
|
399 | + |
|
400 | + $invoice = new WPInv_Legacy_Invoice( $invoice ); |
|
401 | + |
|
402 | + if ( empty( $invoice->ID ) ) { |
|
403 | + return; |
|
404 | + } |
|
405 | + |
|
406 | + $fields = array( |
|
407 | + 'post_id' => $invoice->ID, |
|
408 | + 'number' => $invoice->get_number(), |
|
409 | + 'key' => $invoice->get_key(), |
|
410 | + 'type' => str_replace( 'wpi_', '', $invoice->post_type ), |
|
411 | + 'mode' => $invoice->mode, |
|
412 | + 'user_ip' => $invoice->get_ip(), |
|
413 | + 'first_name' => $invoice->get_first_name(), |
|
414 | + 'last_name' => $invoice->get_last_name(), |
|
415 | + 'address' => $invoice->get_address(), |
|
416 | + 'city' => $invoice->city, |
|
417 | + 'state' => $invoice->state, |
|
418 | + 'country' => $invoice->country, |
|
419 | + 'zip' => $invoice->zip, |
|
420 | + 'adddress_confirmed' => (int) $invoice->adddress_confirmed, |
|
421 | + 'gateway' => $invoice->get_gateway(), |
|
422 | + 'transaction_id' => $invoice->get_transaction_id(), |
|
423 | + 'currency' => $invoice->get_currency(), |
|
424 | + 'subtotal' => $invoice->get_subtotal(), |
|
425 | + 'tax' => $invoice->get_tax(), |
|
426 | + 'fees_total' => $invoice->get_fees_total(), |
|
427 | + 'total' => $invoice->get_total(), |
|
428 | + 'discount' => $invoice->get_discount(), |
|
429 | + 'discount_code' => $invoice->get_discount_code(), |
|
430 | + 'disable_taxes' => $invoice->disable_taxes, |
|
431 | + 'due_date' => $invoice->get_due_date(), |
|
432 | + 'completed_date' => $invoice->get_completed_date(), |
|
433 | + 'company' => $invoice->company, |
|
434 | + 'vat_number' => $invoice->vat_number, |
|
435 | + 'vat_rate' => $invoice->vat_rate, |
|
436 | + 'custom_meta' => $invoice->payment_meta, |
|
437 | + ); |
|
438 | + |
|
439 | + foreach ( $fields as $key => $val ) { |
|
440 | + if ( is_null( $val ) ) { |
|
441 | + $val = ''; |
|
442 | + } |
|
443 | + $val = maybe_serialize( $val ); |
|
444 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
445 | + } |
|
446 | + |
|
447 | + $fields = implode( ', ', $fields ); |
|
448 | + $invoice_rows[] = "($fields)"; |
|
449 | + |
|
450 | + $item_rows = array(); |
|
451 | + $item_columns = array(); |
|
452 | + foreach ( $invoice->get_cart_details() as $details ) { |
|
453 | + $fields = array( |
|
454 | + 'post_id' => $invoice->ID, |
|
455 | + 'item_id' => $details['id'], |
|
456 | + 'item_name' => $details['name'], |
|
457 | + 'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'], |
|
458 | + 'vat_rate' => $details['vat_rate'], |
|
459 | + 'vat_class' => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'], |
|
460 | + 'tax' => $details['tax'], |
|
461 | + 'item_price' => $details['item_price'], |
|
462 | + 'custom_price' => $details['custom_price'], |
|
463 | + 'quantity' => $details['quantity'], |
|
464 | + 'discount' => $details['discount'], |
|
465 | + 'subtotal' => $details['subtotal'], |
|
466 | + 'price' => $details['price'], |
|
467 | + 'meta' => $details['meta'], |
|
468 | + 'fees' => $details['fees'], |
|
469 | + ); |
|
470 | + |
|
471 | + $item_columns = array_keys( $fields ); |
|
472 | + |
|
473 | + foreach ( $fields as $key => $val ) { |
|
474 | + if ( is_null( $val ) ) { |
|
475 | + $val = ''; |
|
476 | + } |
|
477 | + $val = maybe_serialize( $val ); |
|
478 | + $fields[ $key ] = $wpdb->prepare( '%s', $val ); |
|
479 | + } |
|
480 | + |
|
481 | + $fields = implode( ', ', $fields ); |
|
482 | + $item_rows[] = "($fields)"; |
|
483 | + } |
|
484 | + |
|
485 | + $item_rows = implode( ', ', $item_rows ); |
|
486 | + $item_columns = implode( ', ', $item_columns ); |
|
487 | + $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" ); |
|
488 | + } |
|
489 | + |
|
490 | + if ( empty( $invoice_rows ) ) { |
|
491 | + return; |
|
492 | + } |
|
493 | + |
|
494 | + $invoice_rows = implode( ', ', $invoice_rows ); |
|
495 | + $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" ); |
|
496 | + |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Migrates old invoices to new invoices. |
|
501 | + * |
|
502 | + */ |
|
503 | + public static function rename_gateways_label() { |
|
504 | + global $wpdb; |
|
505 | + |
|
506 | + foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) { |
|
507 | + |
|
508 | + $wpdb->update( |
|
509 | + $wpdb->prefix . 'getpaid_invoices', |
|
510 | + array( 'gateway' => $gateway ), |
|
511 | + array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ), |
|
512 | + '%s', |
|
513 | + '%s' |
|
514 | + ); |
|
515 | + |
|
516 | + } |
|
517 | + } |
|
518 | 518 | |
519 | 519 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,1233 +11,1233 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Input { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function input( $args = array() ) { |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'text', |
|
24 | - 'name' => '', |
|
25 | - 'class' => '', |
|
26 | - 'wrap_class' => '', |
|
27 | - 'id' => '', |
|
28 | - 'placeholder' => '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'required' => false, |
|
32 | - 'size' => '', // sm, lg, small, large |
|
33 | - 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | - 'label' => '', |
|
35 | - 'label_after' => false, |
|
36 | - 'label_class' => '', |
|
37 | - 'label_col' => '2', |
|
38 | - 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | - 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | - 'help_text' => '', |
|
42 | - 'validation_text' => '', |
|
43 | - 'validation_pattern' => '', |
|
44 | - 'no_wrap' => false, |
|
45 | - 'input_group_right' => '', |
|
46 | - 'input_group_left' => '', |
|
47 | - 'input_group_right_inside' => false, |
|
48 | - // forces the input group inside the input |
|
49 | - 'input_group_left_inside' => false, |
|
50 | - // forces the input group inside the input |
|
51 | - 'step' => '', |
|
52 | - 'switch' => false, |
|
53 | - // to show checkbox as a switch |
|
54 | - 'checked' => false, |
|
55 | - // set a checkbox or radio as selected |
|
56 | - 'password_toggle' => true, |
|
57 | - // toggle view/hide password |
|
58 | - 'element_require' => '', |
|
59 | - // [%element_id%] == "1" |
|
60 | - 'extra_attributes' => array(), |
|
61 | - // an array of extra attributes |
|
62 | - 'wrap_attributes' => array() |
|
63 | - ); |
|
64 | - |
|
65 | - /** |
|
66 | - * Parse incoming $args into an array and merge it with $defaults |
|
67 | - */ |
|
68 | - $args = wp_parse_args( $args, $defaults ); |
|
69 | - $output = ''; |
|
70 | - if ( ! empty( $args['type'] ) ) { |
|
71 | - // hidden label option needs to be empty |
|
72 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | - |
|
74 | - $type = sanitize_html_class( $args['type'] ); |
|
75 | - |
|
76 | - $help_text = ''; |
|
77 | - $label = ''; |
|
78 | - $label_after = $args['label_after']; |
|
79 | - $label_args = array( |
|
80 | - 'title' => $args['label'], |
|
81 | - 'for' => $args['id'], |
|
82 | - 'class' => $args['label_class'] . " ", |
|
83 | - 'label_type' => $args['label_type'], |
|
84 | - 'label_col' => $args['label_col'] |
|
85 | - ); |
|
86 | - |
|
87 | - // floating labels need label after |
|
88 | - if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | - $label_after = true; |
|
90 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | - } |
|
92 | - |
|
93 | - // size |
|
94 | - $size = ''; |
|
95 | - if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | - $size = 'lg'; |
|
97 | - $args['class'] .= ' form-control-lg'; |
|
98 | - }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | - $size = 'sm'; |
|
100 | - $args['class'] .= ' form-control-sm'; |
|
101 | - } |
|
102 | - |
|
103 | - // clear function |
|
104 | - $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | - |
|
106 | - // Some special sauce for files |
|
107 | - if ( $type == 'file' ) { |
|
108 | - $label_after = true; // if type file we need the label after |
|
109 | - $args['class'] .= ' custom-file-input '; |
|
110 | - } elseif ( $type == 'checkbox' ) { |
|
111 | - $label_after = true; // if type file we need the label after |
|
112 | - $args['class'] .= ' custom-control-input '; |
|
113 | - } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | - $type = 'text'; |
|
115 | - $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | - $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
117 | - |
|
118 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
119 | - |
|
120 | - // set a way to clear field if empty |
|
121 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
122 | - $args['input_group_right_inside'] = true; |
|
123 | - $args['clear_icon'] = true; |
|
124 | - } |
|
125 | - |
|
126 | - // enqueue the script |
|
127 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
128 | - $aui_settings->enqueue_flatpickr(); |
|
129 | - } elseif ( $type == 'iconpicker' ) { |
|
130 | - $type = 'text'; |
|
131 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input( $args = array() ) { |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'text', |
|
24 | + 'name' => '', |
|
25 | + 'class' => '', |
|
26 | + 'wrap_class' => '', |
|
27 | + 'id' => '', |
|
28 | + 'placeholder' => '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'required' => false, |
|
32 | + 'size' => '', // sm, lg, small, large |
|
33 | + 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right |
|
34 | + 'label' => '', |
|
35 | + 'label_after' => false, |
|
36 | + 'label_class' => '', |
|
37 | + 'label_col' => '2', |
|
38 | + 'label_type' => '', // top, horizontal, empty = hidden |
|
39 | + 'label_force_left' => false, // used to force checkbox label left when using horizontal |
|
40 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
41 | + 'help_text' => '', |
|
42 | + 'validation_text' => '', |
|
43 | + 'validation_pattern' => '', |
|
44 | + 'no_wrap' => false, |
|
45 | + 'input_group_right' => '', |
|
46 | + 'input_group_left' => '', |
|
47 | + 'input_group_right_inside' => false, |
|
48 | + // forces the input group inside the input |
|
49 | + 'input_group_left_inside' => false, |
|
50 | + // forces the input group inside the input |
|
51 | + 'step' => '', |
|
52 | + 'switch' => false, |
|
53 | + // to show checkbox as a switch |
|
54 | + 'checked' => false, |
|
55 | + // set a checkbox or radio as selected |
|
56 | + 'password_toggle' => true, |
|
57 | + // toggle view/hide password |
|
58 | + 'element_require' => '', |
|
59 | + // [%element_id%] == "1" |
|
60 | + 'extra_attributes' => array(), |
|
61 | + // an array of extra attributes |
|
62 | + 'wrap_attributes' => array() |
|
63 | + ); |
|
64 | + |
|
65 | + /** |
|
66 | + * Parse incoming $args into an array and merge it with $defaults |
|
67 | + */ |
|
68 | + $args = wp_parse_args( $args, $defaults ); |
|
69 | + $output = ''; |
|
70 | + if ( ! empty( $args['type'] ) ) { |
|
71 | + // hidden label option needs to be empty |
|
72 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
73 | + |
|
74 | + $type = sanitize_html_class( $args['type'] ); |
|
75 | + |
|
76 | + $help_text = ''; |
|
77 | + $label = ''; |
|
78 | + $label_after = $args['label_after']; |
|
79 | + $label_args = array( |
|
80 | + 'title' => $args['label'], |
|
81 | + 'for' => $args['id'], |
|
82 | + 'class' => $args['label_class'] . " ", |
|
83 | + 'label_type' => $args['label_type'], |
|
84 | + 'label_col' => $args['label_col'] |
|
85 | + ); |
|
86 | + |
|
87 | + // floating labels need label after |
|
88 | + if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { |
|
89 | + $label_after = true; |
|
90 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
91 | + } |
|
92 | + |
|
93 | + // size |
|
94 | + $size = ''; |
|
95 | + if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { |
|
96 | + $size = 'lg'; |
|
97 | + $args['class'] .= ' form-control-lg'; |
|
98 | + }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { |
|
99 | + $size = 'sm'; |
|
100 | + $args['class'] .= ' form-control-sm'; |
|
101 | + } |
|
102 | + |
|
103 | + // clear function |
|
104 | + $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; |
|
105 | + |
|
106 | + // Some special sauce for files |
|
107 | + if ( $type == 'file' ) { |
|
108 | + $label_after = true; // if type file we need the label after |
|
109 | + $args['class'] .= ' custom-file-input '; |
|
110 | + } elseif ( $type == 'checkbox' ) { |
|
111 | + $label_after = true; // if type file we need the label after |
|
112 | + $args['class'] .= ' custom-control-input '; |
|
113 | + } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { |
|
114 | + $type = 'text'; |
|
115 | + $args['class'] .= ' bg-initial '; // @todo not sure why we have this? |
|
116 | + $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; |
|
117 | + |
|
118 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
119 | + |
|
120 | + // set a way to clear field if empty |
|
121 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { |
|
122 | + $args['input_group_right_inside'] = true; |
|
123 | + $args['clear_icon'] = true; |
|
124 | + } |
|
125 | + |
|
126 | + // enqueue the script |
|
127 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
128 | + $aui_settings->enqueue_flatpickr(); |
|
129 | + } elseif ( $type == 'iconpicker' ) { |
|
130 | + $type = 'text'; |
|
131 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
132 | 132 | // $args['class'] .= ' bg-initial '; |
133 | 133 | |
134 | - $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
135 | - $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
134 | + $args['extra_attributes']['data-aui-init'] = 'iconpicker'; |
|
135 | + $args['extra_attributes']['data-placement'] = 'bottomRight'; |
|
136 | 136 | |
137 | - $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
137 | + $args['input_group_right'] = '<span class="input-group-addon input-group-text c-pointer"></span>'; |
|
138 | 138 | // $args['input_group_right_inside'] = true; |
139 | - // enqueue the script |
|
140 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
141 | - $aui_settings->enqueue_iconpicker(); |
|
142 | - } |
|
143 | - |
|
144 | - if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | - $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
146 | - } |
|
147 | - |
|
148 | - // allow clear icon |
|
149 | - if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | - $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
151 | - $args['input_group_right_inside'] = true; |
|
152 | - $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | - } |
|
154 | - |
|
155 | - // open/type |
|
156 | - $output .= '<input type="' . $type . '" '; |
|
157 | - |
|
158 | - // name |
|
159 | - if ( ! empty( $args['name'] ) ) { |
|
160 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
161 | - } |
|
162 | - |
|
163 | - // id |
|
164 | - if ( ! empty( $args['id'] ) ) { |
|
165 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
166 | - } |
|
167 | - |
|
168 | - // placeholder |
|
169 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
171 | - } |
|
172 | - |
|
173 | - // title |
|
174 | - if ( ! empty( $args['title'] ) ) { |
|
175 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
176 | - } |
|
177 | - |
|
178 | - // value |
|
179 | - if ( ! empty( $args['value'] ) ) { |
|
180 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
181 | - } |
|
182 | - |
|
183 | - // checked, for radio and checkboxes |
|
184 | - if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
185 | - $output .= ' checked '; |
|
186 | - } |
|
187 | - |
|
188 | - // validation text |
|
189 | - if ( ! empty( $args['validation_text'] ) ) { |
|
190 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
191 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
192 | - } |
|
193 | - |
|
194 | - // validation_pattern |
|
195 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
197 | - } |
|
198 | - |
|
199 | - // step (for numbers) |
|
200 | - if ( ! empty( $args['step'] ) ) { |
|
201 | - $output .= ' step="' . $args['step'] . '" '; |
|
202 | - } |
|
203 | - |
|
204 | - // required |
|
205 | - if ( ! empty( $args['required'] ) ) { |
|
206 | - $output .= ' required '; |
|
207 | - } |
|
208 | - |
|
209 | - // class |
|
210 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
211 | - $output .= ' class="form-control ' . $class . '" '; |
|
212 | - |
|
213 | - // data-attributes |
|
214 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
215 | - |
|
216 | - // extra attributes |
|
217 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
219 | - } |
|
220 | - |
|
221 | - // close |
|
222 | - $output .= ' >'; |
|
223 | - |
|
224 | - // help text |
|
225 | - if ( ! empty( $args['help_text'] ) ) { |
|
226 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
227 | - } |
|
228 | - |
|
229 | - // label |
|
230 | - if ( ! empty( $args['label'] ) ) { |
|
231 | - $label_base_class = ''; |
|
232 | - if ( $type == 'file' ) { |
|
233 | - $label_base_class = ' custom-file-label'; |
|
234 | - } elseif ( $type == 'checkbox' ) { |
|
235 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | - $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
237 | - $help_text = ''; |
|
238 | - //$label_args['class'] .= ' d-inline '; |
|
239 | - $args['wrap_class'] .= ' align-items-center '; |
|
240 | - }else{ |
|
241 | - |
|
242 | - } |
|
243 | - |
|
244 | - $label_base_class = ' custom-control-label'; |
|
245 | - } |
|
246 | - $label_args['class'] .= $label_base_class; |
|
247 | - $temp_label_args = $label_args; |
|
248 | - if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | - $label = self::label( $temp_label_args, $type ); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - // set help text in the correct position |
|
256 | - if ( $label_after ) { |
|
257 | - $output .= $label . $help_text; |
|
258 | - } |
|
259 | - |
|
260 | - // some input types need a separate wrap |
|
261 | - if ( $type == 'file' ) { |
|
262 | - $output = self::wrap( array( |
|
263 | - 'content' => $output, |
|
264 | - 'class' => 'form-group custom-file' |
|
265 | - ) ); |
|
266 | - } elseif ( $type == 'checkbox' ) { |
|
267 | - |
|
268 | - $label_args['title'] = $args['label']; |
|
269 | - $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | - $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | - $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | - $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | - if ( ! empty( $args['label_force_left'] ) ) { |
|
274 | - $wrap_class .= ' d-flex align-content-center'; |
|
275 | - $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
276 | - } |
|
277 | - $output = self::wrap( array( |
|
278 | - 'content' => $output, |
|
279 | - 'class' => 'custom-control ' . $wrap_class |
|
280 | - ) ); |
|
281 | - |
|
282 | - if ( $args['label_type'] == 'horizontal' ) { |
|
283 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
284 | - $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
285 | - } |
|
286 | - } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
287 | - |
|
288 | - |
|
289 | - // allow password field to toggle view |
|
290 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
139 | + // enqueue the script |
|
140 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
141 | + $aui_settings->enqueue_iconpicker(); |
|
142 | + } |
|
143 | + |
|
144 | + if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { |
|
145 | + $output .= '<input type="hidden" name="' . esc_attr( $args['name'] ) . '" value="0" />'; |
|
146 | + } |
|
147 | + |
|
148 | + // allow clear icon |
|
149 | + if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { |
|
150 | + $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); |
|
151 | + $args['input_group_right_inside'] = true; |
|
152 | + $args['input_group_right'] = '<span class="input-group-text aui-clear-input c-pointer bg-initial border-0 px-2 d-none" onclick="' . $clear_function . '"><span style="font-size: '.$font_size.'rem" aria-hidden="true" class="close">×</span></span>'; |
|
153 | + } |
|
154 | + |
|
155 | + // open/type |
|
156 | + $output .= '<input type="' . $type . '" '; |
|
157 | + |
|
158 | + // name |
|
159 | + if ( ! empty( $args['name'] ) ) { |
|
160 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
161 | + } |
|
162 | + |
|
163 | + // id |
|
164 | + if ( ! empty( $args['id'] ) ) { |
|
165 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
166 | + } |
|
167 | + |
|
168 | + // placeholder |
|
169 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
170 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
171 | + } |
|
172 | + |
|
173 | + // title |
|
174 | + if ( ! empty( $args['title'] ) ) { |
|
175 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
176 | + } |
|
177 | + |
|
178 | + // value |
|
179 | + if ( ! empty( $args['value'] ) ) { |
|
180 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
181 | + } |
|
182 | + |
|
183 | + // checked, for radio and checkboxes |
|
184 | + if ( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ) { |
|
185 | + $output .= ' checked '; |
|
186 | + } |
|
187 | + |
|
188 | + // validation text |
|
189 | + if ( ! empty( $args['validation_text'] ) ) { |
|
190 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
191 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
192 | + } |
|
193 | + |
|
194 | + // validation_pattern |
|
195 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
196 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
197 | + } |
|
198 | + |
|
199 | + // step (for numbers) |
|
200 | + if ( ! empty( $args['step'] ) ) { |
|
201 | + $output .= ' step="' . $args['step'] . '" '; |
|
202 | + } |
|
203 | + |
|
204 | + // required |
|
205 | + if ( ! empty( $args['required'] ) ) { |
|
206 | + $output .= ' required '; |
|
207 | + } |
|
208 | + |
|
209 | + // class |
|
210 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
211 | + $output .= ' class="form-control ' . $class . '" '; |
|
212 | + |
|
213 | + // data-attributes |
|
214 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
215 | + |
|
216 | + // extra attributes |
|
217 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
218 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
219 | + } |
|
220 | + |
|
221 | + // close |
|
222 | + $output .= ' >'; |
|
223 | + |
|
224 | + // help text |
|
225 | + if ( ! empty( $args['help_text'] ) ) { |
|
226 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
227 | + } |
|
228 | + |
|
229 | + // label |
|
230 | + if ( ! empty( $args['label'] ) ) { |
|
231 | + $label_base_class = ''; |
|
232 | + if ( $type == 'file' ) { |
|
233 | + $label_base_class = ' custom-file-label'; |
|
234 | + } elseif ( $type == 'checkbox' ) { |
|
235 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
236 | + $label_args['title'] = wp_kses_post( $args['help_text'] ); |
|
237 | + $help_text = ''; |
|
238 | + //$label_args['class'] .= ' d-inline '; |
|
239 | + $args['wrap_class'] .= ' align-items-center '; |
|
240 | + }else{ |
|
241 | + |
|
242 | + } |
|
243 | + |
|
244 | + $label_base_class = ' custom-control-label'; |
|
245 | + } |
|
246 | + $label_args['class'] .= $label_base_class; |
|
247 | + $temp_label_args = $label_args; |
|
248 | + if(! empty( $args['label_force_left'] )){$temp_label_args['class'] = $label_base_class." text-muted";} |
|
249 | + $label = self::label( $temp_label_args, $type ); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + // set help text in the correct position |
|
256 | + if ( $label_after ) { |
|
257 | + $output .= $label . $help_text; |
|
258 | + } |
|
259 | + |
|
260 | + // some input types need a separate wrap |
|
261 | + if ( $type == 'file' ) { |
|
262 | + $output = self::wrap( array( |
|
263 | + 'content' => $output, |
|
264 | + 'class' => 'form-group custom-file' |
|
265 | + ) ); |
|
266 | + } elseif ( $type == 'checkbox' ) { |
|
267 | + |
|
268 | + $label_args['title'] = $args['label']; |
|
269 | + $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); |
|
270 | + $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '<div class="' . $label_col . ' col-form-label"></div>'; |
|
271 | + $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; |
|
272 | + $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; |
|
273 | + if ( ! empty( $args['label_force_left'] ) ) { |
|
274 | + $wrap_class .= ' d-flex align-content-center'; |
|
275 | + $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); |
|
276 | + } |
|
277 | + $output = self::wrap( array( |
|
278 | + 'content' => $output, |
|
279 | + 'class' => 'custom-control ' . $wrap_class |
|
280 | + ) ); |
|
281 | + |
|
282 | + if ( $args['label_type'] == 'horizontal' ) { |
|
283 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
284 | + $output = $label . '<div class="' . $input_col . '">' . $output . '</div>'; |
|
285 | + } |
|
286 | + } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { |
|
287 | + |
|
288 | + |
|
289 | + // allow password field to toggle view |
|
290 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
291 | 291 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
292 | 292 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
293 | 293 | if($el.hasClass(\'fa-eye\')) |
294 | 294 | {$eli.attr(\'type\',\'text\');} |
295 | 295 | else{$eli.attr(\'type\',\'password\');}" |
296 | 296 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
297 | - } |
|
298 | - |
|
299 | - // input group wraps |
|
300 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
302 | - $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
303 | - $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
304 | - |
|
305 | - if ( $args['input_group_left'] ) { |
|
306 | - $output = self::wrap( array( |
|
307 | - 'content' => $output, |
|
308 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
309 | - 'input_group_left' => $args['input_group_left'], |
|
310 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
311 | - ) ); |
|
312 | - } |
|
313 | - if ( $args['input_group_right'] ) { |
|
314 | - $output = self::wrap( array( |
|
315 | - 'content' => $output, |
|
316 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
317 | - 'input_group_right' => $args['input_group_right'], |
|
318 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
319 | - ) ); |
|
320 | - } |
|
321 | - |
|
322 | - } |
|
323 | - |
|
324 | - if ( ! $label_after ) { |
|
325 | - $output .= $help_text; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | - $output = self::wrap( array( |
|
331 | - 'content' => $output, |
|
332 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | - ) ); |
|
334 | - } |
|
335 | - |
|
336 | - if ( ! $label_after ) { |
|
337 | - $output = $label . $output; |
|
338 | - } |
|
339 | - |
|
340 | - // wrap |
|
341 | - if ( ! $args['no_wrap'] ) { |
|
342 | - $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
343 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
344 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | - $output = self::wrap( array( |
|
346 | - 'content' => $output, |
|
347 | - 'class' => $wrap_class, |
|
348 | - 'element_require' => $args['element_require'], |
|
349 | - 'argument_id' => $args['id'], |
|
350 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
351 | - ) ); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - return $output; |
|
356 | - } |
|
357 | - |
|
358 | - public static function label( $args = array(), $type = '' ) { |
|
359 | - //<label for="exampleInputEmail1">Email address</label> |
|
360 | - $defaults = array( |
|
361 | - 'title' => 'div', |
|
362 | - 'for' => '', |
|
363 | - 'class' => '', |
|
364 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
365 | - 'label_col' => '', |
|
366 | - ); |
|
367 | - |
|
368 | - /** |
|
369 | - * Parse incoming $args into an array and merge it with $defaults |
|
370 | - */ |
|
371 | - $args = wp_parse_args( $args, $defaults ); |
|
372 | - $output = ''; |
|
373 | - |
|
374 | - if ( $args['title'] ) { |
|
375 | - |
|
376 | - // maybe hide labels //@todo set a global option for visibility class |
|
377 | - if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
378 | - $class = $args['class']; |
|
379 | - } else { |
|
380 | - $class = 'sr-only ' . $args['class']; |
|
381 | - } |
|
382 | - |
|
383 | - // maybe horizontal |
|
384 | - if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | - $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
386 | - } |
|
387 | - |
|
388 | - // open |
|
389 | - $output .= '<label '; |
|
390 | - |
|
391 | - // for |
|
392 | - if ( ! empty( $args['for'] ) ) { |
|
393 | - $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
394 | - } |
|
395 | - |
|
396 | - // class |
|
397 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
398 | - $output .= ' class="' . $class . '" '; |
|
399 | - |
|
400 | - // close |
|
401 | - $output .= '>'; |
|
402 | - |
|
403 | - |
|
404 | - // title, don't escape fully as can contain html |
|
405 | - if ( ! empty( $args['title'] ) ) { |
|
406 | - $output .= wp_kses_post( $args['title'] ); |
|
407 | - } |
|
408 | - |
|
409 | - // close wrap |
|
410 | - $output .= '</label>'; |
|
411 | - |
|
412 | - |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - return $output; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Wrap some content in a HTML wrapper. |
|
421 | - * |
|
422 | - * @param array $args |
|
423 | - * |
|
424 | - * @return string |
|
425 | - */ |
|
426 | - public static function wrap( $args = array() ) { |
|
427 | - $defaults = array( |
|
428 | - 'type' => 'div', |
|
429 | - 'class' => 'form-group', |
|
430 | - 'content' => '', |
|
431 | - 'input_group_left' => '', |
|
432 | - 'input_group_right' => '', |
|
433 | - 'input_group_left_inside' => false, |
|
434 | - 'input_group_right_inside' => false, |
|
435 | - 'element_require' => '', |
|
436 | - 'argument_id' => '', |
|
437 | - 'wrap_attributes' => array() |
|
438 | - ); |
|
439 | - |
|
440 | - /** |
|
441 | - * Parse incoming $args into an array and merge it with $defaults |
|
442 | - */ |
|
443 | - $args = wp_parse_args( $args, $defaults ); |
|
444 | - $output = ''; |
|
445 | - if ( $args['type'] ) { |
|
446 | - |
|
447 | - // open |
|
448 | - $output .= '<' . sanitize_html_class( $args['type'] ); |
|
449 | - |
|
450 | - // element require |
|
451 | - if ( ! empty( $args['element_require'] ) ) { |
|
452 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
453 | - $args['class'] .= " aui-conditional-field"; |
|
454 | - } |
|
455 | - |
|
456 | - // argument_id |
|
457 | - if ( ! empty( $args['argument_id'] ) ) { |
|
458 | - $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
459 | - } |
|
460 | - |
|
461 | - // class |
|
462 | - $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
463 | - $output .= ' class="' . $class . '" '; |
|
464 | - |
|
465 | - // Attributes |
|
466 | - if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | - $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
468 | - } |
|
469 | - |
|
470 | - // close wrap |
|
471 | - $output .= ' >'; |
|
472 | - |
|
473 | - |
|
474 | - // Input group left |
|
475 | - if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | - $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | - $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | - $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
479 | - } |
|
480 | - |
|
481 | - // content |
|
482 | - $output .= $args['content']; |
|
483 | - |
|
484 | - // Input group right |
|
485 | - if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | - $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | - $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | - $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - // close wrap |
|
493 | - $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
494 | - |
|
495 | - |
|
496 | - } else { |
|
497 | - $output = $args['content']; |
|
498 | - } |
|
499 | - |
|
500 | - return $output; |
|
501 | - } |
|
502 | - |
|
503 | - /** |
|
504 | - * Build the component. |
|
505 | - * |
|
506 | - * @param array $args |
|
507 | - * |
|
508 | - * @return string The rendered component. |
|
509 | - */ |
|
510 | - public static function textarea( $args = array() ) { |
|
511 | - $defaults = array( |
|
512 | - 'name' => '', |
|
513 | - 'class' => '', |
|
514 | - 'wrap_class' => '', |
|
515 | - 'id' => '', |
|
516 | - 'placeholder' => '', |
|
517 | - 'title' => '', |
|
518 | - 'value' => '', |
|
519 | - 'required' => false, |
|
520 | - 'label' => '', |
|
521 | - 'label_after' => false, |
|
522 | - 'label_class' => '', |
|
523 | - 'label_type' => '', |
|
524 | - 'label_col' => '', |
|
525 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
526 | - 'input_group_right' => '', |
|
527 | - 'input_group_left' => '', |
|
528 | - 'input_group_right_inside' => false, |
|
529 | - 'help_text' => '', |
|
530 | - 'validation_text' => '', |
|
531 | - 'validation_pattern' => '', |
|
532 | - 'no_wrap' => false, |
|
533 | - 'rows' => '', |
|
534 | - 'wysiwyg' => false, |
|
535 | - 'allow_tags' => false, |
|
536 | - // Allow HTML tags |
|
537 | - 'element_require' => '', |
|
538 | - // [%element_id%] == "1" |
|
539 | - 'extra_attributes' => array(), |
|
540 | - // an array of extra attributes |
|
541 | - 'wrap_attributes' => array(), |
|
542 | - ); |
|
543 | - |
|
544 | - /** |
|
545 | - * Parse incoming $args into an array and merge it with $defaults |
|
546 | - */ |
|
547 | - $args = wp_parse_args( $args, $defaults ); |
|
548 | - $output = ''; |
|
549 | - |
|
550 | - // hidden label option needs to be empty |
|
551 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
552 | - |
|
553 | - // floating labels don't work with wysiwyg so set it as top |
|
554 | - if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
555 | - $args['label_type'] = 'top'; |
|
556 | - } |
|
557 | - |
|
558 | - $label_after = $args['label_after']; |
|
559 | - |
|
560 | - // floating labels need label after |
|
561 | - if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
562 | - $label_after = true; |
|
563 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
564 | - } |
|
565 | - |
|
566 | - // label |
|
567 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
569 | - $label_args = array( |
|
570 | - 'title' => $args['label'], |
|
571 | - 'for' => $args['id'], |
|
572 | - 'class' => $args['label_class'] . " ", |
|
573 | - 'label_type' => $args['label_type'], |
|
574 | - 'label_col' => $args['label_col'] |
|
575 | - ); |
|
576 | - $output .= self::label( $label_args ); |
|
577 | - } |
|
578 | - |
|
579 | - // maybe horizontal label |
|
580 | - if ( $args['label_type'] == 'horizontal' ) { |
|
581 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
582 | - $output .= '<div class="' . $input_col . '">'; |
|
583 | - } |
|
584 | - |
|
585 | - if ( ! empty( $args['wysiwyg'] ) ) { |
|
586 | - ob_start(); |
|
587 | - $content = $args['value']; |
|
588 | - $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
589 | - $settings = array( |
|
590 | - 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
591 | - 'quicktags' => false, |
|
592 | - 'media_buttons' => false, |
|
593 | - 'editor_class' => 'form-control', |
|
594 | - 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
595 | - 'teeny' => true, |
|
596 | - ); |
|
597 | - |
|
598 | - // maybe set settings if array |
|
599 | - if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
601 | - } |
|
602 | - |
|
603 | - wp_editor( $content, $editor_id, $settings ); |
|
604 | - $output .= ob_get_clean(); |
|
605 | - } else { |
|
606 | - |
|
607 | - // open |
|
608 | - $output .= '<textarea '; |
|
609 | - |
|
610 | - // name |
|
611 | - if ( ! empty( $args['name'] ) ) { |
|
612 | - $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
613 | - } |
|
614 | - |
|
615 | - // id |
|
616 | - if ( ! empty( $args['id'] ) ) { |
|
617 | - $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
618 | - } |
|
619 | - |
|
620 | - // placeholder |
|
621 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | - $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
623 | - } |
|
624 | - |
|
625 | - // title |
|
626 | - if ( ! empty( $args['title'] ) ) { |
|
627 | - $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
628 | - } |
|
629 | - |
|
630 | - // validation text |
|
631 | - if ( ! empty( $args['validation_text'] ) ) { |
|
632 | - $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
633 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
634 | - } |
|
635 | - |
|
636 | - // validation_pattern |
|
637 | - if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | - $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
639 | - } |
|
640 | - |
|
641 | - // required |
|
642 | - if ( ! empty( $args['required'] ) ) { |
|
643 | - $output .= ' required '; |
|
644 | - } |
|
645 | - |
|
646 | - // rows |
|
647 | - if ( ! empty( $args['rows'] ) ) { |
|
648 | - $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - // class |
|
653 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
654 | - $output .= ' class="form-control ' . $class . '" '; |
|
655 | - |
|
656 | - // extra attributes |
|
657 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
659 | - } |
|
660 | - |
|
661 | - // close tag |
|
662 | - $output .= ' >'; |
|
663 | - |
|
664 | - // value |
|
665 | - if ( ! empty( $args['value'] ) ) { |
|
666 | - if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | - $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
668 | - } else { |
|
669 | - $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
670 | - } |
|
671 | - } |
|
672 | - |
|
673 | - // closing tag |
|
674 | - $output .= '</textarea>'; |
|
675 | - |
|
676 | - |
|
677 | - // input group wraps |
|
678 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | - if ( $args['input_group_left'] ) { |
|
681 | - $output = self::wrap( array( |
|
682 | - 'content' => $output, |
|
683 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
684 | - 'input_group_left' => $args['input_group_left'], |
|
685 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
686 | - ) ); |
|
687 | - } |
|
688 | - if ( $args['input_group_right'] ) { |
|
689 | - $output = self::wrap( array( |
|
690 | - 'content' => $output, |
|
691 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
692 | - 'input_group_right' => $args['input_group_right'], |
|
693 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
694 | - ) ); |
|
695 | - } |
|
696 | - |
|
697 | - } |
|
698 | - |
|
699 | - |
|
700 | - } |
|
701 | - |
|
702 | - if ( ! empty( $args['label'] ) && $label_after ) { |
|
703 | - $label_args = array( |
|
704 | - 'title' => $args['label'], |
|
705 | - 'for' => $args['id'], |
|
706 | - 'class' => $args['label_class'] . " ", |
|
707 | - 'label_type' => $args['label_type'], |
|
708 | - 'label_col' => $args['label_col'] |
|
709 | - ); |
|
710 | - $output .= self::label( $label_args ); |
|
711 | - } |
|
712 | - |
|
713 | - // help text |
|
714 | - if ( ! empty( $args['help_text'] ) ) { |
|
715 | - $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
716 | - } |
|
717 | - |
|
718 | - // maybe horizontal label |
|
719 | - if ( $args['label_type'] == 'horizontal' ) { |
|
720 | - $output .= '</div>'; |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - // wrap |
|
725 | - if ( ! $args['no_wrap'] ) { |
|
726 | - $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
727 | - $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
728 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | - $output = self::wrap( array( |
|
730 | - 'content' => $output, |
|
731 | - 'class' => $wrap_class, |
|
732 | - 'element_require' => $args['element_require'], |
|
733 | - 'argument_id' => $args['id'], |
|
734 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
735 | - ) ); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - return $output; |
|
740 | - } |
|
741 | - |
|
742 | - /** |
|
743 | - * Build the component. |
|
744 | - * |
|
745 | - * @param array $args |
|
746 | - * |
|
747 | - * @return string The rendered component. |
|
748 | - */ |
|
749 | - public static function select( $args = array() ) { |
|
750 | - $defaults = array( |
|
751 | - 'class' => '', |
|
752 | - 'wrap_class' => '', |
|
753 | - 'id' => '', |
|
754 | - 'title' => '', |
|
755 | - 'value' => '', |
|
756 | - // can be an array or a string |
|
757 | - 'required' => false, |
|
758 | - 'label' => '', |
|
759 | - 'label_after' => false, |
|
760 | - 'label_type' => '', |
|
761 | - 'label_col' => '', |
|
762 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
763 | - 'label_class' => '', |
|
764 | - 'help_text' => '', |
|
765 | - 'placeholder' => '', |
|
766 | - 'options' => array(), |
|
767 | - // array or string |
|
768 | - 'icon' => '', |
|
769 | - 'multiple' => false, |
|
770 | - 'select2' => false, |
|
771 | - 'no_wrap' => false, |
|
772 | - 'input_group_right' => '', |
|
773 | - 'input_group_left' => '', |
|
774 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
775 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
776 | - 'element_require' => '', |
|
777 | - // [%element_id%] == "1" |
|
778 | - 'extra_attributes' => array(), |
|
779 | - // an array of extra attributes |
|
780 | - 'wrap_attributes' => array(), |
|
781 | - ); |
|
782 | - |
|
783 | - /** |
|
784 | - * Parse incoming $args into an array and merge it with $defaults |
|
785 | - */ |
|
786 | - $args = wp_parse_args( $args, $defaults ); |
|
787 | - $output = ''; |
|
788 | - |
|
789 | - // for now lets hide floating labels |
|
790 | - if ( $args['label_type'] == 'floating' ) { |
|
791 | - $args['label_type'] = 'hidden'; |
|
792 | - } |
|
793 | - |
|
794 | - // hidden label option needs to be empty |
|
795 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
796 | - |
|
797 | - |
|
798 | - $label_after = $args['label_after']; |
|
799 | - |
|
800 | - // floating labels need label after |
|
801 | - if ( $args['label_type'] == 'floating' ) { |
|
802 | - $label_after = true; |
|
803 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
804 | - } |
|
805 | - |
|
806 | - // Maybe setup select2 |
|
807 | - $is_select2 = false; |
|
808 | - if ( ! empty( $args['select2'] ) ) { |
|
809 | - $args['class'] .= ' aui-select2'; |
|
810 | - $is_select2 = true; |
|
811 | - } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
812 | - $is_select2 = true; |
|
813 | - } |
|
814 | - |
|
815 | - // select2 tags |
|
816 | - if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
817 | - $args['data-tags'] = 'true'; |
|
818 | - $args['data-token-separators'] = "[',']"; |
|
819 | - $args['multiple'] = true; |
|
820 | - } |
|
821 | - |
|
822 | - // select2 placeholder |
|
823 | - if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | - $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | - $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
826 | - } |
|
827 | - |
|
828 | - // Set hidden input to save empty value for multiselect. |
|
829 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | - $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
831 | - } |
|
832 | - |
|
833 | - // open/type |
|
834 | - $output .= '<select '; |
|
835 | - |
|
836 | - // style |
|
837 | - if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | - $output .= " style='width:100%;' "; |
|
839 | - } |
|
840 | - |
|
841 | - // element require |
|
842 | - if ( ! empty( $args['element_require'] ) ) { |
|
843 | - $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
844 | - $args['class'] .= " aui-conditional-field"; |
|
845 | - } |
|
846 | - |
|
847 | - // class |
|
848 | - $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | - $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
850 | - |
|
851 | - // name |
|
852 | - if ( ! empty( $args['name'] ) ) { |
|
853 | - $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
854 | - } |
|
855 | - |
|
856 | - // id |
|
857 | - if ( ! empty( $args['id'] ) ) { |
|
858 | - $output .= AUI_Component_Helper::id( $args['id'] ); |
|
859 | - } |
|
860 | - |
|
861 | - // title |
|
862 | - if ( ! empty( $args['title'] ) ) { |
|
863 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
864 | - } |
|
865 | - |
|
866 | - // data-attributes |
|
867 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
868 | - |
|
869 | - // aria-attributes |
|
870 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
871 | - |
|
872 | - // extra attributes |
|
873 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
875 | - } |
|
876 | - |
|
877 | - // required |
|
878 | - if ( ! empty( $args['required'] ) ) { |
|
879 | - $output .= ' required '; |
|
880 | - } |
|
881 | - |
|
882 | - // multiple |
|
883 | - if ( ! empty( $args['multiple'] ) ) { |
|
884 | - $output .= ' multiple '; |
|
885 | - } |
|
886 | - |
|
887 | - // close opening tag |
|
888 | - $output .= ' >'; |
|
889 | - |
|
890 | - // placeholder |
|
891 | - if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | - $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | - } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
894 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
895 | - } |
|
896 | - |
|
897 | - // Options |
|
898 | - if ( ! empty( $args['options'] ) ) { |
|
899 | - |
|
900 | - if ( ! is_array( $args['options'] ) ) { |
|
901 | - $output .= $args['options']; // not the preferred way but an option |
|
902 | - } else { |
|
903 | - foreach ( $args['options'] as $val => $name ) { |
|
904 | - $selected = ''; |
|
905 | - if ( is_array( $name ) ) { |
|
906 | - if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
908 | - |
|
909 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
910 | - } else { |
|
911 | - $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | - $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | - $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | - if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | - $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | - } elseif ( ! empty( $args['value'] ) ) { |
|
917 | - $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | - } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | - $selected = selected( $option_value, $args['value'], false ); |
|
920 | - } |
|
921 | - |
|
922 | - $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
923 | - } |
|
924 | - } else { |
|
925 | - if ( ! empty( $args['value'] ) ) { |
|
926 | - if ( is_array( $args['value'] ) ) { |
|
927 | - $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | - } elseif ( ! empty( $args['value'] ) ) { |
|
929 | - $selected = selected( $args['value'], $val, false ); |
|
930 | - } |
|
931 | - } elseif ( $args['value'] === $val ) { |
|
932 | - $selected = selected( $args['value'], $val, false ); |
|
933 | - } |
|
934 | - $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
935 | - } |
|
936 | - } |
|
937 | - } |
|
938 | - |
|
939 | - } |
|
940 | - |
|
941 | - // closing tag |
|
942 | - $output .= '</select>'; |
|
943 | - |
|
944 | - $label = ''; |
|
945 | - $help_text = ''; |
|
946 | - // label |
|
947 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | - } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
949 | - $label_args = array( |
|
950 | - 'title' => $args['label'], |
|
951 | - 'for' => $args['id'], |
|
952 | - 'class' => $args['label_class'] . " ", |
|
953 | - 'label_type' => $args['label_type'], |
|
954 | - 'label_col' => $args['label_col'] |
|
955 | - ); |
|
956 | - $label = self::label( $label_args ); |
|
957 | - } |
|
958 | - |
|
959 | - // help text |
|
960 | - if ( ! empty( $args['help_text'] ) ) { |
|
961 | - $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
962 | - } |
|
963 | - |
|
964 | - // input group wraps |
|
965 | - if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | - $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | - if ( $args['input_group_left'] ) { |
|
968 | - $output = self::wrap( array( |
|
969 | - 'content' => $output, |
|
970 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
971 | - 'input_group_left' => $args['input_group_left'], |
|
972 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
973 | - ) ); |
|
974 | - } |
|
975 | - if ( $args['input_group_right'] ) { |
|
976 | - $output = self::wrap( array( |
|
977 | - 'content' => $output, |
|
978 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
979 | - 'input_group_right' => $args['input_group_right'], |
|
980 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
981 | - ) ); |
|
982 | - } |
|
983 | - |
|
984 | - } |
|
985 | - |
|
986 | - if ( ! $label_after ) { |
|
987 | - $output .= $help_text; |
|
988 | - } |
|
989 | - |
|
990 | - |
|
991 | - if ( $args['label_type'] == 'horizontal' ) { |
|
992 | - $output = self::wrap( array( |
|
993 | - 'content' => $output, |
|
994 | - 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | - ) ); |
|
996 | - } |
|
997 | - |
|
998 | - if ( ! $label_after ) { |
|
999 | - $output = $label . $output; |
|
1000 | - } |
|
1001 | - |
|
1002 | - // maybe horizontal label |
|
297 | + } |
|
298 | + |
|
299 | + // input group wraps |
|
300 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
301 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
302 | + $group_size = $size == 'lg' ? ' input-group-lg' : ''; |
|
303 | + $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; |
|
304 | + |
|
305 | + if ( $args['input_group_left'] ) { |
|
306 | + $output = self::wrap( array( |
|
307 | + 'content' => $output, |
|
308 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
309 | + 'input_group_left' => $args['input_group_left'], |
|
310 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
311 | + ) ); |
|
312 | + } |
|
313 | + if ( $args['input_group_right'] ) { |
|
314 | + $output = self::wrap( array( |
|
315 | + 'content' => $output, |
|
316 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, |
|
317 | + 'input_group_right' => $args['input_group_right'], |
|
318 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
319 | + ) ); |
|
320 | + } |
|
321 | + |
|
322 | + } |
|
323 | + |
|
324 | + if ( ! $label_after ) { |
|
325 | + $output .= $help_text; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
330 | + $output = self::wrap( array( |
|
331 | + 'content' => $output, |
|
332 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
333 | + ) ); |
|
334 | + } |
|
335 | + |
|
336 | + if ( ! $label_after ) { |
|
337 | + $output = $label . $output; |
|
338 | + } |
|
339 | + |
|
340 | + // wrap |
|
341 | + if ( ! $args['no_wrap'] ) { |
|
342 | + $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
343 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
344 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
345 | + $output = self::wrap( array( |
|
346 | + 'content' => $output, |
|
347 | + 'class' => $wrap_class, |
|
348 | + 'element_require' => $args['element_require'], |
|
349 | + 'argument_id' => $args['id'], |
|
350 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
351 | + ) ); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + return $output; |
|
356 | + } |
|
357 | + |
|
358 | + public static function label( $args = array(), $type = '' ) { |
|
359 | + //<label for="exampleInputEmail1">Email address</label> |
|
360 | + $defaults = array( |
|
361 | + 'title' => 'div', |
|
362 | + 'for' => '', |
|
363 | + 'class' => '', |
|
364 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
365 | + 'label_col' => '', |
|
366 | + ); |
|
367 | + |
|
368 | + /** |
|
369 | + * Parse incoming $args into an array and merge it with $defaults |
|
370 | + */ |
|
371 | + $args = wp_parse_args( $args, $defaults ); |
|
372 | + $output = ''; |
|
373 | + |
|
374 | + if ( $args['title'] ) { |
|
375 | + |
|
376 | + // maybe hide labels //@todo set a global option for visibility class |
|
377 | + if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { |
|
378 | + $class = $args['class']; |
|
379 | + } else { |
|
380 | + $class = 'sr-only ' . $args['class']; |
|
381 | + } |
|
382 | + |
|
383 | + // maybe horizontal |
|
384 | + if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { |
|
385 | + $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; |
|
386 | + } |
|
387 | + |
|
388 | + // open |
|
389 | + $output .= '<label '; |
|
390 | + |
|
391 | + // for |
|
392 | + if ( ! empty( $args['for'] ) ) { |
|
393 | + $output .= ' for="' . esc_attr( $args['for'] ) . '" '; |
|
394 | + } |
|
395 | + |
|
396 | + // class |
|
397 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
398 | + $output .= ' class="' . $class . '" '; |
|
399 | + |
|
400 | + // close |
|
401 | + $output .= '>'; |
|
402 | + |
|
403 | + |
|
404 | + // title, don't escape fully as can contain html |
|
405 | + if ( ! empty( $args['title'] ) ) { |
|
406 | + $output .= wp_kses_post( $args['title'] ); |
|
407 | + } |
|
408 | + |
|
409 | + // close wrap |
|
410 | + $output .= '</label>'; |
|
411 | + |
|
412 | + |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + return $output; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Wrap some content in a HTML wrapper. |
|
421 | + * |
|
422 | + * @param array $args |
|
423 | + * |
|
424 | + * @return string |
|
425 | + */ |
|
426 | + public static function wrap( $args = array() ) { |
|
427 | + $defaults = array( |
|
428 | + 'type' => 'div', |
|
429 | + 'class' => 'form-group', |
|
430 | + 'content' => '', |
|
431 | + 'input_group_left' => '', |
|
432 | + 'input_group_right' => '', |
|
433 | + 'input_group_left_inside' => false, |
|
434 | + 'input_group_right_inside' => false, |
|
435 | + 'element_require' => '', |
|
436 | + 'argument_id' => '', |
|
437 | + 'wrap_attributes' => array() |
|
438 | + ); |
|
439 | + |
|
440 | + /** |
|
441 | + * Parse incoming $args into an array and merge it with $defaults |
|
442 | + */ |
|
443 | + $args = wp_parse_args( $args, $defaults ); |
|
444 | + $output = ''; |
|
445 | + if ( $args['type'] ) { |
|
446 | + |
|
447 | + // open |
|
448 | + $output .= '<' . sanitize_html_class( $args['type'] ); |
|
449 | + |
|
450 | + // element require |
|
451 | + if ( ! empty( $args['element_require'] ) ) { |
|
452 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
453 | + $args['class'] .= " aui-conditional-field"; |
|
454 | + } |
|
455 | + |
|
456 | + // argument_id |
|
457 | + if ( ! empty( $args['argument_id'] ) ) { |
|
458 | + $output .= ' data-argument="' . esc_attr( $args['argument_id'] ) . '"'; |
|
459 | + } |
|
460 | + |
|
461 | + // class |
|
462 | + $class = ! empty( $args['class'] ) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
463 | + $output .= ' class="' . $class . '" '; |
|
464 | + |
|
465 | + // Attributes |
|
466 | + if ( ! empty( $args['wrap_attributes'] ) ) { |
|
467 | + $output .= AUI_Component_Helper::extra_attributes( $args['wrap_attributes'] ); |
|
468 | + } |
|
469 | + |
|
470 | + // close wrap |
|
471 | + $output .= ' >'; |
|
472 | + |
|
473 | + |
|
474 | + // Input group left |
|
475 | + if ( ! empty( $args['input_group_left'] ) ) { |
|
476 | + $position_class = ! empty( $args['input_group_left_inside'] ) ? 'position-absolute h-100' : ''; |
|
477 | + $input_group_left = strpos( $args['input_group_left'], '<' ) !== false ? $args['input_group_left'] : '<span class="input-group-text">' . $args['input_group_left'] . '</span>'; |
|
478 | + $output .= '<div class="input-group-prepend ' . $position_class . '">' . $input_group_left . '</div>'; |
|
479 | + } |
|
480 | + |
|
481 | + // content |
|
482 | + $output .= $args['content']; |
|
483 | + |
|
484 | + // Input group right |
|
485 | + if ( ! empty( $args['input_group_right'] ) ) { |
|
486 | + $position_class = ! empty( $args['input_group_right_inside'] ) ? 'position-absolute h-100' : ''; |
|
487 | + $input_group_right = strpos( $args['input_group_right'], '<' ) !== false ? $args['input_group_right'] : '<span class="input-group-text">' . $args['input_group_right'] . '</span>'; |
|
488 | + $output .= '<div class="input-group-append ' . $position_class . '" style="top:0;right:0;">' . $input_group_right . '</div>'; |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + // close wrap |
|
493 | + $output .= '</' . sanitize_html_class( $args['type'] ) . '>'; |
|
494 | + |
|
495 | + |
|
496 | + } else { |
|
497 | + $output = $args['content']; |
|
498 | + } |
|
499 | + |
|
500 | + return $output; |
|
501 | + } |
|
502 | + |
|
503 | + /** |
|
504 | + * Build the component. |
|
505 | + * |
|
506 | + * @param array $args |
|
507 | + * |
|
508 | + * @return string The rendered component. |
|
509 | + */ |
|
510 | + public static function textarea( $args = array() ) { |
|
511 | + $defaults = array( |
|
512 | + 'name' => '', |
|
513 | + 'class' => '', |
|
514 | + 'wrap_class' => '', |
|
515 | + 'id' => '', |
|
516 | + 'placeholder' => '', |
|
517 | + 'title' => '', |
|
518 | + 'value' => '', |
|
519 | + 'required' => false, |
|
520 | + 'label' => '', |
|
521 | + 'label_after' => false, |
|
522 | + 'label_class' => '', |
|
523 | + 'label_type' => '', |
|
524 | + 'label_col' => '', |
|
525 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
526 | + 'input_group_right' => '', |
|
527 | + 'input_group_left' => '', |
|
528 | + 'input_group_right_inside' => false, |
|
529 | + 'help_text' => '', |
|
530 | + 'validation_text' => '', |
|
531 | + 'validation_pattern' => '', |
|
532 | + 'no_wrap' => false, |
|
533 | + 'rows' => '', |
|
534 | + 'wysiwyg' => false, |
|
535 | + 'allow_tags' => false, |
|
536 | + // Allow HTML tags |
|
537 | + 'element_require' => '', |
|
538 | + // [%element_id%] == "1" |
|
539 | + 'extra_attributes' => array(), |
|
540 | + // an array of extra attributes |
|
541 | + 'wrap_attributes' => array(), |
|
542 | + ); |
|
543 | + |
|
544 | + /** |
|
545 | + * Parse incoming $args into an array and merge it with $defaults |
|
546 | + */ |
|
547 | + $args = wp_parse_args( $args, $defaults ); |
|
548 | + $output = ''; |
|
549 | + |
|
550 | + // hidden label option needs to be empty |
|
551 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
552 | + |
|
553 | + // floating labels don't work with wysiwyg so set it as top |
|
554 | + if ( $args['label_type'] == 'floating' && ! empty( $args['wysiwyg'] ) ) { |
|
555 | + $args['label_type'] = 'top'; |
|
556 | + } |
|
557 | + |
|
558 | + $label_after = $args['label_after']; |
|
559 | + |
|
560 | + // floating labels need label after |
|
561 | + if ( $args['label_type'] == 'floating' && empty( $args['wysiwyg'] ) ) { |
|
562 | + $label_after = true; |
|
563 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
564 | + } |
|
565 | + |
|
566 | + // label |
|
567 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
568 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
569 | + $label_args = array( |
|
570 | + 'title' => $args['label'], |
|
571 | + 'for' => $args['id'], |
|
572 | + 'class' => $args['label_class'] . " ", |
|
573 | + 'label_type' => $args['label_type'], |
|
574 | + 'label_col' => $args['label_col'] |
|
575 | + ); |
|
576 | + $output .= self::label( $label_args ); |
|
577 | + } |
|
578 | + |
|
579 | + // maybe horizontal label |
|
580 | + if ( $args['label_type'] == 'horizontal' ) { |
|
581 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
582 | + $output .= '<div class="' . $input_col . '">'; |
|
583 | + } |
|
584 | + |
|
585 | + if ( ! empty( $args['wysiwyg'] ) ) { |
|
586 | + ob_start(); |
|
587 | + $content = $args['value']; |
|
588 | + $editor_id = ! empty( $args['id'] ) ? sanitize_html_class( $args['id'] ) : 'wp_editor'; |
|
589 | + $settings = array( |
|
590 | + 'textarea_rows' => ! empty( absint( $args['rows'] ) ) ? absint( $args['rows'] ) : 4, |
|
591 | + 'quicktags' => false, |
|
592 | + 'media_buttons' => false, |
|
593 | + 'editor_class' => 'form-control', |
|
594 | + 'textarea_name' => ! empty( $args['name'] ) ? sanitize_html_class( $args['name'] ) : sanitize_html_class( $args['id'] ), |
|
595 | + 'teeny' => true, |
|
596 | + ); |
|
597 | + |
|
598 | + // maybe set settings if array |
|
599 | + if ( is_array( $args['wysiwyg'] ) ) { |
|
600 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
601 | + } |
|
602 | + |
|
603 | + wp_editor( $content, $editor_id, $settings ); |
|
604 | + $output .= ob_get_clean(); |
|
605 | + } else { |
|
606 | + |
|
607 | + // open |
|
608 | + $output .= '<textarea '; |
|
609 | + |
|
610 | + // name |
|
611 | + if ( ! empty( $args['name'] ) ) { |
|
612 | + $output .= ' name="' . esc_attr( $args['name'] ) . '" '; |
|
613 | + } |
|
614 | + |
|
615 | + // id |
|
616 | + if ( ! empty( $args['id'] ) ) { |
|
617 | + $output .= ' id="' . sanitize_html_class( $args['id'] ) . '" '; |
|
618 | + } |
|
619 | + |
|
620 | + // placeholder |
|
621 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] ) { |
|
622 | + $output .= ' placeholder="' . esc_attr( $args['placeholder'] ) . '" '; |
|
623 | + } |
|
624 | + |
|
625 | + // title |
|
626 | + if ( ! empty( $args['title'] ) ) { |
|
627 | + $output .= ' title="' . esc_attr( $args['title'] ) . '" '; |
|
628 | + } |
|
629 | + |
|
630 | + // validation text |
|
631 | + if ( ! empty( $args['validation_text'] ) ) { |
|
632 | + $output .= ' oninvalid="setCustomValidity(\'' . esc_attr( $args['validation_text'] ) . '\')" '; |
|
633 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
634 | + } |
|
635 | + |
|
636 | + // validation_pattern |
|
637 | + if ( ! empty( $args['validation_pattern'] ) ) { |
|
638 | + $output .= ' pattern="' . esc_attr( $args['validation_pattern'] ) . '" '; |
|
639 | + } |
|
640 | + |
|
641 | + // required |
|
642 | + if ( ! empty( $args['required'] ) ) { |
|
643 | + $output .= ' required '; |
|
644 | + } |
|
645 | + |
|
646 | + // rows |
|
647 | + if ( ! empty( $args['rows'] ) ) { |
|
648 | + $output .= ' rows="' . absint( $args['rows'] ) . '" '; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + // class |
|
653 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
654 | + $output .= ' class="form-control ' . $class . '" '; |
|
655 | + |
|
656 | + // extra attributes |
|
657 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
658 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
659 | + } |
|
660 | + |
|
661 | + // close tag |
|
662 | + $output .= ' >'; |
|
663 | + |
|
664 | + // value |
|
665 | + if ( ! empty( $args['value'] ) ) { |
|
666 | + if ( ! empty( $args['allow_tags'] ) ) { |
|
667 | + $output .= AUI_Component_Helper::sanitize_html_field( $args['value'], $args ); // Sanitize HTML. |
|
668 | + } else { |
|
669 | + $output .= AUI_Component_Helper::sanitize_textarea_field( $args['value'] ); |
|
670 | + } |
|
671 | + } |
|
672 | + |
|
673 | + // closing tag |
|
674 | + $output .= '</textarea>'; |
|
675 | + |
|
676 | + |
|
677 | + // input group wraps |
|
678 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
679 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
680 | + if ( $args['input_group_left'] ) { |
|
681 | + $output = self::wrap( array( |
|
682 | + 'content' => $output, |
|
683 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
684 | + 'input_group_left' => $args['input_group_left'], |
|
685 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
686 | + ) ); |
|
687 | + } |
|
688 | + if ( $args['input_group_right'] ) { |
|
689 | + $output = self::wrap( array( |
|
690 | + 'content' => $output, |
|
691 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
692 | + 'input_group_right' => $args['input_group_right'], |
|
693 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
694 | + ) ); |
|
695 | + } |
|
696 | + |
|
697 | + } |
|
698 | + |
|
699 | + |
|
700 | + } |
|
701 | + |
|
702 | + if ( ! empty( $args['label'] ) && $label_after ) { |
|
703 | + $label_args = array( |
|
704 | + 'title' => $args['label'], |
|
705 | + 'for' => $args['id'], |
|
706 | + 'class' => $args['label_class'] . " ", |
|
707 | + 'label_type' => $args['label_type'], |
|
708 | + 'label_col' => $args['label_col'] |
|
709 | + ); |
|
710 | + $output .= self::label( $label_args ); |
|
711 | + } |
|
712 | + |
|
713 | + // help text |
|
714 | + if ( ! empty( $args['help_text'] ) ) { |
|
715 | + $output .= AUI_Component_Helper::help_text( $args['help_text'] ); |
|
716 | + } |
|
717 | + |
|
718 | + // maybe horizontal label |
|
719 | + if ( $args['label_type'] == 'horizontal' ) { |
|
720 | + $output .= '</div>'; |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + // wrap |
|
725 | + if ( ! $args['no_wrap'] ) { |
|
726 | + $form_group_class = $args['label_type'] == 'floating' ? 'form-label-group' : 'form-group'; |
|
727 | + $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
728 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
729 | + $output = self::wrap( array( |
|
730 | + 'content' => $output, |
|
731 | + 'class' => $wrap_class, |
|
732 | + 'element_require' => $args['element_require'], |
|
733 | + 'argument_id' => $args['id'], |
|
734 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
735 | + ) ); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + return $output; |
|
740 | + } |
|
741 | + |
|
742 | + /** |
|
743 | + * Build the component. |
|
744 | + * |
|
745 | + * @param array $args |
|
746 | + * |
|
747 | + * @return string The rendered component. |
|
748 | + */ |
|
749 | + public static function select( $args = array() ) { |
|
750 | + $defaults = array( |
|
751 | + 'class' => '', |
|
752 | + 'wrap_class' => '', |
|
753 | + 'id' => '', |
|
754 | + 'title' => '', |
|
755 | + 'value' => '', |
|
756 | + // can be an array or a string |
|
757 | + 'required' => false, |
|
758 | + 'label' => '', |
|
759 | + 'label_after' => false, |
|
760 | + 'label_type' => '', |
|
761 | + 'label_col' => '', |
|
762 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
763 | + 'label_class' => '', |
|
764 | + 'help_text' => '', |
|
765 | + 'placeholder' => '', |
|
766 | + 'options' => array(), |
|
767 | + // array or string |
|
768 | + 'icon' => '', |
|
769 | + 'multiple' => false, |
|
770 | + 'select2' => false, |
|
771 | + 'no_wrap' => false, |
|
772 | + 'input_group_right' => '', |
|
773 | + 'input_group_left' => '', |
|
774 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
775 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
776 | + 'element_require' => '', |
|
777 | + // [%element_id%] == "1" |
|
778 | + 'extra_attributes' => array(), |
|
779 | + // an array of extra attributes |
|
780 | + 'wrap_attributes' => array(), |
|
781 | + ); |
|
782 | + |
|
783 | + /** |
|
784 | + * Parse incoming $args into an array and merge it with $defaults |
|
785 | + */ |
|
786 | + $args = wp_parse_args( $args, $defaults ); |
|
787 | + $output = ''; |
|
788 | + |
|
789 | + // for now lets hide floating labels |
|
790 | + if ( $args['label_type'] == 'floating' ) { |
|
791 | + $args['label_type'] = 'hidden'; |
|
792 | + } |
|
793 | + |
|
794 | + // hidden label option needs to be empty |
|
795 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
796 | + |
|
797 | + |
|
798 | + $label_after = $args['label_after']; |
|
799 | + |
|
800 | + // floating labels need label after |
|
801 | + if ( $args['label_type'] == 'floating' ) { |
|
802 | + $label_after = true; |
|
803 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
804 | + } |
|
805 | + |
|
806 | + // Maybe setup select2 |
|
807 | + $is_select2 = false; |
|
808 | + if ( ! empty( $args['select2'] ) ) { |
|
809 | + $args['class'] .= ' aui-select2'; |
|
810 | + $is_select2 = true; |
|
811 | + } elseif ( strpos( $args['class'], 'aui-select2' ) !== false ) { |
|
812 | + $is_select2 = true; |
|
813 | + } |
|
814 | + |
|
815 | + // select2 tags |
|
816 | + if ( ! empty( $args['select2'] ) && $args['select2'] === 'tags' ) { // triple equals needed here for some reason |
|
817 | + $args['data-tags'] = 'true'; |
|
818 | + $args['data-token-separators'] = "[',']"; |
|
819 | + $args['multiple'] = true; |
|
820 | + } |
|
821 | + |
|
822 | + // select2 placeholder |
|
823 | + if ( $is_select2 && isset( $args['placeholder'] ) && '' != $args['placeholder'] && empty( $args['data-placeholder'] ) ) { |
|
824 | + $args['data-placeholder'] = esc_attr( $args['placeholder'] ); |
|
825 | + $args['data-allow-clear'] = isset( $args['data-allow-clear'] ) ? (bool) $args['data-allow-clear'] : true; |
|
826 | + } |
|
827 | + |
|
828 | + // Set hidden input to save empty value for multiselect. |
|
829 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['name'] ) ) { |
|
830 | + $output .= '<input type="hidden" ' . AUI_Component_Helper::name( $args['name'] ) . ' value="" data-ignore-rule/>'; |
|
831 | + } |
|
832 | + |
|
833 | + // open/type |
|
834 | + $output .= '<select '; |
|
835 | + |
|
836 | + // style |
|
837 | + if ( $is_select2 && !($args['input_group_left'] || $args['input_group_right'])) { |
|
838 | + $output .= " style='width:100%;' "; |
|
839 | + } |
|
840 | + |
|
841 | + // element require |
|
842 | + if ( ! empty( $args['element_require'] ) ) { |
|
843 | + $output .= AUI_Component_Helper::element_require( $args['element_require'] ); |
|
844 | + $args['class'] .= " aui-conditional-field"; |
|
845 | + } |
|
846 | + |
|
847 | + // class |
|
848 | + $class = ! empty( $args['class'] ) ? $args['class'] : ''; |
|
849 | + $output .= AUI_Component_Helper::class_attr( 'custom-select ' . $class ); |
|
850 | + |
|
851 | + // name |
|
852 | + if ( ! empty( $args['name'] ) ) { |
|
853 | + $output .= AUI_Component_Helper::name( $args['name'], $args['multiple'] ); |
|
854 | + } |
|
855 | + |
|
856 | + // id |
|
857 | + if ( ! empty( $args['id'] ) ) { |
|
858 | + $output .= AUI_Component_Helper::id( $args['id'] ); |
|
859 | + } |
|
860 | + |
|
861 | + // title |
|
862 | + if ( ! empty( $args['title'] ) ) { |
|
863 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
864 | + } |
|
865 | + |
|
866 | + // data-attributes |
|
867 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
868 | + |
|
869 | + // aria-attributes |
|
870 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
871 | + |
|
872 | + // extra attributes |
|
873 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
874 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
875 | + } |
|
876 | + |
|
877 | + // required |
|
878 | + if ( ! empty( $args['required'] ) ) { |
|
879 | + $output .= ' required '; |
|
880 | + } |
|
881 | + |
|
882 | + // multiple |
|
883 | + if ( ! empty( $args['multiple'] ) ) { |
|
884 | + $output .= ' multiple '; |
|
885 | + } |
|
886 | + |
|
887 | + // close opening tag |
|
888 | + $output .= ' >'; |
|
889 | + |
|
890 | + // placeholder |
|
891 | + if ( isset( $args['placeholder'] ) && '' != $args['placeholder'] && ! $is_select2 ) { |
|
892 | + $output .= '<option value="" disabled selected hidden>' . esc_attr( $args['placeholder'] ) . '</option>'; |
|
893 | + } elseif ( $is_select2 && ! empty( $args['placeholder'] ) ) { |
|
894 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
895 | + } |
|
896 | + |
|
897 | + // Options |
|
898 | + if ( ! empty( $args['options'] ) ) { |
|
899 | + |
|
900 | + if ( ! is_array( $args['options'] ) ) { |
|
901 | + $output .= $args['options']; // not the preferred way but an option |
|
902 | + } else { |
|
903 | + foreach ( $args['options'] as $val => $name ) { |
|
904 | + $selected = ''; |
|
905 | + if ( is_array( $name ) ) { |
|
906 | + if ( isset( $name['optgroup'] ) && ( $name['optgroup'] == 'start' || $name['optgroup'] == 'end' ) ) { |
|
907 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
908 | + |
|
909 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr( $option_label ) . '">' : '</optgroup>'; |
|
910 | + } else { |
|
911 | + $option_label = isset( $name['label'] ) ? $name['label'] : ''; |
|
912 | + $option_value = isset( $name['value'] ) ? $name['value'] : ''; |
|
913 | + $extra_attributes = !empty($name['extra_attributes']) ? AUI_Component_Helper::extra_attributes( $name['extra_attributes'] ) : ''; |
|
914 | + if ( ! empty( $args['multiple'] ) && ! empty( $args['value'] ) && is_array( $args['value'] ) ) { |
|
915 | + $selected = in_array( $option_value, stripslashes_deep( $args['value'] ) ) ? "selected" : ""; |
|
916 | + } elseif ( ! empty( $args['value'] ) ) { |
|
917 | + $selected = selected( $option_value, stripslashes_deep( $args['value'] ), false ); |
|
918 | + } elseif ( empty( $args['value'] ) && $args['value'] === $option_value ) { |
|
919 | + $selected = selected( $option_value, $args['value'], false ); |
|
920 | + } |
|
921 | + |
|
922 | + $output .= '<option value="' . esc_attr( $option_value ) . '" ' . $selected . ' '.$extra_attributes .'>' . $option_label . '</option>'; |
|
923 | + } |
|
924 | + } else { |
|
925 | + if ( ! empty( $args['value'] ) ) { |
|
926 | + if ( is_array( $args['value'] ) ) { |
|
927 | + $selected = in_array( $val, $args['value'] ) ? 'selected="selected"' : ''; |
|
928 | + } elseif ( ! empty( $args['value'] ) ) { |
|
929 | + $selected = selected( $args['value'], $val, false ); |
|
930 | + } |
|
931 | + } elseif ( $args['value'] === $val ) { |
|
932 | + $selected = selected( $args['value'], $val, false ); |
|
933 | + } |
|
934 | + $output .= '<option value="' . esc_attr( $val ) . '" ' . $selected . '>' . esc_attr( $name ) . '</option>'; |
|
935 | + } |
|
936 | + } |
|
937 | + } |
|
938 | + |
|
939 | + } |
|
940 | + |
|
941 | + // closing tag |
|
942 | + $output .= '</select>'; |
|
943 | + |
|
944 | + $label = ''; |
|
945 | + $help_text = ''; |
|
946 | + // label |
|
947 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
948 | + } elseif ( ! empty( $args['label'] ) && ! $label_after ) { |
|
949 | + $label_args = array( |
|
950 | + 'title' => $args['label'], |
|
951 | + 'for' => $args['id'], |
|
952 | + 'class' => $args['label_class'] . " ", |
|
953 | + 'label_type' => $args['label_type'], |
|
954 | + 'label_col' => $args['label_col'] |
|
955 | + ); |
|
956 | + $label = self::label( $label_args ); |
|
957 | + } |
|
958 | + |
|
959 | + // help text |
|
960 | + if ( ! empty( $args['help_text'] ) ) { |
|
961 | + $help_text = AUI_Component_Helper::help_text( $args['help_text'] ); |
|
962 | + } |
|
963 | + |
|
964 | + // input group wraps |
|
965 | + if ( $args['input_group_left'] || $args['input_group_right'] ) { |
|
966 | + $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; |
|
967 | + if ( $args['input_group_left'] ) { |
|
968 | + $output = self::wrap( array( |
|
969 | + 'content' => $output, |
|
970 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
971 | + 'input_group_left' => $args['input_group_left'], |
|
972 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
973 | + ) ); |
|
974 | + } |
|
975 | + if ( $args['input_group_right'] ) { |
|
976 | + $output = self::wrap( array( |
|
977 | + 'content' => $output, |
|
978 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 : 'input-group', |
|
979 | + 'input_group_right' => $args['input_group_right'], |
|
980 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
981 | + ) ); |
|
982 | + } |
|
983 | + |
|
984 | + } |
|
985 | + |
|
986 | + if ( ! $label_after ) { |
|
987 | + $output .= $help_text; |
|
988 | + } |
|
989 | + |
|
990 | + |
|
991 | + if ( $args['label_type'] == 'horizontal' ) { |
|
992 | + $output = self::wrap( array( |
|
993 | + 'content' => $output, |
|
994 | + 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) |
|
995 | + ) ); |
|
996 | + } |
|
997 | + |
|
998 | + if ( ! $label_after ) { |
|
999 | + $output = $label . $output; |
|
1000 | + } |
|
1001 | + |
|
1002 | + // maybe horizontal label |
|
1003 | 1003 | // if ( $args['label_type'] == 'horizontal' ) { |
1004 | 1004 | // $output .= '</div>'; |
1005 | 1005 | // } |
1006 | 1006 | |
1007 | 1007 | |
1008 | - // wrap |
|
1009 | - if ( ! $args['no_wrap'] ) { |
|
1010 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1011 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | - $output = self::wrap( array( |
|
1013 | - 'content' => $output, |
|
1014 | - 'class' => $wrap_class, |
|
1015 | - 'element_require' => $args['element_require'], |
|
1016 | - 'argument_id' => $args['id'], |
|
1017 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1018 | - ) ); |
|
1019 | - } |
|
1020 | - |
|
1021 | - |
|
1022 | - return $output; |
|
1023 | - } |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * Build the component. |
|
1027 | - * |
|
1028 | - * @param array $args |
|
1029 | - * |
|
1030 | - * @return string The rendered component. |
|
1031 | - */ |
|
1032 | - public static function radio( $args = array() ) { |
|
1033 | - $defaults = array( |
|
1034 | - 'class' => '', |
|
1035 | - 'wrap_class' => '', |
|
1036 | - 'id' => '', |
|
1037 | - 'title' => '', |
|
1038 | - 'horizontal' => false, |
|
1039 | - // sets the lable horizontal |
|
1040 | - 'value' => '', |
|
1041 | - 'label' => '', |
|
1042 | - 'label_class' => '', |
|
1043 | - 'label_type' => '', |
|
1044 | - 'label_col' => '', |
|
1045 | - // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1046 | - 'help_text' => '', |
|
1047 | - 'inline' => true, |
|
1048 | - 'required' => false, |
|
1049 | - 'options' => array(), |
|
1050 | - 'icon' => '', |
|
1051 | - 'no_wrap' => false, |
|
1052 | - 'element_require' => '', |
|
1053 | - // [%element_id%] == "1" |
|
1054 | - 'extra_attributes' => array(), |
|
1055 | - // an array of extra attributes |
|
1056 | - 'wrap_attributes' => array() |
|
1057 | - ); |
|
1058 | - |
|
1059 | - /** |
|
1060 | - * Parse incoming $args into an array and merge it with $defaults |
|
1061 | - */ |
|
1062 | - $args = wp_parse_args( $args, $defaults ); |
|
1063 | - |
|
1064 | - // for now lets use horizontal for floating |
|
1065 | - if ( $args['label_type'] == 'floating' ) { |
|
1066 | - $args['label_type'] = 'horizontal'; |
|
1067 | - } |
|
1068 | - |
|
1069 | - $label_args = array( |
|
1070 | - 'title' => $args['label'], |
|
1071 | - 'class' => $args['label_class'] . " pt-0 ", |
|
1072 | - 'label_type' => $args['label_type'], |
|
1073 | - 'label_col' => $args['label_col'] |
|
1074 | - ); |
|
1075 | - |
|
1076 | - $output = ''; |
|
1077 | - |
|
1078 | - |
|
1079 | - // label before |
|
1080 | - if ( ! empty( $args['label'] ) ) { |
|
1081 | - $output .= self::label( $label_args, 'radio' ); |
|
1082 | - } |
|
1083 | - |
|
1084 | - // maybe horizontal label |
|
1085 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | - $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1087 | - $output .= '<div class="' . $input_col . '">'; |
|
1088 | - } |
|
1089 | - |
|
1090 | - if ( ! empty( $args['options'] ) ) { |
|
1091 | - $count = 0; |
|
1092 | - foreach ( $args['options'] as $value => $label ) { |
|
1093 | - $option_args = $args; |
|
1094 | - $option_args['value'] = $value; |
|
1095 | - $option_args['label'] = $label; |
|
1096 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1097 | - $output .= self::radio_option( $option_args, $count ); |
|
1098 | - $count ++; |
|
1099 | - } |
|
1100 | - } |
|
1101 | - |
|
1102 | - // help text |
|
1103 | - $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1104 | - $output .= $help_text; |
|
1105 | - |
|
1106 | - // maybe horizontal label |
|
1107 | - if ( $args['label_type'] == 'horizontal' ) { |
|
1108 | - $output .= '</div>'; |
|
1109 | - } |
|
1110 | - |
|
1111 | - // wrap |
|
1112 | - $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1113 | - $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | - $output = self::wrap( array( |
|
1115 | - 'content' => $output, |
|
1116 | - 'class' => $wrap_class, |
|
1117 | - 'element_require' => $args['element_require'], |
|
1118 | - 'argument_id' => $args['id'], |
|
1119 | - 'wrap_attributes' => $args['wrap_attributes'], |
|
1120 | - ) ); |
|
1121 | - |
|
1122 | - |
|
1123 | - return $output; |
|
1124 | - } |
|
1125 | - |
|
1126 | - /** |
|
1127 | - * Build the component. |
|
1128 | - * |
|
1129 | - * @param array $args |
|
1130 | - * |
|
1131 | - * @return string The rendered component. |
|
1132 | - */ |
|
1133 | - public static function radio_option( $args = array(), $count = '' ) { |
|
1134 | - $defaults = array( |
|
1135 | - 'class' => '', |
|
1136 | - 'id' => '', |
|
1137 | - 'title' => '', |
|
1138 | - 'value' => '', |
|
1139 | - 'required' => false, |
|
1140 | - 'inline' => true, |
|
1141 | - 'label' => '', |
|
1142 | - 'options' => array(), |
|
1143 | - 'icon' => '', |
|
1144 | - 'no_wrap' => false, |
|
1145 | - 'extra_attributes' => array() // an array of extra attributes |
|
1146 | - ); |
|
1147 | - |
|
1148 | - /** |
|
1149 | - * Parse incoming $args into an array and merge it with $defaults |
|
1150 | - */ |
|
1151 | - $args = wp_parse_args( $args, $defaults ); |
|
1152 | - |
|
1153 | - $output = ''; |
|
1154 | - |
|
1155 | - // open/type |
|
1156 | - $output .= '<input type="radio"'; |
|
1157 | - |
|
1158 | - // class |
|
1159 | - $output .= ' class="form-check-input" '; |
|
1160 | - |
|
1161 | - // name |
|
1162 | - if ( ! empty( $args['name'] ) ) { |
|
1163 | - $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1164 | - } |
|
1165 | - |
|
1166 | - // id |
|
1167 | - if ( ! empty( $args['id'] ) ) { |
|
1168 | - $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1169 | - } |
|
1170 | - |
|
1171 | - // title |
|
1172 | - if ( ! empty( $args['title'] ) ) { |
|
1173 | - $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1174 | - } |
|
1175 | - |
|
1176 | - // value |
|
1177 | - if ( isset( $args['value'] ) ) { |
|
1178 | - $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1179 | - } |
|
1180 | - |
|
1181 | - // checked, for radio and checkboxes |
|
1182 | - if ( $args['checked'] ) { |
|
1183 | - $output .= ' checked '; |
|
1184 | - } |
|
1185 | - |
|
1186 | - // data-attributes |
|
1187 | - $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1188 | - |
|
1189 | - // aria-attributes |
|
1190 | - $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1191 | - |
|
1192 | - // extra attributes |
|
1193 | - if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | - $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1195 | - } |
|
1196 | - |
|
1197 | - // required |
|
1198 | - if ( ! empty( $args['required'] ) ) { |
|
1199 | - $output .= ' required '; |
|
1200 | - } |
|
1201 | - |
|
1202 | - // close opening tag |
|
1203 | - $output .= ' >'; |
|
1204 | - |
|
1205 | - // label |
|
1206 | - if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | - } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | - $output .= self::label( array( |
|
1209 | - 'title' => $args['label'], |
|
1210 | - 'for' => $args['id'] . $count, |
|
1211 | - 'class' => 'form-check-label' |
|
1212 | - ), 'radio' ); |
|
1213 | - } |
|
1214 | - |
|
1215 | - // wrap |
|
1216 | - if ( ! $args['no_wrap'] ) { |
|
1217 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1218 | - |
|
1219 | - // Unique wrap class |
|
1220 | - $uniq_class = 'fwrap'; |
|
1221 | - if ( ! empty( $args['name'] ) ) { |
|
1222 | - $uniq_class .= '-' . $args['name']; |
|
1223 | - } else if ( ! empty( $args['id'] ) ) { |
|
1224 | - $uniq_class .= '-' . $args['id']; |
|
1225 | - } |
|
1226 | - |
|
1227 | - if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1228 | - $uniq_class .= '-' . $args['value']; |
|
1229 | - } else { |
|
1230 | - $uniq_class .= '-' . $count; |
|
1231 | - } |
|
1232 | - $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1233 | - |
|
1234 | - $output = self::wrap( array( |
|
1235 | - 'content' => $output, |
|
1236 | - 'class' => $wrap_class |
|
1237 | - ) ); |
|
1238 | - } |
|
1239 | - |
|
1240 | - return $output; |
|
1241 | - } |
|
1008 | + // wrap |
|
1009 | + if ( ! $args['no_wrap'] ) { |
|
1010 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1011 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1012 | + $output = self::wrap( array( |
|
1013 | + 'content' => $output, |
|
1014 | + 'class' => $wrap_class, |
|
1015 | + 'element_require' => $args['element_require'], |
|
1016 | + 'argument_id' => $args['id'], |
|
1017 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1018 | + ) ); |
|
1019 | + } |
|
1020 | + |
|
1021 | + |
|
1022 | + return $output; |
|
1023 | + } |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * Build the component. |
|
1027 | + * |
|
1028 | + * @param array $args |
|
1029 | + * |
|
1030 | + * @return string The rendered component. |
|
1031 | + */ |
|
1032 | + public static function radio( $args = array() ) { |
|
1033 | + $defaults = array( |
|
1034 | + 'class' => '', |
|
1035 | + 'wrap_class' => '', |
|
1036 | + 'id' => '', |
|
1037 | + 'title' => '', |
|
1038 | + 'horizontal' => false, |
|
1039 | + // sets the lable horizontal |
|
1040 | + 'value' => '', |
|
1041 | + 'label' => '', |
|
1042 | + 'label_class' => '', |
|
1043 | + 'label_type' => '', |
|
1044 | + 'label_col' => '', |
|
1045 | + // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
1046 | + 'help_text' => '', |
|
1047 | + 'inline' => true, |
|
1048 | + 'required' => false, |
|
1049 | + 'options' => array(), |
|
1050 | + 'icon' => '', |
|
1051 | + 'no_wrap' => false, |
|
1052 | + 'element_require' => '', |
|
1053 | + // [%element_id%] == "1" |
|
1054 | + 'extra_attributes' => array(), |
|
1055 | + // an array of extra attributes |
|
1056 | + 'wrap_attributes' => array() |
|
1057 | + ); |
|
1058 | + |
|
1059 | + /** |
|
1060 | + * Parse incoming $args into an array and merge it with $defaults |
|
1061 | + */ |
|
1062 | + $args = wp_parse_args( $args, $defaults ); |
|
1063 | + |
|
1064 | + // for now lets use horizontal for floating |
|
1065 | + if ( $args['label_type'] == 'floating' ) { |
|
1066 | + $args['label_type'] = 'horizontal'; |
|
1067 | + } |
|
1068 | + |
|
1069 | + $label_args = array( |
|
1070 | + 'title' => $args['label'], |
|
1071 | + 'class' => $args['label_class'] . " pt-0 ", |
|
1072 | + 'label_type' => $args['label_type'], |
|
1073 | + 'label_col' => $args['label_col'] |
|
1074 | + ); |
|
1075 | + |
|
1076 | + $output = ''; |
|
1077 | + |
|
1078 | + |
|
1079 | + // label before |
|
1080 | + if ( ! empty( $args['label'] ) ) { |
|
1081 | + $output .= self::label( $label_args, 'radio' ); |
|
1082 | + } |
|
1083 | + |
|
1084 | + // maybe horizontal label |
|
1085 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1086 | + $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); |
|
1087 | + $output .= '<div class="' . $input_col . '">'; |
|
1088 | + } |
|
1089 | + |
|
1090 | + if ( ! empty( $args['options'] ) ) { |
|
1091 | + $count = 0; |
|
1092 | + foreach ( $args['options'] as $value => $label ) { |
|
1093 | + $option_args = $args; |
|
1094 | + $option_args['value'] = $value; |
|
1095 | + $option_args['label'] = $label; |
|
1096 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
1097 | + $output .= self::radio_option( $option_args, $count ); |
|
1098 | + $count ++; |
|
1099 | + } |
|
1100 | + } |
|
1101 | + |
|
1102 | + // help text |
|
1103 | + $help_text = ! empty( $args['help_text'] ) ? AUI_Component_Helper::help_text( $args['help_text'] ) : ''; |
|
1104 | + $output .= $help_text; |
|
1105 | + |
|
1106 | + // maybe horizontal label |
|
1107 | + if ( $args['label_type'] == 'horizontal' ) { |
|
1108 | + $output .= '</div>'; |
|
1109 | + } |
|
1110 | + |
|
1111 | + // wrap |
|
1112 | + $wrap_class = $args['label_type'] == 'horizontal' ? 'form-group row' : 'form-group'; |
|
1113 | + $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; |
|
1114 | + $output = self::wrap( array( |
|
1115 | + 'content' => $output, |
|
1116 | + 'class' => $wrap_class, |
|
1117 | + 'element_require' => $args['element_require'], |
|
1118 | + 'argument_id' => $args['id'], |
|
1119 | + 'wrap_attributes' => $args['wrap_attributes'], |
|
1120 | + ) ); |
|
1121 | + |
|
1122 | + |
|
1123 | + return $output; |
|
1124 | + } |
|
1125 | + |
|
1126 | + /** |
|
1127 | + * Build the component. |
|
1128 | + * |
|
1129 | + * @param array $args |
|
1130 | + * |
|
1131 | + * @return string The rendered component. |
|
1132 | + */ |
|
1133 | + public static function radio_option( $args = array(), $count = '' ) { |
|
1134 | + $defaults = array( |
|
1135 | + 'class' => '', |
|
1136 | + 'id' => '', |
|
1137 | + 'title' => '', |
|
1138 | + 'value' => '', |
|
1139 | + 'required' => false, |
|
1140 | + 'inline' => true, |
|
1141 | + 'label' => '', |
|
1142 | + 'options' => array(), |
|
1143 | + 'icon' => '', |
|
1144 | + 'no_wrap' => false, |
|
1145 | + 'extra_attributes' => array() // an array of extra attributes |
|
1146 | + ); |
|
1147 | + |
|
1148 | + /** |
|
1149 | + * Parse incoming $args into an array and merge it with $defaults |
|
1150 | + */ |
|
1151 | + $args = wp_parse_args( $args, $defaults ); |
|
1152 | + |
|
1153 | + $output = ''; |
|
1154 | + |
|
1155 | + // open/type |
|
1156 | + $output .= '<input type="radio"'; |
|
1157 | + |
|
1158 | + // class |
|
1159 | + $output .= ' class="form-check-input" '; |
|
1160 | + |
|
1161 | + // name |
|
1162 | + if ( ! empty( $args['name'] ) ) { |
|
1163 | + $output .= AUI_Component_Helper::name( $args['name'] ); |
|
1164 | + } |
|
1165 | + |
|
1166 | + // id |
|
1167 | + if ( ! empty( $args['id'] ) ) { |
|
1168 | + $output .= AUI_Component_Helper::id( $args['id'] . $count ); |
|
1169 | + } |
|
1170 | + |
|
1171 | + // title |
|
1172 | + if ( ! empty( $args['title'] ) ) { |
|
1173 | + $output .= AUI_Component_Helper::title( $args['title'] ); |
|
1174 | + } |
|
1175 | + |
|
1176 | + // value |
|
1177 | + if ( isset( $args['value'] ) ) { |
|
1178 | + $output .= AUI_Component_Helper::value( $args['value'] ); |
|
1179 | + } |
|
1180 | + |
|
1181 | + // checked, for radio and checkboxes |
|
1182 | + if ( $args['checked'] ) { |
|
1183 | + $output .= ' checked '; |
|
1184 | + } |
|
1185 | + |
|
1186 | + // data-attributes |
|
1187 | + $output .= AUI_Component_Helper::data_attributes( $args ); |
|
1188 | + |
|
1189 | + // aria-attributes |
|
1190 | + $output .= AUI_Component_Helper::aria_attributes( $args ); |
|
1191 | + |
|
1192 | + // extra attributes |
|
1193 | + if ( ! empty( $args['extra_attributes'] ) ) { |
|
1194 | + $output .= AUI_Component_Helper::extra_attributes( $args['extra_attributes'] ); |
|
1195 | + } |
|
1196 | + |
|
1197 | + // required |
|
1198 | + if ( ! empty( $args['required'] ) ) { |
|
1199 | + $output .= ' required '; |
|
1200 | + } |
|
1201 | + |
|
1202 | + // close opening tag |
|
1203 | + $output .= ' >'; |
|
1204 | + |
|
1205 | + // label |
|
1206 | + if ( ! empty( $args['label'] ) && is_array( $args['label'] ) ) { |
|
1207 | + } elseif ( ! empty( $args['label'] ) ) { |
|
1208 | + $output .= self::label( array( |
|
1209 | + 'title' => $args['label'], |
|
1210 | + 'for' => $args['id'] . $count, |
|
1211 | + 'class' => 'form-check-label' |
|
1212 | + ), 'radio' ); |
|
1213 | + } |
|
1214 | + |
|
1215 | + // wrap |
|
1216 | + if ( ! $args['no_wrap'] ) { |
|
1217 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1218 | + |
|
1219 | + // Unique wrap class |
|
1220 | + $uniq_class = 'fwrap'; |
|
1221 | + if ( ! empty( $args['name'] ) ) { |
|
1222 | + $uniq_class .= '-' . $args['name']; |
|
1223 | + } else if ( ! empty( $args['id'] ) ) { |
|
1224 | + $uniq_class .= '-' . $args['id']; |
|
1225 | + } |
|
1226 | + |
|
1227 | + if ( isset( $args['value'] ) || $args['value'] !== "" ) { |
|
1228 | + $uniq_class .= '-' . $args['value']; |
|
1229 | + } else { |
|
1230 | + $uniq_class .= '-' . $count; |
|
1231 | + } |
|
1232 | + $wrap_class .= ' ' . sanitize_html_class( $uniq_class ); |
|
1233 | + |
|
1234 | + $output = self::wrap( array( |
|
1235 | + 'content' => $output, |
|
1236 | + 'class' => $wrap_class |
|
1237 | + ) ); |
|
1238 | + } |
|
1239 | + |
|
1240 | + return $output; |
|
1241 | + } |
|
1242 | 1242 | |
1243 | 1243 | } |
1244 | 1244 | \ No newline at end of file |
@@ -12,47 +12,47 @@ discard block |
||
12 | 12 | */ |
13 | 13 | class GetPaid_Reports_Export { |
14 | 14 | |
15 | - /** |
|
16 | - * Displays the reports tab. |
|
17 | - * |
|
18 | - */ |
|
19 | - public function display() { |
|
20 | - |
|
21 | - echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
24 | - } |
|
25 | - $this->display_subscription_export(); |
|
26 | - echo '</div>'; |
|
27 | - |
|
28 | - } |
|
29 | - |
|
30 | - /** |
|
31 | - * Retrieves the download url. |
|
32 | - * |
|
33 | - */ |
|
34 | - public function get_download_url( $post_type ) { |
|
35 | - |
|
36 | - return wp_nonce_url( |
|
37 | - add_query_arg( |
|
38 | - array( |
|
39 | - 'getpaid-admin-action' => 'export_invoices', |
|
40 | - 'post_type' => urlencode( $post_type ), |
|
41 | - ) |
|
42 | - ), |
|
43 | - 'getpaid-nonce', |
|
44 | - 'getpaid-nonce' |
|
45 | - ); |
|
46 | - |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Displays a single post type export card. |
|
51 | - * |
|
52 | - */ |
|
53 | - public function display_post_type_export( $post_type ) { |
|
54 | - |
|
55 | - ?> |
|
15 | + /** |
|
16 | + * Displays the reports tab. |
|
17 | + * |
|
18 | + */ |
|
19 | + public function display() { |
|
20 | + |
|
21 | + echo "<div class='row mt-4' style='max-width: 920px;' >"; |
|
22 | + foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | + $this->display_post_type_export( $post_type ); |
|
24 | + } |
|
25 | + $this->display_subscription_export(); |
|
26 | + echo '</div>'; |
|
27 | + |
|
28 | + } |
|
29 | + |
|
30 | + /** |
|
31 | + * Retrieves the download url. |
|
32 | + * |
|
33 | + */ |
|
34 | + public function get_download_url( $post_type ) { |
|
35 | + |
|
36 | + return wp_nonce_url( |
|
37 | + add_query_arg( |
|
38 | + array( |
|
39 | + 'getpaid-admin-action' => 'export_invoices', |
|
40 | + 'post_type' => urlencode( $post_type ), |
|
41 | + ) |
|
42 | + ), |
|
43 | + 'getpaid-nonce', |
|
44 | + 'getpaid-nonce' |
|
45 | + ); |
|
46 | + |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Displays a single post type export card. |
|
51 | + * |
|
52 | + */ |
|
53 | + public function display_post_type_export( $post_type ) { |
|
54 | + |
|
55 | + ?> |
|
56 | 56 | |
57 | 57 | <div class="col-12 col-md-6"> |
58 | 58 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | <div class="card-header"> |
61 | 61 | <strong> |
62 | 62 | <?php |
63 | - printf( |
|
64 | - esc_html__( 'Export %s', 'invoicing' ), |
|
65 | - esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
66 | - ); |
|
67 | - ?> |
|
63 | + printf( |
|
64 | + esc_html__( 'Export %s', 'invoicing' ), |
|
65 | + esc_html( getpaid_get_post_type_label( $post_type ) ) |
|
66 | + ); |
|
67 | + ?> |
|
68 | 68 | </strong> |
69 | 69 | </div> |
70 | 70 | |
@@ -73,12 +73,12 @@ discard block |
||
73 | 73 | <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
74 | 74 | |
75 | 75 | <?php |
76 | - $this->generate_from_date( $post_type ); |
|
77 | - $this->generate_to_date( $post_type ); |
|
78 | - $this->generate_post_status_select( $post_type ); |
|
79 | - $this->generate_file_type_select( $post_type ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | - ?> |
|
76 | + $this->generate_from_date( $post_type ); |
|
77 | + $this->generate_to_date( $post_type ); |
|
78 | + $this->generate_post_status_select( $post_type ); |
|
79 | + $this->generate_file_type_select( $post_type ); |
|
80 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
81 | + ?> |
|
82 | 82 | |
83 | 83 | </form> |
84 | 84 | |
@@ -89,135 +89,135 @@ discard block |
||
89 | 89 | |
90 | 90 | <?php |
91 | 91 | |
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * Generates the from date input field. |
|
96 | - * |
|
97 | - */ |
|
98 | - public function generate_from_date( $post_type ) { |
|
99 | - |
|
100 | - aui()->input( |
|
101 | - array( |
|
102 | - 'type' => 'datepicker', |
|
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | - 'name' => 'from_date', |
|
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
106 | - 'label_type' => 'vertical', |
|
107 | - 'placeholder' => 'YYYY-MM-DD', |
|
108 | - 'extra_attributes' => array( |
|
109 | - 'data-enable-time' => 'false', |
|
110 | - 'data-allow-input' => 'true', |
|
111 | - ), |
|
112 | - ), |
|
113 | - true |
|
114 | - ); |
|
115 | - |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Generates the to date input field. |
|
120 | - * |
|
121 | - */ |
|
122 | - public function generate_to_date( $post_type ) { |
|
123 | - |
|
124 | - aui()->input( |
|
125 | - array( |
|
126 | - 'type' => 'datepicker', |
|
127 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
128 | - 'name' => 'to_date', |
|
129 | - 'label' => __( 'To Date', 'invoicing' ), |
|
130 | - 'label_type' => 'vertical', |
|
131 | - 'placeholder' => 'YYYY-MM-DD', |
|
132 | - 'extra_attributes' => array( |
|
133 | - 'data-enable-time' => 'false', |
|
134 | - 'data-allow-input' => 'true', |
|
135 | - ), |
|
136 | - ), |
|
137 | - true |
|
138 | - ); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Generates the to post status select field. |
|
143 | - * |
|
144 | - */ |
|
145 | - public function generate_post_status_select( $post_type ) { |
|
146 | - |
|
147 | - if ( 'subscriptions' === $post_type ) { |
|
148 | - $options = getpaid_get_subscription_statuses(); |
|
149 | - } else { |
|
150 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
151 | - } |
|
152 | - |
|
153 | - aui()->select( |
|
154 | - array( |
|
155 | - 'name' => 'status', |
|
156 | - 'id' => esc_attr( "$post_type-status" ), |
|
157 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
158 | - 'label' => __( 'Status', 'invoicing' ), |
|
159 | - 'label_type' => 'vertical', |
|
160 | - 'label_class' => 'd-block', |
|
161 | - 'options' => $options, |
|
162 | - ), |
|
163 | - true |
|
164 | - ); |
|
165 | - |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Generates the to file type select field. |
|
170 | - * |
|
171 | - */ |
|
172 | - public function generate_file_type_select( $post_type ) { |
|
173 | - |
|
174 | - aui()->select( |
|
175 | - array( |
|
176 | - 'name' => 'file_type', |
|
177 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
178 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
179 | - 'label' => __( 'Export File', 'invoicing' ), |
|
180 | - 'label_type' => 'vertical', |
|
181 | - 'label_class' => 'd-block', |
|
182 | - 'value' => 'csv', |
|
183 | - 'options' => array( |
|
184 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
185 | - 'xml' => __( 'XML', 'invoicing' ), |
|
186 | - 'json' => __( 'JSON', 'invoicing' ), |
|
187 | - ), |
|
188 | - ), |
|
189 | - true |
|
190 | - ); |
|
191 | - |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Displays a field's markup. |
|
196 | - * |
|
197 | - */ |
|
198 | - public function display_markup( $markup ) { |
|
199 | - |
|
200 | - echo wp_kses( |
|
201 | - str_replace( |
|
202 | - array( |
|
203 | - 'form-control', |
|
204 | - 'custom-select', |
|
205 | - ), |
|
206 | - 'regular-text', |
|
207 | - $markup |
|
208 | - ), |
|
209 | - getpaid_allowed_html() |
|
210 | - ); |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Displays a subscription export card. |
|
216 | - * |
|
217 | - */ |
|
218 | - public function display_subscription_export() { |
|
219 | - |
|
220 | - ?> |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * Generates the from date input field. |
|
96 | + * |
|
97 | + */ |
|
98 | + public function generate_from_date( $post_type ) { |
|
99 | + |
|
100 | + aui()->input( |
|
101 | + array( |
|
102 | + 'type' => 'datepicker', |
|
103 | + 'id' => esc_attr( "$post_type-from_date" ), |
|
104 | + 'name' => 'from_date', |
|
105 | + 'label' => __( 'From Date', 'invoicing' ), |
|
106 | + 'label_type' => 'vertical', |
|
107 | + 'placeholder' => 'YYYY-MM-DD', |
|
108 | + 'extra_attributes' => array( |
|
109 | + 'data-enable-time' => 'false', |
|
110 | + 'data-allow-input' => 'true', |
|
111 | + ), |
|
112 | + ), |
|
113 | + true |
|
114 | + ); |
|
115 | + |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Generates the to date input field. |
|
120 | + * |
|
121 | + */ |
|
122 | + public function generate_to_date( $post_type ) { |
|
123 | + |
|
124 | + aui()->input( |
|
125 | + array( |
|
126 | + 'type' => 'datepicker', |
|
127 | + 'id' => esc_attr( "$post_type-to_date" ), |
|
128 | + 'name' => 'to_date', |
|
129 | + 'label' => __( 'To Date', 'invoicing' ), |
|
130 | + 'label_type' => 'vertical', |
|
131 | + 'placeholder' => 'YYYY-MM-DD', |
|
132 | + 'extra_attributes' => array( |
|
133 | + 'data-enable-time' => 'false', |
|
134 | + 'data-allow-input' => 'true', |
|
135 | + ), |
|
136 | + ), |
|
137 | + true |
|
138 | + ); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Generates the to post status select field. |
|
143 | + * |
|
144 | + */ |
|
145 | + public function generate_post_status_select( $post_type ) { |
|
146 | + |
|
147 | + if ( 'subscriptions' === $post_type ) { |
|
148 | + $options = getpaid_get_subscription_statuses(); |
|
149 | + } else { |
|
150 | + $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
151 | + } |
|
152 | + |
|
153 | + aui()->select( |
|
154 | + array( |
|
155 | + 'name' => 'status', |
|
156 | + 'id' => esc_attr( "$post_type-status" ), |
|
157 | + 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
158 | + 'label' => __( 'Status', 'invoicing' ), |
|
159 | + 'label_type' => 'vertical', |
|
160 | + 'label_class' => 'd-block', |
|
161 | + 'options' => $options, |
|
162 | + ), |
|
163 | + true |
|
164 | + ); |
|
165 | + |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Generates the to file type select field. |
|
170 | + * |
|
171 | + */ |
|
172 | + public function generate_file_type_select( $post_type ) { |
|
173 | + |
|
174 | + aui()->select( |
|
175 | + array( |
|
176 | + 'name' => 'file_type', |
|
177 | + 'id' => esc_attr( "$post_type-file_type" ), |
|
178 | + 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
179 | + 'label' => __( 'Export File', 'invoicing' ), |
|
180 | + 'label_type' => 'vertical', |
|
181 | + 'label_class' => 'd-block', |
|
182 | + 'value' => 'csv', |
|
183 | + 'options' => array( |
|
184 | + 'csv' => __( 'CSV', 'invoicing' ), |
|
185 | + 'xml' => __( 'XML', 'invoicing' ), |
|
186 | + 'json' => __( 'JSON', 'invoicing' ), |
|
187 | + ), |
|
188 | + ), |
|
189 | + true |
|
190 | + ); |
|
191 | + |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Displays a field's markup. |
|
196 | + * |
|
197 | + */ |
|
198 | + public function display_markup( $markup ) { |
|
199 | + |
|
200 | + echo wp_kses( |
|
201 | + str_replace( |
|
202 | + array( |
|
203 | + 'form-control', |
|
204 | + 'custom-select', |
|
205 | + ), |
|
206 | + 'regular-text', |
|
207 | + $markup |
|
208 | + ), |
|
209 | + getpaid_allowed_html() |
|
210 | + ); |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Displays a subscription export card. |
|
216 | + * |
|
217 | + */ |
|
218 | + public function display_subscription_export() { |
|
219 | + |
|
220 | + ?> |
|
221 | 221 | |
222 | 222 | <div class="col-12 col-md-6"> |
223 | 223 | <div class="card m-0 p-0" style="max-width:100%"> |
@@ -233,12 +233,12 @@ discard block |
||
233 | 233 | <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
234 | 234 | |
235 | 235 | <?php |
236 | - $this->generate_from_date( 'subscriptions' ); |
|
237 | - $this->generate_to_date( 'subscriptions' ); |
|
238 | - $this->generate_post_status_select( 'subscriptions' ); |
|
239 | - $this->generate_file_type_select( 'subscriptions' ); |
|
240 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
241 | - ?> |
|
236 | + $this->generate_from_date( 'subscriptions' ); |
|
237 | + $this->generate_to_date( 'subscriptions' ); |
|
238 | + $this->generate_post_status_select( 'subscriptions' ); |
|
239 | + $this->generate_file_type_select( 'subscriptions' ); |
|
240 | + submit_button( __( 'Download', 'invoicing' ) ); |
|
241 | + ?> |
|
242 | 242 | |
243 | 243 | </form> |
244 | 244 | |
@@ -249,6 +249,6 @@ discard block |
||
249 | 249 | |
250 | 250 | <?php |
251 | 251 | |
252 | - } |
|
252 | + } |
|
253 | 253 | |
254 | 254 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,361 +21,361 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class WP_Font_Awesome_Settings |
|
28 | - * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | - * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | - * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | - * @since 1.0.13 RTL language support added. |
|
32 | - * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | - * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend. |
|
34 | - * @since 1.1.0 Option added to load FontAwesome locally. |
|
35 | - * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED. |
|
36 | - * @ver 1.0.15 |
|
37 | - * @todo decide how to implement textdomain |
|
38 | - */ |
|
39 | - class WP_Font_Awesome_Settings { |
|
40 | - |
|
41 | - /** |
|
42 | - * Class version version. |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - public $version = '1.1.1'; |
|
47 | - |
|
48 | - /** |
|
49 | - * Class textdomain. |
|
50 | - * |
|
51 | - * @var string |
|
52 | - */ |
|
53 | - public $textdomain = 'font-awesome-settings'; |
|
54 | - |
|
55 | - /** |
|
56 | - * Latest version of Font Awesome at time of publish published. |
|
57 | - * |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - public $latest = "5.8.2"; |
|
61 | - |
|
62 | - /** |
|
63 | - * The title. |
|
64 | - * |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - public $name = 'Font Awesome'; |
|
68 | - |
|
69 | - /** |
|
70 | - * Holds the settings values. |
|
71 | - * |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - private $settings; |
|
75 | - |
|
76 | - /** |
|
77 | - * WP_Font_Awesome_Settings instance. |
|
78 | - * |
|
79 | - * @access private |
|
80 | - * @since 1.0.0 |
|
81 | - * @var WP_Font_Awesome_Settings There can be only one! |
|
82 | - */ |
|
83 | - private static $instance = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * Main WP_Font_Awesome_Settings Instance. |
|
87 | - * |
|
88 | - * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
89 | - * |
|
90 | - * @since 1.0.0 |
|
91 | - * @static |
|
92 | - * @return WP_Font_Awesome_Settings - Main instance. |
|
93 | - */ |
|
94 | - public static function instance() { |
|
95 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
96 | - self::$instance = new WP_Font_Awesome_Settings; |
|
97 | - |
|
98 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
99 | - |
|
100 | - if ( is_admin() ) { |
|
101 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
102 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
103 | - add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
104 | - } |
|
105 | - |
|
106 | - do_action( 'wp_font_awesome_settings_loaded' ); |
|
107 | - } |
|
108 | - |
|
109 | - return self::$instance; |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Initiate the settings and add the required action hooks. |
|
114 | - * |
|
115 | - * @since 1.0.8 Settings name wrong - FIXED |
|
116 | - */ |
|
117 | - public function init() { |
|
118 | - // Download fontawesome locally. |
|
119 | - add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
120 | - add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
121 | - |
|
122 | - $this->settings = $this->get_settings(); |
|
123 | - |
|
124 | - // check if the official plugin is active and use that instead if so. |
|
125 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
126 | - |
|
127 | - if ( $this->settings['type'] == 'CSS' ) { |
|
128 | - |
|
129 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
130 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
131 | - } |
|
132 | - |
|
133 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
134 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
135 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
136 | - } |
|
137 | - |
|
138 | - } else { |
|
139 | - |
|
140 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
141 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
142 | - } |
|
143 | - |
|
144 | - if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
145 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
146 | - add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - // remove font awesome if set to do so |
|
151 | - if ( $this->settings['dequeue'] == '1' ) { |
|
152 | - add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
153 | - } |
|
154 | - } |
|
155 | - |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Add FA to the FSE. |
|
160 | - * |
|
161 | - * @param $editor_settings |
|
162 | - * @param $block_editor_context |
|
163 | - * |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
167 | - |
|
168 | - if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
169 | - $url = $this->get_url(); |
|
170 | - $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
171 | - } |
|
172 | - |
|
173 | - return $editor_settings; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Add FA to the FSE. |
|
178 | - * |
|
179 | - * @param $editor_settings |
|
180 | - * @param $block_editor_context |
|
181 | - * |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
185 | - |
|
186 | - $url = $this->get_url(); |
|
187 | - $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
188 | - |
|
189 | - return $editor_settings; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Adds the Font Awesome styles. |
|
194 | - */ |
|
195 | - public function enqueue_style() { |
|
196 | - // build url |
|
197 | - $url = $this->get_url(); |
|
198 | - $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
199 | - |
|
200 | - wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
201 | - wp_register_style( 'font-awesome', $url, array(), $version ); |
|
202 | - wp_enqueue_style( 'font-awesome' ); |
|
203 | - |
|
204 | - // RTL language support CSS. |
|
205 | - if ( is_rtl() ) { |
|
206 | - wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
207 | - } |
|
208 | - |
|
209 | - if ( $this->settings['shims'] ) { |
|
210 | - $url = $this->get_url( true ); |
|
211 | - wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
212 | - wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
213 | - wp_enqueue_style( 'font-awesome-shims' ); |
|
214 | - } |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Adds the Font Awesome JS. |
|
219 | - */ |
|
220 | - public function enqueue_scripts() { |
|
221 | - // build url |
|
222 | - $url = $this->get_url(); |
|
223 | - |
|
224 | - $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
225 | - call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
226 | - wp_register_script( 'font-awesome', $url, array(), null ); |
|
227 | - wp_enqueue_script( 'font-awesome' ); |
|
228 | - |
|
229 | - if ( $this->settings['shims'] ) { |
|
230 | - $url = $this->get_url( true ); |
|
231 | - call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
232 | - wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
233 | - wp_enqueue_script( 'font-awesome-shims' ); |
|
234 | - } |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Get the url of the Font Awesome files. |
|
239 | - * |
|
240 | - * @param bool $shims If this is a shim file or not. |
|
241 | - * @param bool $local Load locally if allowed. |
|
242 | - * |
|
243 | - * @return string The url to the file. |
|
244 | - */ |
|
245 | - public function get_url( $shims = false, $local = true ) { |
|
246 | - $script = $shims ? 'v4-shims' : 'all'; |
|
247 | - $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
248 | - $type = $this->settings['type']; |
|
249 | - $version = $this->settings['version']; |
|
250 | - $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
251 | - $url = ''; |
|
252 | - |
|
253 | - if ( $type == 'KIT' && $kit_url ) { |
|
254 | - if ( $shims ) { |
|
255 | - // if its a kit then we don't add shims here |
|
256 | - return ''; |
|
257 | - } |
|
258 | - $url .= $kit_url; // CDN |
|
259 | - $url .= "?wpfas=true"; // set our var so our version is not removed |
|
260 | - } else { |
|
261 | - $v = ''; |
|
262 | - // Check and load locally. |
|
263 | - if ( $local && $this->has_local() ) { |
|
264 | - $script .= ".min"; |
|
265 | - $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
266 | - $url .= $this->get_fonts_url(); // Local fonts url. |
|
267 | - } else { |
|
268 | - $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
269 | - $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
270 | - } |
|
271 | - $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
272 | - $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
273 | - $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
274 | - } |
|
275 | - |
|
276 | - return $url; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
281 | - * |
|
282 | - * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
283 | - * |
|
284 | - * @param $url |
|
285 | - * @param $original_url |
|
286 | - * @param $_context |
|
287 | - * |
|
288 | - * @return string The filtered url. |
|
289 | - */ |
|
290 | - public function remove_font_awesome( $url, $original_url, $_context ) { |
|
291 | - |
|
292 | - if ( $_context == 'display' |
|
293 | - && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
294 | - && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
295 | - ) {// it's a font-awesome-url (probably) |
|
296 | - |
|
297 | - if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
298 | - if ( $this->settings['type'] == 'JS' ) { |
|
299 | - if ( $this->settings['js-pseudo'] ) { |
|
300 | - $url .= "' data-search-pseudo-elements defer='defer"; |
|
301 | - } else { |
|
302 | - $url .= "' defer='defer"; |
|
303 | - } |
|
304 | - } |
|
305 | - } else { |
|
306 | - $url = ''; // removing the url removes the file |
|
307 | - } |
|
308 | - |
|
309 | - } |
|
310 | - |
|
311 | - return $url; |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Register the database settings with WordPress. |
|
316 | - */ |
|
317 | - public function register_settings() { |
|
318 | - register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * Add the WordPress settings menu item. |
|
323 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
324 | - */ |
|
325 | - public function menu_item() { |
|
326 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
327 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
328 | - $this, |
|
329 | - 'settings_page' |
|
330 | - ) ); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Get the current Font Awesome output settings. |
|
335 | - * |
|
336 | - * @return array The array of settings. |
|
337 | - */ |
|
338 | - public function get_settings() { |
|
339 | - $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
340 | - |
|
341 | - $defaults = array( |
|
342 | - 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
343 | - 'version' => '', // latest |
|
344 | - 'enqueue' => '', // front and backend |
|
345 | - 'shims' => '0', // default OFF now in 2020 |
|
346 | - 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
347 | - 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
348 | - 'pro' => '0', // if pro CDN url should be used |
|
349 | - 'local' => '0', // Store fonts locally. |
|
350 | - 'local_version' => '', // Local fonts version. |
|
351 | - 'kit-url' => '', // the kit url |
|
352 | - ); |
|
353 | - |
|
354 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
355 | - |
|
356 | - /** |
|
357 | - * Filter the Font Awesome settings. |
|
358 | - * |
|
359 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
360 | - */ |
|
361 | - return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * The settings page html output. |
|
366 | - */ |
|
367 | - public function settings_page() { |
|
368 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
369 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
370 | - } |
|
371 | - |
|
372 | - // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
373 | - if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
374 | - $this->get_latest_version( $force_api = true ); |
|
375 | - } |
|
376 | - |
|
377 | - if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
378 | - ?> |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class WP_Font_Awesome_Settings |
|
28 | + * @since 1.0.10 Now able to pass wp.org theme check. |
|
29 | + * @since 1.0.11 Font Awesome Pro now supported. |
|
30 | + * @since 1.0.11 Font Awesome Kits now supported. |
|
31 | + * @since 1.0.13 RTL language support added. |
|
32 | + * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed. |
|
33 | + * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend. |
|
34 | + * @since 1.1.0 Option added to load FontAwesome locally. |
|
35 | + * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED. |
|
36 | + * @ver 1.0.15 |
|
37 | + * @todo decide how to implement textdomain |
|
38 | + */ |
|
39 | + class WP_Font_Awesome_Settings { |
|
40 | + |
|
41 | + /** |
|
42 | + * Class version version. |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + public $version = '1.1.1'; |
|
47 | + |
|
48 | + /** |
|
49 | + * Class textdomain. |
|
50 | + * |
|
51 | + * @var string |
|
52 | + */ |
|
53 | + public $textdomain = 'font-awesome-settings'; |
|
54 | + |
|
55 | + /** |
|
56 | + * Latest version of Font Awesome at time of publish published. |
|
57 | + * |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + public $latest = "5.8.2"; |
|
61 | + |
|
62 | + /** |
|
63 | + * The title. |
|
64 | + * |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + public $name = 'Font Awesome'; |
|
68 | + |
|
69 | + /** |
|
70 | + * Holds the settings values. |
|
71 | + * |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + private $settings; |
|
75 | + |
|
76 | + /** |
|
77 | + * WP_Font_Awesome_Settings instance. |
|
78 | + * |
|
79 | + * @access private |
|
80 | + * @since 1.0.0 |
|
81 | + * @var WP_Font_Awesome_Settings There can be only one! |
|
82 | + */ |
|
83 | + private static $instance = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * Main WP_Font_Awesome_Settings Instance. |
|
87 | + * |
|
88 | + * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded. |
|
89 | + * |
|
90 | + * @since 1.0.0 |
|
91 | + * @static |
|
92 | + * @return WP_Font_Awesome_Settings - Main instance. |
|
93 | + */ |
|
94 | + public static function instance() { |
|
95 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) { |
|
96 | + self::$instance = new WP_Font_Awesome_Settings; |
|
97 | + |
|
98 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
99 | + |
|
100 | + if ( is_admin() ) { |
|
101 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
102 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
103 | + add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) ); |
|
104 | + } |
|
105 | + |
|
106 | + do_action( 'wp_font_awesome_settings_loaded' ); |
|
107 | + } |
|
108 | + |
|
109 | + return self::$instance; |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Initiate the settings and add the required action hooks. |
|
114 | + * |
|
115 | + * @since 1.0.8 Settings name wrong - FIXED |
|
116 | + */ |
|
117 | + public function init() { |
|
118 | + // Download fontawesome locally. |
|
119 | + add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 ); |
|
120 | + add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
121 | + |
|
122 | + $this->settings = $this->get_settings(); |
|
123 | + |
|
124 | + // check if the official plugin is active and use that instead if so. |
|
125 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
126 | + |
|
127 | + if ( $this->settings['type'] == 'CSS' ) { |
|
128 | + |
|
129 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
130 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
131 | + } |
|
132 | + |
|
133 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
134 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 ); |
|
135 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 ); |
|
136 | + } |
|
137 | + |
|
138 | + } else { |
|
139 | + |
|
140 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) { |
|
141 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
142 | + } |
|
143 | + |
|
144 | + if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) { |
|
145 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 ); |
|
146 | + add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 ); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + // remove font awesome if set to do so |
|
151 | + if ( $this->settings['dequeue'] == '1' ) { |
|
152 | + add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 ); |
|
153 | + } |
|
154 | + } |
|
155 | + |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Add FA to the FSE. |
|
160 | + * |
|
161 | + * @param $editor_settings |
|
162 | + * @param $block_editor_context |
|
163 | + * |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + public function enqueue_editor_styles( $editor_settings, $block_editor_context ){ |
|
167 | + |
|
168 | + if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) { |
|
169 | + $url = $this->get_url(); |
|
170 | + $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css' href='$url' media='all' />"; |
|
171 | + } |
|
172 | + |
|
173 | + return $editor_settings; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Add FA to the FSE. |
|
178 | + * |
|
179 | + * @param $editor_settings |
|
180 | + * @param $block_editor_context |
|
181 | + * |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){ |
|
185 | + |
|
186 | + $url = $this->get_url(); |
|
187 | + $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>"; |
|
188 | + |
|
189 | + return $editor_settings; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Adds the Font Awesome styles. |
|
194 | + */ |
|
195 | + public function enqueue_style() { |
|
196 | + // build url |
|
197 | + $url = $this->get_url(); |
|
198 | + $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null; |
|
199 | + |
|
200 | + wp_deregister_style( 'font-awesome' ); // deregister in case its already there |
|
201 | + wp_register_style( 'font-awesome', $url, array(), $version ); |
|
202 | + wp_enqueue_style( 'font-awesome' ); |
|
203 | + |
|
204 | + // RTL language support CSS. |
|
205 | + if ( is_rtl() ) { |
|
206 | + wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() ); |
|
207 | + } |
|
208 | + |
|
209 | + if ( $this->settings['shims'] ) { |
|
210 | + $url = $this->get_url( true ); |
|
211 | + wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there |
|
212 | + wp_register_style( 'font-awesome-shims', $url, array(), $version ); |
|
213 | + wp_enqueue_style( 'font-awesome-shims' ); |
|
214 | + } |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Adds the Font Awesome JS. |
|
219 | + */ |
|
220 | + public function enqueue_scripts() { |
|
221 | + // build url |
|
222 | + $url = $this->get_url(); |
|
223 | + |
|
224 | + $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script'; |
|
225 | + call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there |
|
226 | + wp_register_script( 'font-awesome', $url, array(), null ); |
|
227 | + wp_enqueue_script( 'font-awesome' ); |
|
228 | + |
|
229 | + if ( $this->settings['shims'] ) { |
|
230 | + $url = $this->get_url( true ); |
|
231 | + call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there |
|
232 | + wp_register_script( 'font-awesome-shims', $url, array(), null ); |
|
233 | + wp_enqueue_script( 'font-awesome-shims' ); |
|
234 | + } |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Get the url of the Font Awesome files. |
|
239 | + * |
|
240 | + * @param bool $shims If this is a shim file or not. |
|
241 | + * @param bool $local Load locally if allowed. |
|
242 | + * |
|
243 | + * @return string The url to the file. |
|
244 | + */ |
|
245 | + public function get_url( $shims = false, $local = true ) { |
|
246 | + $script = $shims ? 'v4-shims' : 'all'; |
|
247 | + $sub = $this->settings['pro'] ? 'pro' : 'use'; |
|
248 | + $type = $this->settings['type']; |
|
249 | + $version = $this->settings['version']; |
|
250 | + $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : ''; |
|
251 | + $url = ''; |
|
252 | + |
|
253 | + if ( $type == 'KIT' && $kit_url ) { |
|
254 | + if ( $shims ) { |
|
255 | + // if its a kit then we don't add shims here |
|
256 | + return ''; |
|
257 | + } |
|
258 | + $url .= $kit_url; // CDN |
|
259 | + $url .= "?wpfas=true"; // set our var so our version is not removed |
|
260 | + } else { |
|
261 | + $v = ''; |
|
262 | + // Check and load locally. |
|
263 | + if ( $local && $this->has_local() ) { |
|
264 | + $script .= ".min"; |
|
265 | + $v .= '&ver=' . strip_tags( $this->settings['local_version'] ); |
|
266 | + $url .= $this->get_fonts_url(); // Local fonts url. |
|
267 | + } else { |
|
268 | + $url .= "https://$sub.fontawesome.com/releases/"; // CDN |
|
269 | + $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version |
|
270 | + } |
|
271 | + $url .= $type == 'CSS' ? 'css/' : 'js/'; // type |
|
272 | + $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type |
|
273 | + $url .= "?wpfas=true" . $v; // set our var so our version is not removed |
|
274 | + } |
|
275 | + |
|
276 | + return $url; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Try and remove any other versions of Font Awesome added by other plugins/themes. |
|
281 | + * |
|
282 | + * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version. |
|
283 | + * |
|
284 | + * @param $url |
|
285 | + * @param $original_url |
|
286 | + * @param $_context |
|
287 | + * |
|
288 | + * @return string The filtered url. |
|
289 | + */ |
|
290 | + public function remove_font_awesome( $url, $original_url, $_context ) { |
|
291 | + |
|
292 | + if ( $_context == 'display' |
|
293 | + && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false ) |
|
294 | + && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false ) |
|
295 | + ) {// it's a font-awesome-url (probably) |
|
296 | + |
|
297 | + if ( strstr( $url, "wpfas=true" ) !== false ) { |
|
298 | + if ( $this->settings['type'] == 'JS' ) { |
|
299 | + if ( $this->settings['js-pseudo'] ) { |
|
300 | + $url .= "' data-search-pseudo-elements defer='defer"; |
|
301 | + } else { |
|
302 | + $url .= "' defer='defer"; |
|
303 | + } |
|
304 | + } |
|
305 | + } else { |
|
306 | + $url = ''; // removing the url removes the file |
|
307 | + } |
|
308 | + |
|
309 | + } |
|
310 | + |
|
311 | + return $url; |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Register the database settings with WordPress. |
|
316 | + */ |
|
317 | + public function register_settings() { |
|
318 | + register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' ); |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * Add the WordPress settings menu item. |
|
323 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
324 | + */ |
|
325 | + public function menu_item() { |
|
326 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
327 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array( |
|
328 | + $this, |
|
329 | + 'settings_page' |
|
330 | + ) ); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Get the current Font Awesome output settings. |
|
335 | + * |
|
336 | + * @return array The array of settings. |
|
337 | + */ |
|
338 | + public function get_settings() { |
|
339 | + $db_settings = get_option( 'wp-font-awesome-settings' ); |
|
340 | + |
|
341 | + $defaults = array( |
|
342 | + 'type' => 'CSS', // type to use, CSS or JS or KIT |
|
343 | + 'version' => '', // latest |
|
344 | + 'enqueue' => '', // front and backend |
|
345 | + 'shims' => '0', // default OFF now in 2020 |
|
346 | + 'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive) |
|
347 | + 'dequeue' => '0', // if we should try to remove other versions added by other plugins/themes |
|
348 | + 'pro' => '0', // if pro CDN url should be used |
|
349 | + 'local' => '0', // Store fonts locally. |
|
350 | + 'local_version' => '', // Local fonts version. |
|
351 | + 'kit-url' => '', // the kit url |
|
352 | + ); |
|
353 | + |
|
354 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
355 | + |
|
356 | + /** |
|
357 | + * Filter the Font Awesome settings. |
|
358 | + * |
|
359 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
360 | + */ |
|
361 | + return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults ); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * The settings page html output. |
|
366 | + */ |
|
367 | + public function settings_page() { |
|
368 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
369 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) ); |
|
370 | + } |
|
371 | + |
|
372 | + // a hidden way to force the update of the version number via api instead of waiting the 48 hours |
|
373 | + if ( isset( $_REQUEST['force-version-check'] ) ) { |
|
374 | + $this->get_latest_version( $force_api = true ); |
|
375 | + } |
|
376 | + |
|
377 | + if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
378 | + ?> |
|
379 | 379 | <style> |
380 | 380 | .wpfas-kit-show { |
381 | 381 | display: none; |
@@ -401,16 +401,16 @@ discard block |
||
401 | 401 | <h1><?php echo $this->name; ?></h1> |
402 | 402 | <form method="post" action="options.php" class="fas-settings-form"> |
403 | 403 | <?php |
404 | - settings_fields( 'wp-font-awesome-settings' ); |
|
405 | - do_settings_sections( 'wp-font-awesome-settings' ); |
|
406 | - $table_class = ''; |
|
407 | - if ( $this->settings['type'] ) { |
|
408 | - $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
409 | - } |
|
410 | - if ( ! empty( $this->settings['pro'] ) ) { |
|
411 | - $table_class .= ' wpfas-has-pro'; |
|
412 | - } |
|
413 | - ?> |
|
404 | + settings_fields( 'wp-font-awesome-settings' ); |
|
405 | + do_settings_sections( 'wp-font-awesome-settings' ); |
|
406 | + $table_class = ''; |
|
407 | + if ( $this->settings['type'] ) { |
|
408 | + $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set'; |
|
409 | + } |
|
410 | + if ( ! empty( $this->settings['pro'] ) ) { |
|
411 | + $table_class .= ' wpfas-has-pro'; |
|
412 | + } |
|
413 | + ?> |
|
414 | 414 | <?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?> |
415 | 415 | <?php if ( $this->has_local() ) { ?> |
416 | 416 | <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'font-awesome-settings' ); ?></strong></p></div> |
@@ -435,12 +435,12 @@ discard block |
||
435 | 435 | <td> |
436 | 436 | <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/> |
437 | 437 | <span><?php |
438 | - echo sprintf( |
|
439 | - __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
440 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
441 | - '</a>' |
|
442 | - ); |
|
443 | - ?></span> |
|
438 | + echo sprintf( |
|
439 | + __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ), |
|
440 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>', |
|
441 | + '</a>' |
|
442 | + ); |
|
443 | + ?></span> |
|
444 | 444 | </td> |
445 | 445 | </tr> |
446 | 446 | |
@@ -481,14 +481,14 @@ discard block |
||
481 | 481 | <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/> |
482 | 482 | <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/> |
483 | 483 | <span><?php |
484 | - echo wp_sprintf( |
|
485 | - __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
486 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
487 | - ' <i class="fas fa-external-link-alt"></i></a>', |
|
488 | - '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
489 | - ' <i class="fas fa-external-link-alt"></i></a>' |
|
490 | - ); |
|
491 | - ?></span> |
|
484 | + echo wp_sprintf( |
|
485 | + __( 'Requires a subscription. %sLearn more%s %sManage my allowed domains%s', 'font-awesome-settings' ), |
|
486 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">', |
|
487 | + ' <i class="fas fa-external-link-alt"></i></a>', |
|
488 | + '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">', |
|
489 | + ' <i class="fas fa-external-link-alt"></i></a>' |
|
490 | + ); |
|
491 | + ?></span> |
|
492 | 492 | </td> |
493 | 493 | </tr> |
494 | 494 | |
@@ -542,8 +542,8 @@ discard block |
||
542 | 542 | </table> |
543 | 543 | <div class="fas-buttons"> |
544 | 544 | <?php |
545 | - submit_button(); |
|
546 | - ?> |
|
545 | + submit_button(); |
|
546 | + ?> |
|
547 | 547 | <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p> |
548 | 548 | |
549 | 549 | </div> |
@@ -552,392 +552,392 @@ discard block |
||
552 | 552 | <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div> |
553 | 553 | </div> |
554 | 554 | <?php |
555 | - } |
|
556 | - } |
|
557 | - |
|
558 | - /** |
|
559 | - * Check a version number is valid and if so return it or else return an empty string. |
|
560 | - * |
|
561 | - * @param $version string The version number to check. |
|
562 | - * |
|
563 | - * @since 1.0.6 |
|
564 | - * |
|
565 | - * @return string Either a valid version number or an empty string. |
|
566 | - */ |
|
567 | - public function validate_version_number( $version ) { |
|
568 | - |
|
569 | - if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
570 | - // valid |
|
571 | - } else { |
|
572 | - $version = '';// not validated |
|
573 | - } |
|
574 | - |
|
575 | - return $version; |
|
576 | - } |
|
577 | - |
|
578 | - |
|
579 | - /** |
|
580 | - * Get the latest version of Font Awesome. |
|
581 | - * |
|
582 | - * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
583 | - * |
|
584 | - * @since 1.0.7 |
|
585 | - * @return mixed|string The latest version number found. |
|
586 | - */ |
|
587 | - public function get_latest_version( $force_api = false ) { |
|
588 | - $latest_version = $this->latest; |
|
589 | - |
|
590 | - $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
591 | - |
|
592 | - if ( $cache === false || $force_api ) { // its not set |
|
593 | - $api_ver = $this->get_latest_version_from_api(); |
|
594 | - if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
595 | - $latest_version = $api_ver; |
|
596 | - set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
597 | - } |
|
598 | - } elseif ( $this->validate_version_number( $cache ) ) { |
|
599 | - if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
600 | - $latest_version = $cache; |
|
601 | - } |
|
602 | - } |
|
603 | - |
|
604 | - // Check and auto download fonts locally. |
|
605 | - if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
606 | - if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
607 | - $this->download_package( $latest_version ); |
|
608 | - } |
|
609 | - } |
|
610 | - |
|
611 | - return $latest_version; |
|
612 | - } |
|
613 | - |
|
614 | - /** |
|
615 | - * Get the latest Font Awesome version from the github API. |
|
616 | - * |
|
617 | - * @since 1.0.7 |
|
618 | - * @return string The latest version number or `0` on API fail. |
|
619 | - */ |
|
620 | - public function get_latest_version_from_api() { |
|
621 | - $version = "0"; |
|
622 | - $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
623 | - if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
624 | - $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
625 | - if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
626 | - $version = $api_response['tag_name']; |
|
627 | - } |
|
628 | - } |
|
629 | - |
|
630 | - return $version; |
|
631 | - } |
|
632 | - |
|
633 | - /** |
|
634 | - * Inline CSS for RTL language support. |
|
635 | - * |
|
636 | - * @since 1.0.13 |
|
637 | - * @return string Inline CSS. |
|
638 | - */ |
|
639 | - public function rtl_inline_css() { |
|
640 | - $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
641 | - |
|
642 | - return $inline_css; |
|
643 | - } |
|
644 | - |
|
645 | - /** |
|
646 | - * Show any warnings as an admin notice. |
|
647 | - * |
|
648 | - * @return void |
|
649 | - */ |
|
650 | - public function admin_notices() { |
|
651 | - $settings = $this->settings; |
|
652 | - |
|
653 | - if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
654 | - if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
655 | - ?> |
|
555 | + } |
|
556 | + } |
|
557 | + |
|
558 | + /** |
|
559 | + * Check a version number is valid and if so return it or else return an empty string. |
|
560 | + * |
|
561 | + * @param $version string The version number to check. |
|
562 | + * |
|
563 | + * @since 1.0.6 |
|
564 | + * |
|
565 | + * @return string Either a valid version number or an empty string. |
|
566 | + */ |
|
567 | + public function validate_version_number( $version ) { |
|
568 | + |
|
569 | + if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) { |
|
570 | + // valid |
|
571 | + } else { |
|
572 | + $version = '';// not validated |
|
573 | + } |
|
574 | + |
|
575 | + return $version; |
|
576 | + } |
|
577 | + |
|
578 | + |
|
579 | + /** |
|
580 | + * Get the latest version of Font Awesome. |
|
581 | + * |
|
582 | + * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours. |
|
583 | + * |
|
584 | + * @since 1.0.7 |
|
585 | + * @return mixed|string The latest version number found. |
|
586 | + */ |
|
587 | + public function get_latest_version( $force_api = false ) { |
|
588 | + $latest_version = $this->latest; |
|
589 | + |
|
590 | + $cache = get_transient( 'wp-font-awesome-settings-version' ); |
|
591 | + |
|
592 | + if ( $cache === false || $force_api ) { // its not set |
|
593 | + $api_ver = $this->get_latest_version_from_api(); |
|
594 | + if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) { |
|
595 | + $latest_version = $api_ver; |
|
596 | + set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS ); |
|
597 | + } |
|
598 | + } elseif ( $this->validate_version_number( $cache ) ) { |
|
599 | + if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) { |
|
600 | + $latest_version = $cache; |
|
601 | + } |
|
602 | + } |
|
603 | + |
|
604 | + // Check and auto download fonts locally. |
|
605 | + if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) { |
|
606 | + if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) { |
|
607 | + $this->download_package( $latest_version ); |
|
608 | + } |
|
609 | + } |
|
610 | + |
|
611 | + return $latest_version; |
|
612 | + } |
|
613 | + |
|
614 | + /** |
|
615 | + * Get the latest Font Awesome version from the github API. |
|
616 | + * |
|
617 | + * @since 1.0.7 |
|
618 | + * @return string The latest version number or `0` on API fail. |
|
619 | + */ |
|
620 | + public function get_latest_version_from_api() { |
|
621 | + $version = "0"; |
|
622 | + $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" ); |
|
623 | + if ( ! is_wp_error( $response ) && is_array( $response ) ) { |
|
624 | + $api_response = json_decode( wp_remote_retrieve_body( $response ), true ); |
|
625 | + if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) { |
|
626 | + $version = $api_response['tag_name']; |
|
627 | + } |
|
628 | + } |
|
629 | + |
|
630 | + return $version; |
|
631 | + } |
|
632 | + |
|
633 | + /** |
|
634 | + * Inline CSS for RTL language support. |
|
635 | + * |
|
636 | + * @since 1.0.13 |
|
637 | + * @return string Inline CSS. |
|
638 | + */ |
|
639 | + public function rtl_inline_css() { |
|
640 | + $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}'; |
|
641 | + |
|
642 | + return $inline_css; |
|
643 | + } |
|
644 | + |
|
645 | + /** |
|
646 | + * Show any warnings as an admin notice. |
|
647 | + * |
|
648 | + * @return void |
|
649 | + */ |
|
650 | + public function admin_notices() { |
|
651 | + $settings = $this->settings; |
|
652 | + |
|
653 | + if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) { |
|
654 | + if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) { |
|
655 | + ?> |
|
656 | 656 | <div class="notice notice-error is-dismissible"> |
657 | 657 | <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p> |
658 | 658 | </div> |
659 | 659 | <?php |
660 | - } |
|
661 | - } else { |
|
662 | - if ( ! empty( $settings ) ) { |
|
663 | - if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
664 | - $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
665 | - ?> |
|
660 | + } |
|
661 | + } else { |
|
662 | + if ( ! empty( $settings ) ) { |
|
663 | + if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) { |
|
664 | + $link = admin_url('options-general.php?page=wp-font-awesome-settings'); |
|
665 | + ?> |
|
666 | 666 | <div class="notice notice-error is-dismissible"> |
667 | 667 | <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p> |
668 | 668 | </div> |
669 | 669 | <?php |
670 | - } |
|
671 | - } |
|
672 | - } |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Handle fontawesome add settings to download fontawesome to store locally. |
|
677 | - * |
|
678 | - * @since 1.1.1 |
|
679 | - * |
|
680 | - * @param string $option The option name. |
|
681 | - * @param mixed $value The option value. |
|
682 | - */ |
|
683 | - public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
684 | - // Do nothing if WordPress is being installed. |
|
685 | - if ( wp_installing() ) { |
|
686 | - return; |
|
687 | - } |
|
688 | - |
|
689 | - if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
690 | - $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
691 | - |
|
692 | - if ( ! empty( $version ) ) { |
|
693 | - $response = $this->download_package( $version, $value ); |
|
694 | - |
|
695 | - if ( is_wp_error( $response ) ) { |
|
696 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
697 | - } |
|
698 | - } |
|
699 | - } |
|
700 | - } |
|
701 | - |
|
702 | - /** |
|
703 | - * Handle fontawesome update settings to download fontawesome to store locally. |
|
704 | - * |
|
705 | - * @since 1.1.0 |
|
706 | - * |
|
707 | - * @param mixed $old_value The old option value. |
|
708 | - * @param mixed $value The new option value. |
|
709 | - */ |
|
710 | - public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
711 | - // Do nothing if WordPress is being installed. |
|
712 | - if ( wp_installing() ) { |
|
713 | - return; |
|
714 | - } |
|
715 | - |
|
716 | - if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
717 | - // Old values |
|
718 | - $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
719 | - $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
720 | - |
|
721 | - // New values |
|
722 | - $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
723 | - |
|
724 | - if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
725 | - $response = $this->download_package( $new_version, $new_value ); |
|
726 | - |
|
727 | - if ( is_wp_error( $response ) ) { |
|
728 | - add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
729 | - } |
|
730 | - } |
|
731 | - } |
|
732 | - } |
|
733 | - |
|
734 | - /** |
|
735 | - * Get the fonts directory local path. |
|
736 | - * |
|
737 | - * @since 1.1.0 |
|
738 | - * |
|
739 | - * @param string Fonts directory local path. |
|
740 | - */ |
|
741 | - public function get_fonts_dir() { |
|
742 | - $upload_dir = wp_upload_dir( null, false ); |
|
743 | - |
|
744 | - return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
745 | - } |
|
746 | - |
|
747 | - /** |
|
748 | - * Get the fonts directory local url. |
|
749 | - * |
|
750 | - * @since 1.1.0 |
|
751 | - * |
|
752 | - * @param string Fonts directory local url. |
|
753 | - */ |
|
754 | - public function get_fonts_url() { |
|
755 | - $upload_dir = wp_upload_dir( null, false ); |
|
756 | - |
|
757 | - return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
758 | - } |
|
759 | - |
|
760 | - /** |
|
761 | - * Check whether load locally active. |
|
762 | - * |
|
763 | - * @since 1.1.0 |
|
764 | - * |
|
765 | - * @return bool True if active else false. |
|
766 | - */ |
|
767 | - public function has_local() { |
|
768 | - if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
769 | - return true; |
|
770 | - } |
|
771 | - |
|
772 | - return false; |
|
773 | - } |
|
774 | - |
|
775 | - /** |
|
776 | - * Get the WP Filesystem access. |
|
777 | - * |
|
778 | - * @since 1.1.0 |
|
779 | - * |
|
780 | - * @return object The WP Filesystem. |
|
781 | - */ |
|
782 | - public function get_wp_filesystem() { |
|
783 | - if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
784 | - require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
785 | - } |
|
786 | - |
|
787 | - $access_type = get_filesystem_method(); |
|
788 | - |
|
789 | - if ( $access_type === 'direct' ) { |
|
790 | - /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
791 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
792 | - |
|
793 | - /* Initialize the API */ |
|
794 | - if ( ! WP_Filesystem( $creds ) ) { |
|
795 | - /* Any problems and we exit */ |
|
796 | - return false; |
|
797 | - } |
|
798 | - |
|
799 | - global $wp_filesystem; |
|
800 | - |
|
801 | - return $wp_filesystem; |
|
802 | - /* Do our file manipulations below */ |
|
803 | - } else if ( defined( 'FTP_USER' ) ) { |
|
804 | - $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
805 | - |
|
806 | - /* Initialize the API */ |
|
807 | - if ( ! WP_Filesystem( $creds ) ) { |
|
808 | - /* Any problems and we exit */ |
|
809 | - return false; |
|
810 | - } |
|
811 | - |
|
812 | - global $wp_filesystem; |
|
813 | - |
|
814 | - return $wp_filesystem; |
|
815 | - } else { |
|
816 | - /* Don't have direct write access. Prompt user with our notice */ |
|
817 | - return false; |
|
818 | - } |
|
819 | - } |
|
820 | - |
|
821 | - /** |
|
822 | - * Download the fontawesome package file. |
|
823 | - * |
|
824 | - * @since 1.1.0 |
|
825 | - * |
|
826 | - * @param mixed $version The font awesome. |
|
827 | - * @param array $option Fontawesome settings. |
|
828 | - * @return WP_ERROR|bool Error on fail and true on success. |
|
829 | - */ |
|
830 | - public function download_package( $version, $option = array() ) { |
|
831 | - $filename = 'fontawesome-free-' . $version . '-web'; |
|
832 | - $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
833 | - |
|
834 | - if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
835 | - require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
836 | - } |
|
837 | - |
|
838 | - $download_file = download_url( esc_url_raw( $url ) ); |
|
839 | - |
|
840 | - if ( is_wp_error( $download_file ) ) { |
|
841 | - return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) ); |
|
842 | - } else if ( empty( $download_file ) ) { |
|
843 | - return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) ); |
|
844 | - } |
|
845 | - |
|
846 | - $response = $this->extract_package( $download_file, $filename, true ); |
|
847 | - |
|
848 | - // Update local version. |
|
849 | - if ( is_wp_error( $response ) ) { |
|
850 | - return $response; |
|
851 | - } else if ( $response ) { |
|
852 | - if ( empty( $option ) ) { |
|
853 | - $option = get_option( 'wp-font-awesome-settings' ); |
|
854 | - } |
|
855 | - |
|
856 | - $option['local_version'] = $version; |
|
857 | - |
|
858 | - // Remove action to prevent looping. |
|
859 | - remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
860 | - |
|
861 | - update_option( 'wp-font-awesome-settings', $option ); |
|
862 | - |
|
863 | - return true; |
|
864 | - } |
|
865 | - |
|
866 | - return false; |
|
867 | - } |
|
868 | - |
|
869 | - /** |
|
870 | - * Extract the fontawesome package file. |
|
871 | - * |
|
872 | - * @since 1.1.0 |
|
873 | - * |
|
874 | - * @param string $package The package file path. |
|
875 | - * @param string $dirname Package file name. |
|
876 | - * @param bool $delete_package Delete temp file or not. |
|
877 | - * @return WP_Error|bool True on success WP_Error on fail. |
|
878 | - */ |
|
879 | - public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
880 | - global $wp_filesystem; |
|
881 | - |
|
882 | - $wp_filesystem = $this->get_wp_filesystem(); |
|
883 | - |
|
884 | - if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
885 | - return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) ); |
|
886 | - } else if ( empty( $wp_filesystem ) ) { |
|
887 | - return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) ); |
|
888 | - } |
|
889 | - |
|
890 | - $fonts_dir = $this->get_fonts_dir(); |
|
891 | - $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
892 | - |
|
893 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
894 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
895 | - } |
|
896 | - |
|
897 | - // Unzip package to working directory. |
|
898 | - $result = unzip_file( $package, $fonts_tmp_dir ); |
|
899 | - |
|
900 | - if ( is_wp_error( $result ) ) { |
|
901 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
902 | - |
|
903 | - if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
904 | - return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) ); |
|
905 | - } |
|
906 | - |
|
907 | - return $result; |
|
908 | - } |
|
909 | - |
|
910 | - if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
911 | - $wp_filesystem->delete( $fonts_dir, true ); |
|
912 | - } |
|
913 | - |
|
914 | - $extract_dir = $fonts_tmp_dir; |
|
915 | - |
|
916 | - if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
917 | - $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
918 | - } |
|
919 | - |
|
920 | - try { |
|
921 | - $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
922 | - } catch ( Exception $e ) { |
|
923 | - $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) ); |
|
924 | - } |
|
925 | - |
|
926 | - if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
927 | - $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
928 | - } |
|
929 | - |
|
930 | - // Once extracted, delete the package if required. |
|
931 | - if ( $delete_package ) { |
|
932 | - unlink( $package ); |
|
933 | - } |
|
934 | - |
|
935 | - return $return; |
|
936 | - } |
|
937 | - } |
|
938 | - |
|
939 | - /** |
|
940 | - * Run the class if found. |
|
941 | - */ |
|
942 | - WP_Font_Awesome_Settings::instance(); |
|
670 | + } |
|
671 | + } |
|
672 | + } |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Handle fontawesome add settings to download fontawesome to store locally. |
|
677 | + * |
|
678 | + * @since 1.1.1 |
|
679 | + * |
|
680 | + * @param string $option The option name. |
|
681 | + * @param mixed $value The option value. |
|
682 | + */ |
|
683 | + public function add_option_wp_font_awesome_settings( $option, $value ) { |
|
684 | + // Do nothing if WordPress is being installed. |
|
685 | + if ( wp_installing() ) { |
|
686 | + return; |
|
687 | + } |
|
688 | + |
|
689 | + if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) { |
|
690 | + $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version(); |
|
691 | + |
|
692 | + if ( ! empty( $version ) ) { |
|
693 | + $response = $this->download_package( $version, $value ); |
|
694 | + |
|
695 | + if ( is_wp_error( $response ) ) { |
|
696 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
697 | + } |
|
698 | + } |
|
699 | + } |
|
700 | + } |
|
701 | + |
|
702 | + /** |
|
703 | + * Handle fontawesome update settings to download fontawesome to store locally. |
|
704 | + * |
|
705 | + * @since 1.1.0 |
|
706 | + * |
|
707 | + * @param mixed $old_value The old option value. |
|
708 | + * @param mixed $value The new option value. |
|
709 | + */ |
|
710 | + public function update_option_wp_font_awesome_settings( $old_value, $new_value ) { |
|
711 | + // Do nothing if WordPress is being installed. |
|
712 | + if ( wp_installing() ) { |
|
713 | + return; |
|
714 | + } |
|
715 | + |
|
716 | + if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) { |
|
717 | + // Old values |
|
718 | + $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' ); |
|
719 | + $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0; |
|
720 | + |
|
721 | + // New values |
|
722 | + $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version(); |
|
723 | + |
|
724 | + if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
725 | + $response = $this->download_package( $new_version, $new_value ); |
|
726 | + |
|
727 | + if ( is_wp_error( $response ) ) { |
|
728 | + add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' ); |
|
729 | + } |
|
730 | + } |
|
731 | + } |
|
732 | + } |
|
733 | + |
|
734 | + /** |
|
735 | + * Get the fonts directory local path. |
|
736 | + * |
|
737 | + * @since 1.1.0 |
|
738 | + * |
|
739 | + * @param string Fonts directory local path. |
|
740 | + */ |
|
741 | + public function get_fonts_dir() { |
|
742 | + $upload_dir = wp_upload_dir( null, false ); |
|
743 | + |
|
744 | + return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR; |
|
745 | + } |
|
746 | + |
|
747 | + /** |
|
748 | + * Get the fonts directory local url. |
|
749 | + * |
|
750 | + * @since 1.1.0 |
|
751 | + * |
|
752 | + * @param string Fonts directory local url. |
|
753 | + */ |
|
754 | + public function get_fonts_url() { |
|
755 | + $upload_dir = wp_upload_dir( null, false ); |
|
756 | + |
|
757 | + return $upload_dir['baseurl'] . '/ayefonts/fa/'; |
|
758 | + } |
|
759 | + |
|
760 | + /** |
|
761 | + * Check whether load locally active. |
|
762 | + * |
|
763 | + * @since 1.1.0 |
|
764 | + * |
|
765 | + * @return bool True if active else false. |
|
766 | + */ |
|
767 | + public function has_local() { |
|
768 | + if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) { |
|
769 | + return true; |
|
770 | + } |
|
771 | + |
|
772 | + return false; |
|
773 | + } |
|
774 | + |
|
775 | + /** |
|
776 | + * Get the WP Filesystem access. |
|
777 | + * |
|
778 | + * @since 1.1.0 |
|
779 | + * |
|
780 | + * @return object The WP Filesystem. |
|
781 | + */ |
|
782 | + public function get_wp_filesystem() { |
|
783 | + if ( ! function_exists( 'get_filesystem_method' ) ) { |
|
784 | + require_once( ABSPATH . "/wp-admin/includes/file.php" ); |
|
785 | + } |
|
786 | + |
|
787 | + $access_type = get_filesystem_method(); |
|
788 | + |
|
789 | + if ( $access_type === 'direct' ) { |
|
790 | + /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */ |
|
791 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
792 | + |
|
793 | + /* Initialize the API */ |
|
794 | + if ( ! WP_Filesystem( $creds ) ) { |
|
795 | + /* Any problems and we exit */ |
|
796 | + return false; |
|
797 | + } |
|
798 | + |
|
799 | + global $wp_filesystem; |
|
800 | + |
|
801 | + return $wp_filesystem; |
|
802 | + /* Do our file manipulations below */ |
|
803 | + } else if ( defined( 'FTP_USER' ) ) { |
|
804 | + $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() ); |
|
805 | + |
|
806 | + /* Initialize the API */ |
|
807 | + if ( ! WP_Filesystem( $creds ) ) { |
|
808 | + /* Any problems and we exit */ |
|
809 | + return false; |
|
810 | + } |
|
811 | + |
|
812 | + global $wp_filesystem; |
|
813 | + |
|
814 | + return $wp_filesystem; |
|
815 | + } else { |
|
816 | + /* Don't have direct write access. Prompt user with our notice */ |
|
817 | + return false; |
|
818 | + } |
|
819 | + } |
|
820 | + |
|
821 | + /** |
|
822 | + * Download the fontawesome package file. |
|
823 | + * |
|
824 | + * @since 1.1.0 |
|
825 | + * |
|
826 | + * @param mixed $version The font awesome. |
|
827 | + * @param array $option Fontawesome settings. |
|
828 | + * @return WP_ERROR|bool Error on fail and true on success. |
|
829 | + */ |
|
830 | + public function download_package( $version, $option = array() ) { |
|
831 | + $filename = 'fontawesome-free-' . $version . '-web'; |
|
832 | + $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip'; |
|
833 | + |
|
834 | + if ( ! function_exists( 'wp_handle_upload' ) ) { |
|
835 | + require_once ABSPATH . 'wp-admin/includes/file.php'; |
|
836 | + } |
|
837 | + |
|
838 | + $download_file = download_url( esc_url_raw( $url ) ); |
|
839 | + |
|
840 | + if ( is_wp_error( $download_file ) ) { |
|
841 | + return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) ); |
|
842 | + } else if ( empty( $download_file ) ) { |
|
843 | + return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) ); |
|
844 | + } |
|
845 | + |
|
846 | + $response = $this->extract_package( $download_file, $filename, true ); |
|
847 | + |
|
848 | + // Update local version. |
|
849 | + if ( is_wp_error( $response ) ) { |
|
850 | + return $response; |
|
851 | + } else if ( $response ) { |
|
852 | + if ( empty( $option ) ) { |
|
853 | + $option = get_option( 'wp-font-awesome-settings' ); |
|
854 | + } |
|
855 | + |
|
856 | + $option['local_version'] = $version; |
|
857 | + |
|
858 | + // Remove action to prevent looping. |
|
859 | + remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 ); |
|
860 | + |
|
861 | + update_option( 'wp-font-awesome-settings', $option ); |
|
862 | + |
|
863 | + return true; |
|
864 | + } |
|
865 | + |
|
866 | + return false; |
|
867 | + } |
|
868 | + |
|
869 | + /** |
|
870 | + * Extract the fontawesome package file. |
|
871 | + * |
|
872 | + * @since 1.1.0 |
|
873 | + * |
|
874 | + * @param string $package The package file path. |
|
875 | + * @param string $dirname Package file name. |
|
876 | + * @param bool $delete_package Delete temp file or not. |
|
877 | + * @return WP_Error|bool True on success WP_Error on fail. |
|
878 | + */ |
|
879 | + public function extract_package( $package, $dirname = '', $delete_package = false ) { |
|
880 | + global $wp_filesystem; |
|
881 | + |
|
882 | + $wp_filesystem = $this->get_wp_filesystem(); |
|
883 | + |
|
884 | + if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) { |
|
885 | + return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) ); |
|
886 | + } else if ( empty( $wp_filesystem ) ) { |
|
887 | + return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) ); |
|
888 | + } |
|
889 | + |
|
890 | + $fonts_dir = $this->get_fonts_dir(); |
|
891 | + $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR; |
|
892 | + |
|
893 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
894 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
895 | + } |
|
896 | + |
|
897 | + // Unzip package to working directory. |
|
898 | + $result = unzip_file( $package, $fonts_tmp_dir ); |
|
899 | + |
|
900 | + if ( is_wp_error( $result ) ) { |
|
901 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
902 | + |
|
903 | + if ( 'incompatible_archive' === $result->get_error_code() ) { |
|
904 | + return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) ); |
|
905 | + } |
|
906 | + |
|
907 | + return $result; |
|
908 | + } |
|
909 | + |
|
910 | + if ( $wp_filesystem->is_dir( $fonts_dir ) ) { |
|
911 | + $wp_filesystem->delete( $fonts_dir, true ); |
|
912 | + } |
|
913 | + |
|
914 | + $extract_dir = $fonts_tmp_dir; |
|
915 | + |
|
916 | + if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) { |
|
917 | + $extract_dir .= $dirname . DIRECTORY_SEPARATOR; |
|
918 | + } |
|
919 | + |
|
920 | + try { |
|
921 | + $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true ); |
|
922 | + } catch ( Exception $e ) { |
|
923 | + $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) ); |
|
924 | + } |
|
925 | + |
|
926 | + if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) { |
|
927 | + $wp_filesystem->delete( $fonts_tmp_dir, true ); |
|
928 | + } |
|
929 | + |
|
930 | + // Once extracted, delete the package if required. |
|
931 | + if ( $delete_package ) { |
|
932 | + unlink( $package ); |
|
933 | + } |
|
934 | + |
|
935 | + return $return; |
|
936 | + } |
|
937 | + } |
|
938 | + |
|
939 | + /** |
|
940 | + * Run the class if found. |
|
941 | + */ |
|
942 | + WP_Font_Awesome_Settings::instance(); |
|
943 | 943 | } |
@@ -7,40 +7,40 @@ |
||
7 | 7 | * Bail if we are not in WP. |
8 | 8 | */ |
9 | 9 | if ( ! defined( 'ABSPATH' ) ) { |
10 | - exit; |
|
10 | + exit; |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
14 | 14 | * Set the version only if its the current newest while loading. |
15 | 15 | */ |
16 | 16 | add_action('after_setup_theme', function () { |
17 | - global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | - $this_version = "0.1.85"; |
|
19 | - if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | - $ayecode_ui_version = $this_version ; |
|
21 | - $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | - } |
|
17 | + global $ayecode_ui_version,$ayecode_ui_file_key; |
|
18 | + $this_version = "0.1.85"; |
|
19 | + if(empty($ayecode_ui_version) || version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | + $ayecode_ui_version = $this_version ; |
|
21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | + } |
|
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | 28 | add_action('after_setup_theme', function () { |
29 | - global $ayecode_ui_file_key; |
|
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | - } |
|
29 | + global $ayecode_ui_file_key; |
|
30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | + } |
|
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | 39 | if(!function_exists('aui')){ |
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
42 | - return false; |
|
43 | - } |
|
44 | - return AUI::instance(); |
|
45 | - } |
|
40 | + function aui(){ |
|
41 | + if(!class_exists("AUI",false)){ |
|
42 | + return false; |
|
43 | + } |
|
44 | + return AUI::instance(); |
|
45 | + } |
|
46 | 46 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,435 +21,435 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class AyeCode_UI_Settings |
|
28 | - * @ver 1.0.0 |
|
29 | - * @todo decide how to implement textdomain |
|
30 | - */ |
|
31 | - class AyeCode_UI_Settings { |
|
32 | - |
|
33 | - /** |
|
34 | - * Class version version. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $version = '0.1.85'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Class textdomain. |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $textdomain = 'aui'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Latest version of Bootstrap at time of publish published. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $latest = "4.5.3"; |
|
53 | - |
|
54 | - /** |
|
55 | - * Current version of select2 being used. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $select2_version = "4.0.11"; |
|
60 | - |
|
61 | - /** |
|
62 | - * The title. |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public $name = 'AyeCode UI'; |
|
67 | - |
|
68 | - /** |
|
69 | - * The relative url to the assets. |
|
70 | - * |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - public $url = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * Holds the settings values. |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - private $settings; |
|
81 | - |
|
82 | - /** |
|
83 | - * AyeCode_UI_Settings instance. |
|
84 | - * |
|
85 | - * @access private |
|
86 | - * @since 1.0.0 |
|
87 | - * @var AyeCode_UI_Settings There can be only one! |
|
88 | - */ |
|
89 | - private static $instance = null; |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Main AyeCode_UI_Settings Instance. |
|
94 | - * |
|
95 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
96 | - * |
|
97 | - * @since 1.0.0 |
|
98 | - * @static |
|
99 | - * @return AyeCode_UI_Settings - Main instance. |
|
100 | - */ |
|
101 | - public static function instance() { |
|
102 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
103 | - |
|
104 | - self::$instance = new AyeCode_UI_Settings; |
|
105 | - |
|
106 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
107 | - |
|
108 | - if ( is_admin() ) { |
|
109 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
110 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
111 | - |
|
112 | - // Maybe show example page |
|
113 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
114 | - |
|
115 | - if ( defined( 'BLOCKSTRAP_VERSION' ) ) { |
|
116 | - add_filter( 'sd_aui_colors', array( self::$instance,'sd_aui_colors' ), 10, 3 ); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
121 | - |
|
122 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
123 | - } |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class AyeCode_UI_Settings |
|
28 | + * @ver 1.0.0 |
|
29 | + * @todo decide how to implement textdomain |
|
30 | + */ |
|
31 | + class AyeCode_UI_Settings { |
|
32 | + |
|
33 | + /** |
|
34 | + * Class version version. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $version = '0.1.85'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Class textdomain. |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $textdomain = 'aui'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Latest version of Bootstrap at time of publish published. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $latest = "4.5.3"; |
|
53 | + |
|
54 | + /** |
|
55 | + * Current version of select2 being used. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $select2_version = "4.0.11"; |
|
60 | + |
|
61 | + /** |
|
62 | + * The title. |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public $name = 'AyeCode UI'; |
|
67 | + |
|
68 | + /** |
|
69 | + * The relative url to the assets. |
|
70 | + * |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + public $url = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * Holds the settings values. |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + private $settings; |
|
81 | + |
|
82 | + /** |
|
83 | + * AyeCode_UI_Settings instance. |
|
84 | + * |
|
85 | + * @access private |
|
86 | + * @since 1.0.0 |
|
87 | + * @var AyeCode_UI_Settings There can be only one! |
|
88 | + */ |
|
89 | + private static $instance = null; |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Main AyeCode_UI_Settings Instance. |
|
94 | + * |
|
95 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
96 | + * |
|
97 | + * @since 1.0.0 |
|
98 | + * @static |
|
99 | + * @return AyeCode_UI_Settings - Main instance. |
|
100 | + */ |
|
101 | + public static function instance() { |
|
102 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
103 | + |
|
104 | + self::$instance = new AyeCode_UI_Settings; |
|
105 | + |
|
106 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
107 | + |
|
108 | + if ( is_admin() ) { |
|
109 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
110 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
111 | + |
|
112 | + // Maybe show example page |
|
113 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
114 | + |
|
115 | + if ( defined( 'BLOCKSTRAP_VERSION' ) ) { |
|
116 | + add_filter( 'sd_aui_colors', array( self::$instance,'sd_aui_colors' ), 10, 3 ); |
|
117 | + } |
|
118 | + } |
|
124 | 119 | |
125 | - return self::$instance; |
|
126 | - } |
|
120 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
127 | 121 | |
128 | - /** |
|
129 | - * Add custom colors to the color selector. |
|
130 | - * |
|
131 | - * @param $theme_colors |
|
132 | - * @param $include_outlines |
|
133 | - * @param $include_branding |
|
134 | - * |
|
135 | - * @return mixed |
|
136 | - */ |
|
137 | - public function sd_aui_colors( $theme_colors, $include_outlines, $include_branding ){ |
|
122 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
123 | + } |
|
138 | 124 | |
125 | + return self::$instance; |
|
126 | + } |
|
139 | 127 | |
140 | - $setting = wp_get_global_settings(); |
|
128 | + /** |
|
129 | + * Add custom colors to the color selector. |
|
130 | + * |
|
131 | + * @param $theme_colors |
|
132 | + * @param $include_outlines |
|
133 | + * @param $include_branding |
|
134 | + * |
|
135 | + * @return mixed |
|
136 | + */ |
|
137 | + public function sd_aui_colors( $theme_colors, $include_outlines, $include_branding ){ |
|
141 | 138 | |
142 | - if(!empty($setting['color']['palette']['custom'])){ |
|
143 | - foreach($setting['color']['palette']['custom'] as $color){ |
|
144 | - $theme_colors[$color['slug']] = esc_attr($color['name']); |
|
145 | - } |
|
146 | - } |
|
147 | - |
|
148 | - return $theme_colors; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * Setup some constants. |
|
153 | - */ |
|
154 | - public function constants(){ |
|
155 | - define( 'AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be" ); |
|
156 | - define( 'AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d' ); |
|
157 | - define( 'AUI_INFO_COLOR_ORIGINAL', '#17a2b8' ); |
|
158 | - define( 'AUI_WARNING_COLOR_ORIGINAL', '#ffc107' ); |
|
159 | - define( 'AUI_DANGER_COLOR_ORIGINAL', '#dc3545' ); |
|
160 | - define( 'AUI_SUCCESS_COLOR_ORIGINAL', '#44c553' ); |
|
161 | - define( 'AUI_LIGHT_COLOR_ORIGINAL', '#f8f9fa' ); |
|
162 | - define( 'AUI_DARK_COLOR_ORIGINAL', '#343a40' ); |
|
163 | - define( 'AUI_WHITE_COLOR_ORIGINAL', '#fff' ); |
|
164 | - define( 'AUI_PURPLE_COLOR_ORIGINAL', '#ad6edd' ); |
|
165 | - define( 'AUI_SALMON_COLOR_ORIGINAL', '#ff977a' ); |
|
166 | - define( 'AUI_CYAN_COLOR_ORIGINAL', '#35bdff' ); |
|
167 | - define( 'AUI_GRAY_COLOR_ORIGINAL', '#ced4da' ); |
|
168 | - define( 'AUI_INDIGO_COLOR_ORIGINAL', '#502c6c' ); |
|
169 | - define( 'AUI_ORANGE_COLOR_ORIGINAL', '#orange' ); |
|
170 | - define( 'AUI_BLACK_COLOR_ORIGINAL', '#000' ); |
|
171 | - |
|
172 | - if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) { |
|
173 | - define( 'AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL ); |
|
174 | - } |
|
175 | - if ( ! defined( 'AUI_SECONDARY_COLOR' ) ) { |
|
176 | - define( 'AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL ); |
|
177 | - } |
|
178 | - if ( ! defined( 'AUI_INFO_COLOR' ) ) { |
|
179 | - define( 'AUI_INFO_COLOR', AUI_INFO_COLOR_ORIGINAL ); |
|
180 | - } |
|
181 | - if ( ! defined( 'AUI_WARNING_COLOR' ) ) { |
|
182 | - define( 'AUI_WARNING_COLOR', AUI_WARNING_COLOR_ORIGINAL ); |
|
183 | - } |
|
184 | - if ( ! defined( 'AUI_DANGER_COLOR' ) ) { |
|
185 | - define( 'AUI_DANGER_COLOR', AUI_DANGER_COLOR_ORIGINAL ); |
|
186 | - } |
|
187 | - if ( ! defined( 'AUI_SUCCESS_COLOR' ) ) { |
|
188 | - define( 'AUI_SUCCESS_COLOR', AUI_SUCCESS_COLOR_ORIGINAL ); |
|
189 | - } |
|
190 | - if ( ! defined( 'AUI_LIGHT_COLOR' ) ) { |
|
191 | - define( 'AUI_LIGHT_COLOR', AUI_LIGHT_COLOR_ORIGINAL ); |
|
192 | - } |
|
193 | - if ( ! defined( 'AUI_DARK_COLOR' ) ) { |
|
194 | - define( 'AUI_DARK_COLOR', AUI_DARK_COLOR_ORIGINAL ); |
|
195 | - } |
|
196 | - if ( ! defined( 'AUI_WHITE_COLOR' ) ) { |
|
197 | - define( 'AUI_WHITE_COLOR', AUI_WHITE_COLOR_ORIGINAL ); |
|
198 | - } |
|
199 | - if ( ! defined( 'AUI_PURPLE_COLOR' ) ) { |
|
200 | - define( 'AUI_PURPLE_COLOR', AUI_PURPLE_COLOR_ORIGINAL ); |
|
201 | - } |
|
202 | - if ( ! defined( 'AUI_SALMON_COLOR' ) ) { |
|
203 | - define( 'AUI_SALMON_COLOR', AUI_SALMON_COLOR_ORIGINAL ); |
|
204 | - } |
|
205 | - if ( ! defined( 'AUI_CYAN_COLOR' ) ) { |
|
206 | - define( 'AUI_CYAN_COLOR', AUI_CYAN_COLOR_ORIGINAL ); |
|
207 | - } |
|
208 | - if ( ! defined( 'AUI_GRAY_COLOR' ) ) { |
|
209 | - define( 'AUI_GRAY_COLOR', AUI_GRAY_COLOR_ORIGINAL ); |
|
210 | - } |
|
211 | - if ( ! defined( 'AUI_INDIGO_COLOR' ) ) { |
|
212 | - define( 'AUI_INDIGO_COLOR', AUI_INDIGO_COLOR_ORIGINAL ); |
|
213 | - } |
|
214 | - if ( ! defined( 'AUI_ORANGE_COLOR' ) ) { |
|
215 | - define( 'AUI_ORANGE_COLOR', AUI_ORANGE_COLOR_ORIGINAL ); |
|
216 | - } |
|
217 | - if ( ! defined( 'AUI_BLACK_COLOR' ) ) { |
|
218 | - define( 'AUI_BLACK_COLOR', AUI_BLACK_COLOR_ORIGINAL ); |
|
219 | - } |
|
220 | - |
|
221 | - } |
|
222 | - |
|
223 | - public static function get_colors( $original = false){ |
|
224 | - |
|
225 | - if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) { |
|
226 | - return array(); |
|
227 | - } |
|
228 | - if ( $original ) { |
|
229 | - return array( |
|
230 | - 'primary' => AUI_PRIMARY_COLOR_ORIGINAL, |
|
231 | - 'secondary' => AUI_SECONDARY_COLOR_ORIGINAL, |
|
232 | - 'info' => AUI_INFO_COLOR_ORIGINAL, |
|
233 | - 'warning' => AUI_WARNING_COLOR_ORIGINAL, |
|
234 | - 'danger' => AUI_DANGER_COLOR_ORIGINAL, |
|
235 | - 'success' => AUI_SUCCESS_COLOR_ORIGINAL, |
|
236 | - 'light' => AUI_LIGHT_COLOR_ORIGINAL, |
|
237 | - 'dark' => AUI_DARK_COLOR_ORIGINAL, |
|
238 | - 'white' => AUI_WHITE_COLOR_ORIGINAL, |
|
239 | - 'purple' => AUI_PURPLE_COLOR_ORIGINAL, |
|
240 | - 'salmon' => AUI_SALMON_COLOR_ORIGINAL, |
|
241 | - 'cyan' => AUI_CYAN_COLOR_ORIGINAL, |
|
242 | - 'gray' => AUI_GRAY_COLOR_ORIGINAL, |
|
243 | - 'indigo' => AUI_INDIGO_COLOR_ORIGINAL, |
|
244 | - 'orange' => AUI_ORANGE_COLOR_ORIGINAL, |
|
245 | - 'black' => AUI_BLACK_COLOR_ORIGINAL, |
|
246 | - ); |
|
247 | - } |
|
248 | - |
|
249 | - return array( |
|
250 | - 'primary' => AUI_PRIMARY_COLOR, |
|
251 | - 'secondary' => AUI_SECONDARY_COLOR, |
|
252 | - 'info' => AUI_INFO_COLOR, |
|
253 | - 'warning' => AUI_WARNING_COLOR, |
|
254 | - 'danger' => AUI_DANGER_COLOR, |
|
255 | - 'success' => AUI_SUCCESS_COLOR, |
|
256 | - 'light' => AUI_LIGHT_COLOR, |
|
257 | - 'dark' => AUI_DARK_COLOR, |
|
258 | - 'white' => AUI_WHITE_COLOR, |
|
259 | - 'purple' => AUI_PURPLE_COLOR, |
|
260 | - 'salmon' => AUI_SALMON_COLOR, |
|
261 | - 'cyan' => AUI_CYAN_COLOR, |
|
262 | - 'gray' => AUI_GRAY_COLOR, |
|
263 | - 'indigo' => AUI_INDIGO_COLOR, |
|
264 | - 'orange' => AUI_ORANGE_COLOR, |
|
265 | - 'black' => AUI_BLACK_COLOR, |
|
266 | - ); |
|
267 | - } |
|
268 | - |
|
269 | - /** |
|
270 | - * Initiate the settings and add the required action hooks. |
|
271 | - */ |
|
272 | - public function init() { |
|
273 | - |
|
274 | - // Maybe fix settings |
|
275 | - if ( ! empty( $_REQUEST['aui-fix-admin'] ) && !empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], "aui-fix-admin" ) ) { |
|
276 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
277 | - if ( ! empty( $db_settings ) ) { |
|
278 | - $db_settings['css_backend'] = 'compatibility'; |
|
279 | - $db_settings['js_backend'] = 'core-popper'; |
|
280 | - update_option( 'ayecode-ui-settings', $db_settings ); |
|
281 | - wp_safe_redirect(admin_url("options-general.php?page=ayecode-ui-settings&updated=true")); |
|
282 | - } |
|
283 | - } |
|
284 | 139 | |
285 | - $this->constants(); |
|
286 | - $this->settings = $this->get_settings(); |
|
287 | - $this->url = $this->get_url(); |
|
140 | + $setting = wp_get_global_settings(); |
|
288 | 141 | |
289 | - /** |
|
290 | - * Maybe load CSS |
|
291 | - * |
|
292 | - * We load super early in case there is a theme version that might change the colors |
|
293 | - */ |
|
294 | - if ( $this->settings['css'] ) { |
|
295 | - $priority = $this->is_bs3_compat() ? 100 : 1; |
|
296 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority ); |
|
297 | - } |
|
298 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
299 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
300 | - } |
|
301 | - |
|
302 | - // maybe load JS |
|
303 | - if ( $this->settings['js'] ) { |
|
304 | - $priority = $this->is_bs3_compat() ? 100 : 1; |
|
305 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
306 | - } |
|
307 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
308 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
309 | - } |
|
310 | - |
|
311 | - // Maybe set the HTML font size |
|
312 | - if ( $this->settings['html_font_size'] ) { |
|
313 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
314 | - } |
|
315 | - |
|
316 | - // Maybe show backend style error |
|
317 | - if( $this->settings['css_backend'] != 'compatibility' || $this->settings['js_backend'] != 'core-popper' ){ |
|
318 | - add_action( 'admin_notices', array( $this, 'show_admin_style_notice' ) ); |
|
319 | - } |
|
320 | - |
|
321 | - } |
|
322 | - |
|
323 | - /** |
|
324 | - * Show admin notice if backend scripts not loaded. |
|
325 | - */ |
|
326 | - public function show_admin_style_notice(){ |
|
327 | - $fix_url = admin_url("options-general.php?page=ayecode-ui-settings&aui-fix-admin=true&nonce=".wp_create_nonce('aui-fix-admin')); |
|
328 | - $button = '<a href="'.esc_url($fix_url).'" class="button-primary">Fix Now</a>'; |
|
329 | - $message = __( '<b>Style Issue:</b> AyeCode UI is disable or set wrong.')." " .$button; |
|
330 | - echo '<div class="notice notice-error aui-settings-error-notice"><p>'.$message.'</p></div>'; |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Check if we should load the admin scripts or not. |
|
335 | - * |
|
336 | - * @return bool |
|
337 | - */ |
|
338 | - public function load_admin_scripts(){ |
|
339 | - $result = true; |
|
340 | - |
|
341 | - // check if specifically disabled |
|
342 | - if(!empty($this->settings['disable_admin'])){ |
|
343 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
344 | - foreach($url_parts as $part){ |
|
345 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
346 | - return false; // return early, no point checking further |
|
347 | - } |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - return $result; |
|
352 | - } |
|
353 | - |
|
354 | - /** |
|
355 | - * Add a html font size to the footer. |
|
356 | - */ |
|
357 | - public function html_font_size(){ |
|
358 | - $this->settings = $this->get_settings(); |
|
359 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Check if the current admin screen should load scripts. |
|
364 | - * |
|
365 | - * @return bool |
|
366 | - */ |
|
367 | - public function is_aui_screen(){ |
|
142 | + if(!empty($setting['color']['palette']['custom'])){ |
|
143 | + foreach($setting['color']['palette']['custom'] as $color){ |
|
144 | + $theme_colors[$color['slug']] = esc_attr($color['name']); |
|
145 | + } |
|
146 | + } |
|
147 | + |
|
148 | + return $theme_colors; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * Setup some constants. |
|
153 | + */ |
|
154 | + public function constants(){ |
|
155 | + define( 'AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be" ); |
|
156 | + define( 'AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d' ); |
|
157 | + define( 'AUI_INFO_COLOR_ORIGINAL', '#17a2b8' ); |
|
158 | + define( 'AUI_WARNING_COLOR_ORIGINAL', '#ffc107' ); |
|
159 | + define( 'AUI_DANGER_COLOR_ORIGINAL', '#dc3545' ); |
|
160 | + define( 'AUI_SUCCESS_COLOR_ORIGINAL', '#44c553' ); |
|
161 | + define( 'AUI_LIGHT_COLOR_ORIGINAL', '#f8f9fa' ); |
|
162 | + define( 'AUI_DARK_COLOR_ORIGINAL', '#343a40' ); |
|
163 | + define( 'AUI_WHITE_COLOR_ORIGINAL', '#fff' ); |
|
164 | + define( 'AUI_PURPLE_COLOR_ORIGINAL', '#ad6edd' ); |
|
165 | + define( 'AUI_SALMON_COLOR_ORIGINAL', '#ff977a' ); |
|
166 | + define( 'AUI_CYAN_COLOR_ORIGINAL', '#35bdff' ); |
|
167 | + define( 'AUI_GRAY_COLOR_ORIGINAL', '#ced4da' ); |
|
168 | + define( 'AUI_INDIGO_COLOR_ORIGINAL', '#502c6c' ); |
|
169 | + define( 'AUI_ORANGE_COLOR_ORIGINAL', '#orange' ); |
|
170 | + define( 'AUI_BLACK_COLOR_ORIGINAL', '#000' ); |
|
171 | + |
|
172 | + if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) { |
|
173 | + define( 'AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL ); |
|
174 | + } |
|
175 | + if ( ! defined( 'AUI_SECONDARY_COLOR' ) ) { |
|
176 | + define( 'AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL ); |
|
177 | + } |
|
178 | + if ( ! defined( 'AUI_INFO_COLOR' ) ) { |
|
179 | + define( 'AUI_INFO_COLOR', AUI_INFO_COLOR_ORIGINAL ); |
|
180 | + } |
|
181 | + if ( ! defined( 'AUI_WARNING_COLOR' ) ) { |
|
182 | + define( 'AUI_WARNING_COLOR', AUI_WARNING_COLOR_ORIGINAL ); |
|
183 | + } |
|
184 | + if ( ! defined( 'AUI_DANGER_COLOR' ) ) { |
|
185 | + define( 'AUI_DANGER_COLOR', AUI_DANGER_COLOR_ORIGINAL ); |
|
186 | + } |
|
187 | + if ( ! defined( 'AUI_SUCCESS_COLOR' ) ) { |
|
188 | + define( 'AUI_SUCCESS_COLOR', AUI_SUCCESS_COLOR_ORIGINAL ); |
|
189 | + } |
|
190 | + if ( ! defined( 'AUI_LIGHT_COLOR' ) ) { |
|
191 | + define( 'AUI_LIGHT_COLOR', AUI_LIGHT_COLOR_ORIGINAL ); |
|
192 | + } |
|
193 | + if ( ! defined( 'AUI_DARK_COLOR' ) ) { |
|
194 | + define( 'AUI_DARK_COLOR', AUI_DARK_COLOR_ORIGINAL ); |
|
195 | + } |
|
196 | + if ( ! defined( 'AUI_WHITE_COLOR' ) ) { |
|
197 | + define( 'AUI_WHITE_COLOR', AUI_WHITE_COLOR_ORIGINAL ); |
|
198 | + } |
|
199 | + if ( ! defined( 'AUI_PURPLE_COLOR' ) ) { |
|
200 | + define( 'AUI_PURPLE_COLOR', AUI_PURPLE_COLOR_ORIGINAL ); |
|
201 | + } |
|
202 | + if ( ! defined( 'AUI_SALMON_COLOR' ) ) { |
|
203 | + define( 'AUI_SALMON_COLOR', AUI_SALMON_COLOR_ORIGINAL ); |
|
204 | + } |
|
205 | + if ( ! defined( 'AUI_CYAN_COLOR' ) ) { |
|
206 | + define( 'AUI_CYAN_COLOR', AUI_CYAN_COLOR_ORIGINAL ); |
|
207 | + } |
|
208 | + if ( ! defined( 'AUI_GRAY_COLOR' ) ) { |
|
209 | + define( 'AUI_GRAY_COLOR', AUI_GRAY_COLOR_ORIGINAL ); |
|
210 | + } |
|
211 | + if ( ! defined( 'AUI_INDIGO_COLOR' ) ) { |
|
212 | + define( 'AUI_INDIGO_COLOR', AUI_INDIGO_COLOR_ORIGINAL ); |
|
213 | + } |
|
214 | + if ( ! defined( 'AUI_ORANGE_COLOR' ) ) { |
|
215 | + define( 'AUI_ORANGE_COLOR', AUI_ORANGE_COLOR_ORIGINAL ); |
|
216 | + } |
|
217 | + if ( ! defined( 'AUI_BLACK_COLOR' ) ) { |
|
218 | + define( 'AUI_BLACK_COLOR', AUI_BLACK_COLOR_ORIGINAL ); |
|
219 | + } |
|
220 | + |
|
221 | + } |
|
222 | + |
|
223 | + public static function get_colors( $original = false){ |
|
224 | + |
|
225 | + if ( ! defined( 'AUI_PRIMARY_COLOR' ) ) { |
|
226 | + return array(); |
|
227 | + } |
|
228 | + if ( $original ) { |
|
229 | + return array( |
|
230 | + 'primary' => AUI_PRIMARY_COLOR_ORIGINAL, |
|
231 | + 'secondary' => AUI_SECONDARY_COLOR_ORIGINAL, |
|
232 | + 'info' => AUI_INFO_COLOR_ORIGINAL, |
|
233 | + 'warning' => AUI_WARNING_COLOR_ORIGINAL, |
|
234 | + 'danger' => AUI_DANGER_COLOR_ORIGINAL, |
|
235 | + 'success' => AUI_SUCCESS_COLOR_ORIGINAL, |
|
236 | + 'light' => AUI_LIGHT_COLOR_ORIGINAL, |
|
237 | + 'dark' => AUI_DARK_COLOR_ORIGINAL, |
|
238 | + 'white' => AUI_WHITE_COLOR_ORIGINAL, |
|
239 | + 'purple' => AUI_PURPLE_COLOR_ORIGINAL, |
|
240 | + 'salmon' => AUI_SALMON_COLOR_ORIGINAL, |
|
241 | + 'cyan' => AUI_CYAN_COLOR_ORIGINAL, |
|
242 | + 'gray' => AUI_GRAY_COLOR_ORIGINAL, |
|
243 | + 'indigo' => AUI_INDIGO_COLOR_ORIGINAL, |
|
244 | + 'orange' => AUI_ORANGE_COLOR_ORIGINAL, |
|
245 | + 'black' => AUI_BLACK_COLOR_ORIGINAL, |
|
246 | + ); |
|
247 | + } |
|
248 | + |
|
249 | + return array( |
|
250 | + 'primary' => AUI_PRIMARY_COLOR, |
|
251 | + 'secondary' => AUI_SECONDARY_COLOR, |
|
252 | + 'info' => AUI_INFO_COLOR, |
|
253 | + 'warning' => AUI_WARNING_COLOR, |
|
254 | + 'danger' => AUI_DANGER_COLOR, |
|
255 | + 'success' => AUI_SUCCESS_COLOR, |
|
256 | + 'light' => AUI_LIGHT_COLOR, |
|
257 | + 'dark' => AUI_DARK_COLOR, |
|
258 | + 'white' => AUI_WHITE_COLOR, |
|
259 | + 'purple' => AUI_PURPLE_COLOR, |
|
260 | + 'salmon' => AUI_SALMON_COLOR, |
|
261 | + 'cyan' => AUI_CYAN_COLOR, |
|
262 | + 'gray' => AUI_GRAY_COLOR, |
|
263 | + 'indigo' => AUI_INDIGO_COLOR, |
|
264 | + 'orange' => AUI_ORANGE_COLOR, |
|
265 | + 'black' => AUI_BLACK_COLOR, |
|
266 | + ); |
|
267 | + } |
|
268 | + |
|
269 | + /** |
|
270 | + * Initiate the settings and add the required action hooks. |
|
271 | + */ |
|
272 | + public function init() { |
|
273 | + |
|
274 | + // Maybe fix settings |
|
275 | + if ( ! empty( $_REQUEST['aui-fix-admin'] ) && !empty($_REQUEST['nonce']) && wp_verify_nonce( $_REQUEST['nonce'], "aui-fix-admin" ) ) { |
|
276 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
277 | + if ( ! empty( $db_settings ) ) { |
|
278 | + $db_settings['css_backend'] = 'compatibility'; |
|
279 | + $db_settings['js_backend'] = 'core-popper'; |
|
280 | + update_option( 'ayecode-ui-settings', $db_settings ); |
|
281 | + wp_safe_redirect(admin_url("options-general.php?page=ayecode-ui-settings&updated=true")); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + $this->constants(); |
|
286 | + $this->settings = $this->get_settings(); |
|
287 | + $this->url = $this->get_url(); |
|
288 | + |
|
289 | + /** |
|
290 | + * Maybe load CSS |
|
291 | + * |
|
292 | + * We load super early in case there is a theme version that might change the colors |
|
293 | + */ |
|
294 | + if ( $this->settings['css'] ) { |
|
295 | + $priority = $this->is_bs3_compat() ? 100 : 1; |
|
296 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), $priority ); |
|
297 | + } |
|
298 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
299 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
300 | + } |
|
301 | + |
|
302 | + // maybe load JS |
|
303 | + if ( $this->settings['js'] ) { |
|
304 | + $priority = $this->is_bs3_compat() ? 100 : 1; |
|
305 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority ); |
|
306 | + } |
|
307 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
308 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
309 | + } |
|
310 | + |
|
311 | + // Maybe set the HTML font size |
|
312 | + if ( $this->settings['html_font_size'] ) { |
|
313 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
314 | + } |
|
315 | + |
|
316 | + // Maybe show backend style error |
|
317 | + if( $this->settings['css_backend'] != 'compatibility' || $this->settings['js_backend'] != 'core-popper' ){ |
|
318 | + add_action( 'admin_notices', array( $this, 'show_admin_style_notice' ) ); |
|
319 | + } |
|
320 | + |
|
321 | + } |
|
322 | + |
|
323 | + /** |
|
324 | + * Show admin notice if backend scripts not loaded. |
|
325 | + */ |
|
326 | + public function show_admin_style_notice(){ |
|
327 | + $fix_url = admin_url("options-general.php?page=ayecode-ui-settings&aui-fix-admin=true&nonce=".wp_create_nonce('aui-fix-admin')); |
|
328 | + $button = '<a href="'.esc_url($fix_url).'" class="button-primary">Fix Now</a>'; |
|
329 | + $message = __( '<b>Style Issue:</b> AyeCode UI is disable or set wrong.')." " .$button; |
|
330 | + echo '<div class="notice notice-error aui-settings-error-notice"><p>'.$message.'</p></div>'; |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Check if we should load the admin scripts or not. |
|
335 | + * |
|
336 | + * @return bool |
|
337 | + */ |
|
338 | + public function load_admin_scripts(){ |
|
339 | + $result = true; |
|
340 | + |
|
341 | + // check if specifically disabled |
|
342 | + if(!empty($this->settings['disable_admin'])){ |
|
343 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
344 | + foreach($url_parts as $part){ |
|
345 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
346 | + return false; // return early, no point checking further |
|
347 | + } |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + return $result; |
|
352 | + } |
|
353 | + |
|
354 | + /** |
|
355 | + * Add a html font size to the footer. |
|
356 | + */ |
|
357 | + public function html_font_size(){ |
|
358 | + $this->settings = $this->get_settings(); |
|
359 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Check if the current admin screen should load scripts. |
|
364 | + * |
|
365 | + * @return bool |
|
366 | + */ |
|
367 | + public function is_aui_screen(){ |
|
368 | 368 | // echo '###';exit; |
369 | - $load = false; |
|
370 | - // check if we should load or not |
|
371 | - if ( is_admin() ) { |
|
372 | - // Only enable on set pages |
|
373 | - $aui_screens = array( |
|
374 | - 'page', |
|
375 | - 'post', |
|
376 | - 'settings_page_ayecode-ui-settings', |
|
377 | - 'appearance_page_gutenberg-widgets', |
|
378 | - 'widgets', |
|
379 | - 'ayecode-ui-settings', |
|
380 | - 'site-editor' |
|
381 | - ); |
|
382 | - $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
383 | - |
|
384 | - $screen = get_current_screen(); |
|
369 | + $load = false; |
|
370 | + // check if we should load or not |
|
371 | + if ( is_admin() ) { |
|
372 | + // Only enable on set pages |
|
373 | + $aui_screens = array( |
|
374 | + 'page', |
|
375 | + 'post', |
|
376 | + 'settings_page_ayecode-ui-settings', |
|
377 | + 'appearance_page_gutenberg-widgets', |
|
378 | + 'widgets', |
|
379 | + 'ayecode-ui-settings', |
|
380 | + 'site-editor' |
|
381 | + ); |
|
382 | + $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens ); |
|
383 | + |
|
384 | + $screen = get_current_screen(); |
|
385 | 385 | |
386 | 386 | // echo '###'.$screen->id; |
387 | 387 | |
388 | - // check if we are on a AUI screen |
|
389 | - if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
390 | - $load = true; |
|
391 | - } |
|
388 | + // check if we are on a AUI screen |
|
389 | + if ( $screen && in_array( $screen->id, $screen_ids ) ) { |
|
390 | + $load = true; |
|
391 | + } |
|
392 | 392 | |
393 | - //load for widget previews in WP 5.8 |
|
394 | - if( !empty($_REQUEST['legacy-widget-preview'])){ |
|
395 | - $load = true; |
|
396 | - } |
|
397 | - } |
|
393 | + //load for widget previews in WP 5.8 |
|
394 | + if( !empty($_REQUEST['legacy-widget-preview'])){ |
|
395 | + $load = true; |
|
396 | + } |
|
397 | + } |
|
398 | 398 | |
399 | - return apply_filters( 'aui_load_on_admin' , $load ); |
|
400 | - } |
|
399 | + return apply_filters( 'aui_load_on_admin' , $load ); |
|
400 | + } |
|
401 | 401 | |
402 | - /** |
|
403 | - * Check if the current theme is a block theme. |
|
404 | - * |
|
405 | - * @return bool |
|
406 | - */ |
|
407 | - public static function is_block_theme() { |
|
408 | - if ( function_exists( 'wp_is_block_theme' && wp_is_block_theme() ) ) { |
|
409 | - return true; |
|
410 | - } |
|
402 | + /** |
|
403 | + * Check if the current theme is a block theme. |
|
404 | + * |
|
405 | + * @return bool |
|
406 | + */ |
|
407 | + public static function is_block_theme() { |
|
408 | + if ( function_exists( 'wp_is_block_theme' && wp_is_block_theme() ) ) { |
|
409 | + return true; |
|
410 | + } |
|
411 | 411 | |
412 | - return false; |
|
413 | - } |
|
412 | + return false; |
|
413 | + } |
|
414 | 414 | |
415 | - /** |
|
416 | - * Adds the styles. |
|
417 | - */ |
|
418 | - public function enqueue_style() { |
|
415 | + /** |
|
416 | + * Adds the styles. |
|
417 | + */ |
|
418 | + public function enqueue_style() { |
|
419 | 419 | |
420 | 420 | |
421 | - if( is_admin() && !$this->is_aui_screen()){ |
|
422 | - // don't add wp-admin scripts if not requested to |
|
423 | - }else{ |
|
424 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
421 | + if( is_admin() && !$this->is_aui_screen()){ |
|
422 | + // don't add wp-admin scripts if not requested to |
|
423 | + }else{ |
|
424 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
425 | 425 | |
426 | - $rtl = is_rtl() ? '-rtl' : ''; |
|
426 | + $rtl = is_rtl() ? '-rtl' : ''; |
|
427 | 427 | |
428 | - if($this->settings[$css_setting]){ |
|
429 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
430 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
428 | + if($this->settings[$css_setting]){ |
|
429 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
430 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css'; |
|
431 | 431 | |
432 | 432 | |
433 | 433 | |
434 | - wp_register_style( 'ayecode-ui', $url, array(), $this->version ); |
|
435 | - wp_enqueue_style( 'ayecode-ui' ); |
|
434 | + wp_register_style( 'ayecode-ui', $url, array(), $this->version ); |
|
435 | + wp_enqueue_style( 'ayecode-ui' ); |
|
436 | 436 | |
437 | - $current_screen = function_exists('get_current_screen' ) ? get_current_screen() : ''; |
|
437 | + $current_screen = function_exists('get_current_screen' ) ? get_current_screen() : ''; |
|
438 | 438 | |
439 | 439 | // if ( is_admin() && !empty($_REQUEST['postType']) ) { |
440 | - if ( is_admin() && ( !empty($_REQUEST['postType']) || $current_screen->is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) { |
|
441 | - $url = $this->url.'assets/css/ayecode-ui-fse.css'; |
|
442 | - wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version ); |
|
443 | - wp_enqueue_style( 'ayecode-ui-fse' ); |
|
444 | - } |
|
440 | + if ( is_admin() && ( !empty($_REQUEST['postType']) || $current_screen->is_block_editor() ) && ( defined( 'BLOCKSTRAP_VERSION' ) || defined( 'AUI_FSE' ) ) ) { |
|
441 | + $url = $this->url.'assets/css/ayecode-ui-fse.css'; |
|
442 | + wp_register_style( 'ayecode-ui-fse', $url, array(), $this->version ); |
|
443 | + wp_enqueue_style( 'ayecode-ui-fse' ); |
|
444 | + } |
|
445 | 445 | |
446 | 446 | |
447 | - // flatpickr |
|
448 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->version ); |
|
447 | + // flatpickr |
|
448 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->version ); |
|
449 | 449 | |
450 | - // fix some wp-admin issues |
|
451 | - if(is_admin()){ |
|
452 | - $custom_css = " |
|
450 | + // fix some wp-admin issues |
|
451 | + if(is_admin()){ |
|
452 | + $custom_css = " |
|
453 | 453 | body{ |
454 | 454 | background-color: #f1f1f1; |
455 | 455 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -495,35 +495,35 @@ discard block |
||
495 | 495 | } |
496 | 496 | "; |
497 | 497 | |
498 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
499 | - $custom_css .= " |
|
498 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
499 | + $custom_css .= " |
|
500 | 500 | .edit-post-sidebar input[type=color].components-text-control__input{ |
501 | 501 | padding: 0; |
502 | 502 | } |
503 | 503 | "; |
504 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
505 | - } |
|
504 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
505 | + } |
|
506 | 506 | |
507 | - // custom changes |
|
508 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
507 | + // custom changes |
|
508 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
509 | 509 | |
510 | - } |
|
511 | - } |
|
510 | + } |
|
511 | + } |
|
512 | 512 | |
513 | 513 | |
514 | - } |
|
514 | + } |
|
515 | 515 | |
516 | - /** |
|
517 | - * Get inline script used if bootstrap enqueued |
|
518 | - * |
|
519 | - * If this remains small then its best to use this than to add another JS file. |
|
520 | - */ |
|
521 | - public function inline_script() { |
|
522 | - // Flatpickr calendar locale |
|
523 | - $flatpickr_locale = self::flatpickr_locale(); |
|
516 | + /** |
|
517 | + * Get inline script used if bootstrap enqueued |
|
518 | + * |
|
519 | + * If this remains small then its best to use this than to add another JS file. |
|
520 | + */ |
|
521 | + public function inline_script() { |
|
522 | + // Flatpickr calendar locale |
|
523 | + $flatpickr_locale = self::flatpickr_locale(); |
|
524 | 524 | |
525 | - ob_start(); |
|
526 | - ?> |
|
525 | + ob_start(); |
|
526 | + ?> |
|
527 | 527 | <script> |
528 | 528 | /** |
529 | 529 | * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ). |
@@ -1460,8 +1460,8 @@ discard block |
||
1460 | 1460 | aui_set_data_scroll(); |
1461 | 1461 | |
1462 | 1462 | <?php |
1463 | - // FSE tweaks. |
|
1464 | - if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?> |
|
1463 | + // FSE tweaks. |
|
1464 | + if(!empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'){ ?> |
|
1465 | 1465 | function aui_fse_set_data_scroll() { |
1466 | 1466 | console.log('init scroll'); |
1467 | 1467 | let Iframe = document.getElementsByClassName("edit-site-visual-editor__editor-canvas"); |
@@ -1494,29 +1494,29 @@ discard block |
||
1494 | 1494 | |
1495 | 1495 | </script> |
1496 | 1496 | <?php |
1497 | - $output = ob_get_clean(); |
|
1497 | + $output = ob_get_clean(); |
|
1498 | 1498 | |
1499 | 1499 | |
1500 | 1500 | |
1501 | - /* |
|
1501 | + /* |
|
1502 | 1502 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1503 | 1503 | */ |
1504 | - return str_replace( array( |
|
1505 | - '<script>', |
|
1506 | - '</script>' |
|
1507 | - ), '', self::minify_js($output) ); |
|
1508 | - } |
|
1509 | - |
|
1510 | - |
|
1511 | - /** |
|
1512 | - * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1513 | - * |
|
1514 | - * @TODO we may need this when other conflicts arrise. |
|
1515 | - * @return mixed |
|
1516 | - */ |
|
1517 | - public static function bs3_compat_js() { |
|
1518 | - ob_start(); |
|
1519 | - ?> |
|
1504 | + return str_replace( array( |
|
1505 | + '<script>', |
|
1506 | + '</script>' |
|
1507 | + ), '', self::minify_js($output) ); |
|
1508 | + } |
|
1509 | + |
|
1510 | + |
|
1511 | + /** |
|
1512 | + * JS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1513 | + * |
|
1514 | + * @TODO we may need this when other conflicts arrise. |
|
1515 | + * @return mixed |
|
1516 | + */ |
|
1517 | + public static function bs3_compat_js() { |
|
1518 | + ob_start(); |
|
1519 | + ?> |
|
1520 | 1520 | <script> |
1521 | 1521 | <?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?> |
1522 | 1522 | /* With Avada builder */ |
@@ -1524,20 +1524,20 @@ discard block |
||
1524 | 1524 | <?php } ?> |
1525 | 1525 | </script> |
1526 | 1526 | <?php |
1527 | - return str_replace( array( |
|
1528 | - '<script>', |
|
1529 | - '</script>' |
|
1530 | - ), '', ob_get_clean()); |
|
1531 | - } |
|
1532 | - |
|
1533 | - /** |
|
1534 | - * Get inline script used if bootstrap file browser enqueued. |
|
1535 | - * |
|
1536 | - * If this remains small then its best to use this than to add another JS file. |
|
1537 | - */ |
|
1538 | - public function inline_script_file_browser(){ |
|
1539 | - ob_start(); |
|
1540 | - ?> |
|
1527 | + return str_replace( array( |
|
1528 | + '<script>', |
|
1529 | + '</script>' |
|
1530 | + ), '', ob_get_clean()); |
|
1531 | + } |
|
1532 | + |
|
1533 | + /** |
|
1534 | + * Get inline script used if bootstrap file browser enqueued. |
|
1535 | + * |
|
1536 | + * If this remains small then its best to use this than to add another JS file. |
|
1537 | + */ |
|
1538 | + public function inline_script_file_browser(){ |
|
1539 | + ob_start(); |
|
1540 | + ?> |
|
1541 | 1541 | <script> |
1542 | 1542 | // run on doc ready |
1543 | 1543 | jQuery(document).ready(function () { |
@@ -1545,227 +1545,227 @@ discard block |
||
1545 | 1545 | }); |
1546 | 1546 | </script> |
1547 | 1547 | <?php |
1548 | - $output = ob_get_clean(); |
|
1548 | + $output = ob_get_clean(); |
|
1549 | 1549 | |
1550 | - /* |
|
1550 | + /* |
|
1551 | 1551 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1552 | 1552 | */ |
1553 | - return str_replace( array( |
|
1554 | - '<script>', |
|
1555 | - '</script>' |
|
1556 | - ), '', $output ); |
|
1557 | - } |
|
1558 | - |
|
1559 | - /** |
|
1560 | - * Adds the Font Awesome JS. |
|
1561 | - */ |
|
1562 | - public function enqueue_scripts() { |
|
1563 | - |
|
1564 | - if( is_admin() && !$this->is_aui_screen()){ |
|
1565 | - // don't add wp-admin scripts if not requested to |
|
1566 | - }else { |
|
1567 | - |
|
1568 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
1569 | - |
|
1570 | - // select2 |
|
1571 | - wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
1572 | - |
|
1573 | - // flatpickr |
|
1574 | - wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version ); |
|
1575 | - |
|
1576 | - // flatpickr |
|
1577 | - wp_register_script( 'iconpicker', $this->url . 'assets/js/fa-iconpicker.min.js', array(), $this->version ); |
|
1578 | - |
|
1579 | - // Bootstrap file browser |
|
1580 | - wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
1581 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
1582 | - |
|
1583 | - $load_inline = false; |
|
1584 | - |
|
1585 | - if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
1586 | - // Bootstrap bundle |
|
1587 | - $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
1588 | - wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
1589 | - 'select2', |
|
1590 | - 'jquery' |
|
1591 | - ), $this->version, $this->is_bs3_compat() ); |
|
1592 | - // if in admin then add to footer for compatibility. |
|
1593 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
1594 | - $script = $this->inline_script(); |
|
1595 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
1596 | - } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
1597 | - $url = $this->url . 'assets/js/popper.min.js'; |
|
1598 | - wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version ); |
|
1599 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
1600 | - $load_inline = true; |
|
1601 | - } else { |
|
1602 | - $load_inline = true; |
|
1603 | - } |
|
1604 | - |
|
1605 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
1606 | - if ( $load_inline ) { |
|
1607 | - wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
1608 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
1609 | - $script = $this->inline_script(); |
|
1610 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
1611 | - } |
|
1612 | - } |
|
1613 | - |
|
1614 | - } |
|
1615 | - |
|
1616 | - /** |
|
1617 | - * Enqueue flatpickr if called. |
|
1618 | - */ |
|
1619 | - public function enqueue_flatpickr(){ |
|
1620 | - wp_enqueue_style( 'flatpickr' ); |
|
1621 | - wp_enqueue_script( 'flatpickr' ); |
|
1622 | - } |
|
1623 | - |
|
1624 | - /** |
|
1625 | - * Enqueue iconpicker if called. |
|
1626 | - */ |
|
1627 | - public function enqueue_iconpicker(){ |
|
1628 | - wp_enqueue_style( 'iconpicker' ); |
|
1629 | - wp_enqueue_script( 'iconpicker' ); |
|
1630 | - } |
|
1631 | - |
|
1632 | - /** |
|
1633 | - * Get the url path to the current folder. |
|
1634 | - * |
|
1635 | - * @return string |
|
1636 | - */ |
|
1637 | - public function get_url() { |
|
1638 | - $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
1639 | - $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
1640 | - |
|
1641 | - // Replace http:// to https://. |
|
1642 | - if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
1643 | - $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
1644 | - } |
|
1645 | - |
|
1646 | - // Check if we are inside a plugin |
|
1647 | - $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1648 | - $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
1649 | - |
|
1650 | - return trailingslashit( $url ); |
|
1651 | - } |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * Get the url path to the current folder. |
|
1655 | - * |
|
1656 | - * @return string |
|
1657 | - */ |
|
1658 | - public function get_url_old() { |
|
1659 | - |
|
1660 | - $url = ''; |
|
1661 | - // check if we are inside a plugin |
|
1662 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1663 | - |
|
1664 | - // add check in-case user has changed wp-content dir name. |
|
1665 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
1666 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
1667 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
1668 | - |
|
1669 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1670 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
1671 | - } |
|
1672 | - |
|
1673 | - return $url; |
|
1674 | - } |
|
1675 | - |
|
1676 | - /** |
|
1677 | - * Register the database settings with WordPress. |
|
1678 | - */ |
|
1679 | - public function register_settings() { |
|
1680 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
1681 | - } |
|
1682 | - |
|
1683 | - /** |
|
1684 | - * Add the WordPress settings menu item. |
|
1685 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
1686 | - */ |
|
1687 | - public function menu_item() { |
|
1688 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
1689 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
1690 | - $this, |
|
1691 | - 'settings_page' |
|
1692 | - ) ); |
|
1693 | - } |
|
1694 | - |
|
1695 | - /** |
|
1696 | - * Get a list of themes and their default JS settings. |
|
1697 | - * |
|
1698 | - * @return array |
|
1699 | - */ |
|
1700 | - public function theme_js_settings(){ |
|
1701 | - return array( |
|
1702 | - 'ayetheme' => 'popper', |
|
1703 | - 'listimia' => 'required', |
|
1704 | - 'listimia_backend' => 'core-popper', |
|
1705 | - //'avada' => 'required', // removed as we now add compatibility |
|
1706 | - ); |
|
1707 | - } |
|
1708 | - |
|
1709 | - /** |
|
1710 | - * Get the current Font Awesome output settings. |
|
1711 | - * |
|
1712 | - * @return array The array of settings. |
|
1713 | - */ |
|
1714 | - public function get_settings() { |
|
1715 | - |
|
1716 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
1717 | - $js_default = 'core-popper'; |
|
1718 | - $js_default_backend = $js_default; |
|
1719 | - |
|
1720 | - // maybe set defaults (if no settings set) |
|
1721 | - if(empty($db_settings)){ |
|
1722 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
1723 | - $theme_js_settings = self::theme_js_settings(); |
|
1724 | - if(isset($theme_js_settings[$active_theme])){ |
|
1725 | - $js_default = $theme_js_settings[$active_theme]; |
|
1726 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1727 | - } |
|
1728 | - } |
|
1553 | + return str_replace( array( |
|
1554 | + '<script>', |
|
1555 | + '</script>' |
|
1556 | + ), '', $output ); |
|
1557 | + } |
|
1558 | + |
|
1559 | + /** |
|
1560 | + * Adds the Font Awesome JS. |
|
1561 | + */ |
|
1562 | + public function enqueue_scripts() { |
|
1563 | + |
|
1564 | + if( is_admin() && !$this->is_aui_screen()){ |
|
1565 | + // don't add wp-admin scripts if not requested to |
|
1566 | + }else { |
|
1567 | + |
|
1568 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
1569 | + |
|
1570 | + // select2 |
|
1571 | + wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version ); |
|
1572 | + |
|
1573 | + // flatpickr |
|
1574 | + wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->version ); |
|
1575 | + |
|
1576 | + // flatpickr |
|
1577 | + wp_register_script( 'iconpicker', $this->url . 'assets/js/fa-iconpicker.min.js', array(), $this->version ); |
|
1578 | + |
|
1579 | + // Bootstrap file browser |
|
1580 | + wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version ); |
|
1581 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
1582 | + |
|
1583 | + $load_inline = false; |
|
1584 | + |
|
1585 | + if ( $this->settings[ $js_setting ] == 'core-popper' ) { |
|
1586 | + // Bootstrap bundle |
|
1587 | + $url = $this->url . 'assets/js/bootstrap.bundle.min.js'; |
|
1588 | + wp_register_script( 'bootstrap-js-bundle', $url, array( |
|
1589 | + 'select2', |
|
1590 | + 'jquery' |
|
1591 | + ), $this->version, $this->is_bs3_compat() ); |
|
1592 | + // if in admin then add to footer for compatibility. |
|
1593 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' ); |
|
1594 | + $script = $this->inline_script(); |
|
1595 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
1596 | + } elseif ( $this->settings[ $js_setting ] == 'popper' ) { |
|
1597 | + $url = $this->url . 'assets/js/popper.min.js'; |
|
1598 | + wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->version ); |
|
1599 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
1600 | + $load_inline = true; |
|
1601 | + } else { |
|
1602 | + $load_inline = true; |
|
1603 | + } |
|
1729 | 1604 | |
1730 | - /** |
|
1731 | - * Filter the default settings. |
|
1732 | - */ |
|
1733 | - $defaults = apply_filters( 'ayecode-ui-default-settings', array( |
|
1734 | - 'css' => 'compatibility', // core, compatibility |
|
1735 | - 'js' => $js_default, // js to load, core-popper, popper |
|
1736 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
1737 | - 'css_backend' => 'compatibility', // core, compatibility |
|
1738 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1739 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1740 | - ), $db_settings ); |
|
1741 | - |
|
1742 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
1743 | - |
|
1744 | - /** |
|
1745 | - * Filter the Bootstrap settings. |
|
1746 | - * |
|
1747 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1748 | - */ |
|
1749 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1750 | - } |
|
1751 | - |
|
1752 | - |
|
1753 | - /** |
|
1754 | - * The settings page html output. |
|
1755 | - */ |
|
1756 | - public function settings_page() { |
|
1757 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1758 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1759 | - } |
|
1760 | - ?> |
|
1605 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
1606 | + if ( $load_inline ) { |
|
1607 | + wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) ); |
|
1608 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
1609 | + $script = $this->inline_script(); |
|
1610 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
1611 | + } |
|
1612 | + } |
|
1613 | + |
|
1614 | + } |
|
1615 | + |
|
1616 | + /** |
|
1617 | + * Enqueue flatpickr if called. |
|
1618 | + */ |
|
1619 | + public function enqueue_flatpickr(){ |
|
1620 | + wp_enqueue_style( 'flatpickr' ); |
|
1621 | + wp_enqueue_script( 'flatpickr' ); |
|
1622 | + } |
|
1623 | + |
|
1624 | + /** |
|
1625 | + * Enqueue iconpicker if called. |
|
1626 | + */ |
|
1627 | + public function enqueue_iconpicker(){ |
|
1628 | + wp_enqueue_style( 'iconpicker' ); |
|
1629 | + wp_enqueue_script( 'iconpicker' ); |
|
1630 | + } |
|
1631 | + |
|
1632 | + /** |
|
1633 | + * Get the url path to the current folder. |
|
1634 | + * |
|
1635 | + * @return string |
|
1636 | + */ |
|
1637 | + public function get_url() { |
|
1638 | + $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) ); |
|
1639 | + $content_url = untrailingslashit( WP_CONTENT_URL ); |
|
1640 | + |
|
1641 | + // Replace http:// to https://. |
|
1642 | + if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) { |
|
1643 | + $content_url = str_replace( 'http://', 'https://', $content_url ); |
|
1644 | + } |
|
1645 | + |
|
1646 | + // Check if we are inside a plugin |
|
1647 | + $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1648 | + $url = str_replace( $content_dir, $content_url, $file_dir ); |
|
1649 | + |
|
1650 | + return trailingslashit( $url ); |
|
1651 | + } |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * Get the url path to the current folder. |
|
1655 | + * |
|
1656 | + * @return string |
|
1657 | + */ |
|
1658 | + public function get_url_old() { |
|
1659 | + |
|
1660 | + $url = ''; |
|
1661 | + // check if we are inside a plugin |
|
1662 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
1663 | + |
|
1664 | + // add check in-case user has changed wp-content dir name. |
|
1665 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
1666 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
1667 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
1668 | + |
|
1669 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
1670 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
1671 | + } |
|
1672 | + |
|
1673 | + return $url; |
|
1674 | + } |
|
1675 | + |
|
1676 | + /** |
|
1677 | + * Register the database settings with WordPress. |
|
1678 | + */ |
|
1679 | + public function register_settings() { |
|
1680 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
1681 | + } |
|
1682 | + |
|
1683 | + /** |
|
1684 | + * Add the WordPress settings menu item. |
|
1685 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
1686 | + */ |
|
1687 | + public function menu_item() { |
|
1688 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
1689 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
1690 | + $this, |
|
1691 | + 'settings_page' |
|
1692 | + ) ); |
|
1693 | + } |
|
1694 | + |
|
1695 | + /** |
|
1696 | + * Get a list of themes and their default JS settings. |
|
1697 | + * |
|
1698 | + * @return array |
|
1699 | + */ |
|
1700 | + public function theme_js_settings(){ |
|
1701 | + return array( |
|
1702 | + 'ayetheme' => 'popper', |
|
1703 | + 'listimia' => 'required', |
|
1704 | + 'listimia_backend' => 'core-popper', |
|
1705 | + //'avada' => 'required', // removed as we now add compatibility |
|
1706 | + ); |
|
1707 | + } |
|
1708 | + |
|
1709 | + /** |
|
1710 | + * Get the current Font Awesome output settings. |
|
1711 | + * |
|
1712 | + * @return array The array of settings. |
|
1713 | + */ |
|
1714 | + public function get_settings() { |
|
1715 | + |
|
1716 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
1717 | + $js_default = 'core-popper'; |
|
1718 | + $js_default_backend = $js_default; |
|
1719 | + |
|
1720 | + // maybe set defaults (if no settings set) |
|
1721 | + if(empty($db_settings)){ |
|
1722 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
1723 | + $theme_js_settings = self::theme_js_settings(); |
|
1724 | + if(isset($theme_js_settings[$active_theme])){ |
|
1725 | + $js_default = $theme_js_settings[$active_theme]; |
|
1726 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
1727 | + } |
|
1728 | + } |
|
1729 | + |
|
1730 | + /** |
|
1731 | + * Filter the default settings. |
|
1732 | + */ |
|
1733 | + $defaults = apply_filters( 'ayecode-ui-default-settings', array( |
|
1734 | + 'css' => 'compatibility', // core, compatibility |
|
1735 | + 'js' => $js_default, // js to load, core-popper, popper |
|
1736 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
1737 | + 'css_backend' => 'compatibility', // core, compatibility |
|
1738 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
1739 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
1740 | + ), $db_settings ); |
|
1741 | + |
|
1742 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
1743 | + |
|
1744 | + /** |
|
1745 | + * Filter the Bootstrap settings. |
|
1746 | + * |
|
1747 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
1748 | + */ |
|
1749 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
1750 | + } |
|
1751 | + |
|
1752 | + |
|
1753 | + /** |
|
1754 | + * The settings page html output. |
|
1755 | + */ |
|
1756 | + public function settings_page() { |
|
1757 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
1758 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
1759 | + } |
|
1760 | + ?> |
|
1761 | 1761 | <div class="wrap"> |
1762 | 1762 | <h1><?php echo $this->name; ?></h1> |
1763 | 1763 | <p><?php echo apply_filters( 'ayecode-ui-settings-message', __("Here you can adjust settings if you are having compatibility issues.",'aui') );?></p> |
1764 | 1764 | <form method="post" action="options.php"> |
1765 | 1765 | <?php |
1766 | - settings_fields( 'ayecode-ui-settings' ); |
|
1767 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
1768 | - ?> |
|
1766 | + settings_fields( 'ayecode-ui-settings' ); |
|
1767 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
1768 | + ?> |
|
1769 | 1769 | |
1770 | 1770 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
1771 | 1771 | <table class="form-table wpbs-table-settings"> |
@@ -1845,60 +1845,60 @@ discard block |
||
1845 | 1845 | </table> |
1846 | 1846 | |
1847 | 1847 | <?php |
1848 | - submit_button(); |
|
1849 | - ?> |
|
1848 | + submit_button(); |
|
1849 | + ?> |
|
1850 | 1850 | </form> |
1851 | 1851 | |
1852 | 1852 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
1853 | 1853 | </div> |
1854 | 1854 | |
1855 | 1855 | <?php |
1856 | - } |
|
1857 | - |
|
1858 | - public function customizer_settings($wp_customize){ |
|
1859 | - $wp_customize->add_section('aui_settings', array( |
|
1860 | - 'title' => __('AyeCode UI','aui'), |
|
1861 | - 'priority' => 120, |
|
1862 | - )); |
|
1863 | - |
|
1864 | - // ============================= |
|
1865 | - // = Color Picker = |
|
1866 | - // ============================= |
|
1867 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1868 | - 'default' => AUI_PRIMARY_COLOR, |
|
1869 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1870 | - 'capability' => 'edit_theme_options', |
|
1871 | - 'type' => 'option', |
|
1872 | - 'transport' => 'refresh', |
|
1873 | - )); |
|
1874 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1875 | - 'label' => __('Primary Color','aui'), |
|
1876 | - 'section' => 'aui_settings', |
|
1877 | - 'settings' => 'aui_options[color_primary]', |
|
1878 | - ))); |
|
1879 | - |
|
1880 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1881 | - 'default' => '#6c757d', |
|
1882 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1883 | - 'capability' => 'edit_theme_options', |
|
1884 | - 'type' => 'option', |
|
1885 | - 'transport' => 'refresh', |
|
1886 | - )); |
|
1887 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1888 | - 'label' => __('Secondary Color','aui'), |
|
1889 | - 'section' => 'aui_settings', |
|
1890 | - 'settings' => 'aui_options[color_secondary]', |
|
1891 | - ))); |
|
1892 | - } |
|
1893 | - |
|
1894 | - /** |
|
1895 | - * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1896 | - * |
|
1897 | - * @return mixed |
|
1898 | - */ |
|
1899 | - public static function bs3_compat_css() { |
|
1900 | - ob_start(); |
|
1901 | - ?> |
|
1856 | + } |
|
1857 | + |
|
1858 | + public function customizer_settings($wp_customize){ |
|
1859 | + $wp_customize->add_section('aui_settings', array( |
|
1860 | + 'title' => __('AyeCode UI','aui'), |
|
1861 | + 'priority' => 120, |
|
1862 | + )); |
|
1863 | + |
|
1864 | + // ============================= |
|
1865 | + // = Color Picker = |
|
1866 | + // ============================= |
|
1867 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1868 | + 'default' => AUI_PRIMARY_COLOR, |
|
1869 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1870 | + 'capability' => 'edit_theme_options', |
|
1871 | + 'type' => 'option', |
|
1872 | + 'transport' => 'refresh', |
|
1873 | + )); |
|
1874 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1875 | + 'label' => __('Primary Color','aui'), |
|
1876 | + 'section' => 'aui_settings', |
|
1877 | + 'settings' => 'aui_options[color_primary]', |
|
1878 | + ))); |
|
1879 | + |
|
1880 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1881 | + 'default' => '#6c757d', |
|
1882 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1883 | + 'capability' => 'edit_theme_options', |
|
1884 | + 'type' => 'option', |
|
1885 | + 'transport' => 'refresh', |
|
1886 | + )); |
|
1887 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1888 | + 'label' => __('Secondary Color','aui'), |
|
1889 | + 'section' => 'aui_settings', |
|
1890 | + 'settings' => 'aui_options[color_secondary]', |
|
1891 | + ))); |
|
1892 | + } |
|
1893 | + |
|
1894 | + /** |
|
1895 | + * CSS to help with conflict issues with other plugins and themes using bootstrap v3. |
|
1896 | + * |
|
1897 | + * @return mixed |
|
1898 | + */ |
|
1899 | + public static function bs3_compat_css() { |
|
1900 | + ob_start(); |
|
1901 | + ?> |
|
1902 | 1902 | <style> |
1903 | 1903 | /* Bootstrap 3 compatibility */ |
1904 | 1904 | body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;} |
@@ -1927,825 +1927,825 @@ discard block |
||
1927 | 1927 | <?php } ?> |
1928 | 1928 | </style> |
1929 | 1929 | <?php |
1930 | - return str_replace( array( |
|
1931 | - '<style>', |
|
1932 | - '</style>' |
|
1933 | - ), '', self::minify_css( ob_get_clean() ) ); |
|
1934 | - } |
|
1935 | - |
|
1936 | - |
|
1937 | - public static function custom_css($compatibility = true) { |
|
1938 | - $colors = array(); |
|
1939 | - if ( defined( 'BLOCKSTRAP_VERSION' ) ) { |
|
1940 | - |
|
1941 | - $setting = wp_get_global_settings(); |
|
1942 | - if(!empty($setting['color']['palette']['theme'])){ |
|
1943 | - foreach($setting['color']['palette']['theme'] as $color){ |
|
1944 | - $colors[$color['slug']] = esc_attr($color['color']); |
|
1945 | - } |
|
1946 | - } |
|
1930 | + return str_replace( array( |
|
1931 | + '<style>', |
|
1932 | + '</style>' |
|
1933 | + ), '', self::minify_css( ob_get_clean() ) ); |
|
1934 | + } |
|
1947 | 1935 | |
1948 | - if(!empty($setting['color']['palette']['custom'])){ |
|
1949 | - foreach($setting['color']['palette']['custom'] as $color){ |
|
1950 | - $colors[$color['slug']] = esc_attr($color['color']); |
|
1951 | - } |
|
1952 | - } |
|
1953 | - }else{ |
|
1954 | - $settings = get_option('aui_options'); |
|
1955 | - $colors = array( |
|
1956 | - 'primary' => ! empty( $settings['color_primary'] ) ? $settings['color_primary'] : AUI_PRIMARY_COLOR, |
|
1957 | - 'secondary' => ! empty( $settings['color_secondary'] ) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR |
|
1958 | - ); |
|
1959 | - } |
|
1960 | 1936 | |
1961 | - ob_start(); |
|
1937 | + public static function custom_css($compatibility = true) { |
|
1938 | + $colors = array(); |
|
1939 | + if ( defined( 'BLOCKSTRAP_VERSION' ) ) { |
|
1940 | + |
|
1941 | + $setting = wp_get_global_settings(); |
|
1942 | + if(!empty($setting['color']['palette']['theme'])){ |
|
1943 | + foreach($setting['color']['palette']['theme'] as $color){ |
|
1944 | + $colors[$color['slug']] = esc_attr($color['color']); |
|
1945 | + } |
|
1946 | + } |
|
1947 | + |
|
1948 | + if(!empty($setting['color']['palette']['custom'])){ |
|
1949 | + foreach($setting['color']['palette']['custom'] as $color){ |
|
1950 | + $colors[$color['slug']] = esc_attr($color['color']); |
|
1951 | + } |
|
1952 | + } |
|
1953 | + }else{ |
|
1954 | + $settings = get_option('aui_options'); |
|
1955 | + $colors = array( |
|
1956 | + 'primary' => ! empty( $settings['color_primary'] ) ? $settings['color_primary'] : AUI_PRIMARY_COLOR, |
|
1957 | + 'secondary' => ! empty( $settings['color_secondary'] ) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR |
|
1958 | + ); |
|
1959 | + } |
|
1962 | 1960 | |
1963 | - ?> |
|
1961 | + ob_start(); |
|
1962 | + |
|
1963 | + ?> |
|
1964 | 1964 | <style> |
1965 | 1965 | <?php |
1966 | 1966 | |
1967 | - // BS v3 compat |
|
1968 | - if( self::is_bs3_compat() ){ |
|
1969 | - echo self::bs3_compat_css(); |
|
1970 | - } |
|
1967 | + // BS v3 compat |
|
1968 | + if( self::is_bs3_compat() ){ |
|
1969 | + echo self::bs3_compat_css(); |
|
1970 | + } |
|
1971 | 1971 | |
1972 | - if(!empty($colors)){ |
|
1973 | - $d_colors = self::get_colors(true); |
|
1974 | - //print_r($d_colors );exit; |
|
1972 | + if(!empty($colors)){ |
|
1973 | + $d_colors = self::get_colors(true); |
|
1974 | + //print_r($d_colors );exit; |
|
1975 | 1975 | // print_r($colors );exit; |
1976 | - $is_fse = !empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'; |
|
1977 | - foreach($colors as $key => $color ){ |
|
1978 | - if((empty( $d_colors[$key]) || $d_colors[$key] != $color) || $is_fse ) { |
|
1979 | - $var = $is_fse ? "var(--wp--preset--color--$key)" : $color; |
|
1980 | - $compat = $is_fse ? '.editor-styles-wrapper' : $compatibility; |
|
1981 | - echo self::css_overwrite($key,$var,$compat); |
|
1982 | - } |
|
1983 | - } |
|
1984 | - // exit; |
|
1985 | - } |
|
1976 | + $is_fse = !empty($_REQUEST['postType']) && $_REQUEST['postType']=='wp_template'; |
|
1977 | + foreach($colors as $key => $color ){ |
|
1978 | + if((empty( $d_colors[$key]) || $d_colors[$key] != $color) || $is_fse ) { |
|
1979 | + $var = $is_fse ? "var(--wp--preset--color--$key)" : $color; |
|
1980 | + $compat = $is_fse ? '.editor-styles-wrapper' : $compatibility; |
|
1981 | + echo self::css_overwrite($key,$var,$compat); |
|
1982 | + } |
|
1983 | + } |
|
1984 | + // exit; |
|
1985 | + } |
|
1986 | 1986 | |
1987 | - // Set admin bar z-index lower when modal is open. |
|
1988 | - echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}'; |
|
1987 | + // Set admin bar z-index lower when modal is open. |
|
1988 | + echo ' body.modal-open #wpadminbar{z-index:999}.embed-responsive-16by9 .fluid-width-video-wrapper{padding:0 !important;position:initial}'; |
|
1989 | 1989 | |
1990 | - if(is_admin()){ |
|
1991 | - echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}'; |
|
1992 | - } |
|
1993 | - ?> |
|
1990 | + if(is_admin()){ |
|
1991 | + echo ' body.modal-open #adminmenuwrap{z-index:999} body.modal-open #wpadminbar{z-index:1025}'; |
|
1992 | + } |
|
1993 | + ?> |
|
1994 | 1994 | </style> |
1995 | 1995 | <?php |
1996 | 1996 | |
1997 | 1997 | |
1998 | - /* |
|
1998 | + /* |
|
1999 | 1999 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
2000 | 2000 | */ |
2001 | - return str_replace( array( |
|
2002 | - '<style>', |
|
2003 | - '</style>' |
|
2004 | - ), '', self::minify_css( ob_get_clean() ) ); |
|
2005 | - } |
|
2006 | - |
|
2007 | - |
|
2008 | - |
|
2009 | - /** |
|
2010 | - * Check if we should add booststrap 3 compatibility changes. |
|
2011 | - * |
|
2012 | - * @return bool |
|
2013 | - */ |
|
2014 | - public static function is_bs3_compat(){ |
|
2015 | - return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
2016 | - } |
|
2017 | - |
|
2018 | - /** |
|
2019 | - * Build the CSS to overwrite a bootstrap color variable. |
|
2020 | - * |
|
2021 | - * @param $type |
|
2022 | - * @param $color_code |
|
2023 | - * @param $compatibility |
|
2024 | - * |
|
2025 | - * @return string |
|
2026 | - */ |
|
2027 | - public static function css_overwrite($type,$color_code,$compatibility){ |
|
2028 | - |
|
2029 | - $is_var = false; |
|
2030 | - if(!$color_code){return '';} |
|
2031 | - if(!sanitize_hex_color($color_code)){ |
|
2032 | - $color_code = esc_attr($color_code); |
|
2033 | - $is_var = true; |
|
2001 | + return str_replace( array( |
|
2002 | + '<style>', |
|
2003 | + '</style>' |
|
2004 | + ), '', self::minify_css( ob_get_clean() ) ); |
|
2005 | + } |
|
2006 | + |
|
2007 | + |
|
2008 | + |
|
2009 | + /** |
|
2010 | + * Check if we should add booststrap 3 compatibility changes. |
|
2011 | + * |
|
2012 | + * @return bool |
|
2013 | + */ |
|
2014 | + public static function is_bs3_compat(){ |
|
2015 | + return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION'); |
|
2016 | + } |
|
2017 | + |
|
2018 | + /** |
|
2019 | + * Build the CSS to overwrite a bootstrap color variable. |
|
2020 | + * |
|
2021 | + * @param $type |
|
2022 | + * @param $color_code |
|
2023 | + * @param $compatibility |
|
2024 | + * |
|
2025 | + * @return string |
|
2026 | + */ |
|
2027 | + public static function css_overwrite($type,$color_code,$compatibility){ |
|
2028 | + |
|
2029 | + $is_var = false; |
|
2030 | + if(!$color_code){return '';} |
|
2031 | + if(!sanitize_hex_color($color_code)){ |
|
2032 | + $color_code = esc_attr($color_code); |
|
2033 | + $is_var = true; |
|
2034 | 2034 | // echo '###1'.$color_code;//exit; |
2035 | - } |
|
2036 | - if(!$color_code){return '';} |
|
2035 | + } |
|
2036 | + if(!$color_code){return '';} |
|
2037 | 2037 | |
2038 | - if($compatibility===true || $compatibility===1){ |
|
2039 | - $compatibility = '.bsui'; |
|
2040 | - }elseif(!$compatibility){ |
|
2041 | - $compatibility = ''; |
|
2042 | - }else{ |
|
2043 | - $compatibility = esc_attr($compatibility); |
|
2044 | - } |
|
2038 | + if($compatibility===true || $compatibility===1){ |
|
2039 | + $compatibility = '.bsui'; |
|
2040 | + }elseif(!$compatibility){ |
|
2041 | + $compatibility = ''; |
|
2042 | + }else{ |
|
2043 | + $compatibility = esc_attr($compatibility); |
|
2044 | + } |
|
2045 | 2045 | |
2046 | 2046 | // echo '####'.$color_code;exit; |
2047 | 2047 | |
2048 | - $type = sanitize_html_class($type); |
|
2049 | - |
|
2050 | - /** |
|
2051 | - * c = color, b = background color, o = border-color, f = fill |
|
2052 | - */ |
|
2053 | - $selectors = array( |
|
2054 | - ".btn-{$type}" => array( 'b', 'o' ), |
|
2055 | - ".btn-{$type}.disabled" => array( 'b', 'o' ), |
|
2056 | - ".btn-{$type}:disabled" => array( 'b', 'o' ), |
|
2057 | - ".btn-outline-{$type}" => array( 'c', 'o' ), |
|
2058 | - ".btn-outline-{$type}:hover" => array( 'b', 'o' ), |
|
2059 | - ".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ), |
|
2060 | - ".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ), |
|
2061 | - ".show>.btn-outline-{$type}.dropdown-toggle" => array( 'b', 'o' ), |
|
2062 | - ".badge-{$type}" => array( 'b' ), |
|
2063 | - ".alert-{$type}" => array( 'b', 'o' ), |
|
2064 | - ".bg-{$type}" => array( 'b', 'f' ), |
|
2065 | - ".btn-link.btn-{$type}" => array( 'c' ), |
|
2066 | - ); |
|
2067 | - |
|
2068 | - if ( $type == 'primary' ) { |
|
2069 | - $selectors = $selectors + array( |
|
2070 | - 'a' => array( 'c' ), |
|
2071 | - '.btn-link' => array( 'c' ), |
|
2072 | - '.dropdown-item.active' => array( 'b' ), |
|
2073 | - '.custom-control-input:checked~.custom-control-label::before' => array( |
|
2074 | - 'b', |
|
2075 | - 'o' |
|
2076 | - ), |
|
2077 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array( |
|
2078 | - 'b', |
|
2079 | - 'o' |
|
2080 | - ), |
|
2081 | - '.nav-pills .nav-link.active' => array( 'b' ), |
|
2082 | - '.nav-pills .show>.nav-link' => array( 'b' ), |
|
2083 | - '.page-link' => array( 'c' ), |
|
2084 | - '.page-item.active .page-link' => array( |
|
2085 | - 'b', |
|
2086 | - 'o' |
|
2087 | - ), |
|
2088 | - '.progress-bar' => array( 'b' ), |
|
2089 | - '.list-group-item.active' => array( |
|
2090 | - 'b', |
|
2091 | - 'o' |
|
2092 | - ), |
|
2093 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ), |
|
2048 | + $type = sanitize_html_class($type); |
|
2049 | + |
|
2050 | + /** |
|
2051 | + * c = color, b = background color, o = border-color, f = fill |
|
2052 | + */ |
|
2053 | + $selectors = array( |
|
2054 | + ".btn-{$type}" => array( 'b', 'o' ), |
|
2055 | + ".btn-{$type}.disabled" => array( 'b', 'o' ), |
|
2056 | + ".btn-{$type}:disabled" => array( 'b', 'o' ), |
|
2057 | + ".btn-outline-{$type}" => array( 'c', 'o' ), |
|
2058 | + ".btn-outline-{$type}:hover" => array( 'b', 'o' ), |
|
2059 | + ".btn-outline-{$type}:not(:disabled):not(.disabled).active" => array( 'b', 'o' ), |
|
2060 | + ".btn-outline-{$type}:not(:disabled):not(.disabled):active" => array( 'b', 'o' ), |
|
2061 | + ".show>.btn-outline-{$type}.dropdown-toggle" => array( 'b', 'o' ), |
|
2062 | + ".badge-{$type}" => array( 'b' ), |
|
2063 | + ".alert-{$type}" => array( 'b', 'o' ), |
|
2064 | + ".bg-{$type}" => array( 'b', 'f' ), |
|
2065 | + ".btn-link.btn-{$type}" => array( 'c' ), |
|
2066 | + ); |
|
2067 | + |
|
2068 | + if ( $type == 'primary' ) { |
|
2069 | + $selectors = $selectors + array( |
|
2070 | + 'a' => array( 'c' ), |
|
2071 | + '.btn-link' => array( 'c' ), |
|
2072 | + '.dropdown-item.active' => array( 'b' ), |
|
2073 | + '.custom-control-input:checked~.custom-control-label::before' => array( |
|
2074 | + 'b', |
|
2075 | + 'o' |
|
2076 | + ), |
|
2077 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array( |
|
2078 | + 'b', |
|
2079 | + 'o' |
|
2080 | + ), |
|
2081 | + '.nav-pills .nav-link.active' => array( 'b' ), |
|
2082 | + '.nav-pills .show>.nav-link' => array( 'b' ), |
|
2083 | + '.page-link' => array( 'c' ), |
|
2084 | + '.page-item.active .page-link' => array( |
|
2085 | + 'b', |
|
2086 | + 'o' |
|
2087 | + ), |
|
2088 | + '.progress-bar' => array( 'b' ), |
|
2089 | + '.list-group-item.active' => array( |
|
2090 | + 'b', |
|
2091 | + 'o' |
|
2092 | + ), |
|
2093 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array( 'b' ), |
|
2094 | 2094 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
2095 | 2095 | // '.custom-range::-moz-range-thumb' => array('b'), |
2096 | 2096 | // '.custom-range::-ms-thumb' => array('b'), |
2097 | - ); |
|
2098 | - } |
|
2099 | - |
|
2100 | - $important_selectors = array( |
|
2101 | - ".bg-{$type}" => array('b','f'), |
|
2102 | - ".border-{$type}" => array('o'), |
|
2103 | - ".text-{$type}" => array('c'), |
|
2104 | - ); |
|
2105 | - |
|
2106 | - $color = array(); |
|
2107 | - $color_i = array(); |
|
2108 | - $background = array(); |
|
2109 | - $background_i = array(); |
|
2110 | - $border = array(); |
|
2111 | - $border_i = array(); |
|
2112 | - $fill = array(); |
|
2113 | - $fill_i = array(); |
|
2114 | - |
|
2115 | - $output = ''; |
|
2116 | - |
|
2117 | - // build rules into each type |
|
2118 | - foreach($selectors as $selector => $types){ |
|
2119 | - $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
|
2120 | - $types = array_combine($types,$types); |
|
2121 | - if(isset($types['c'])){$color[] = $selector;} |
|
2122 | - if(isset($types['b'])){$background[] = $selector;} |
|
2123 | - if(isset($types['o'])){$border[] = $selector;} |
|
2124 | - if(isset($types['f'])){$fill[] = $selector;} |
|
2125 | - } |
|
2126 | - |
|
2127 | - // build rules into each type |
|
2128 | - foreach($important_selectors as $selector => $types){ |
|
2129 | - $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
|
2130 | - $types = array_combine($types,$types); |
|
2131 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
2132 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
2133 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
2134 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
2135 | - } |
|
2136 | - |
|
2137 | - // add any color rules |
|
2138 | - if(!empty($color)){ |
|
2139 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
2140 | - } |
|
2141 | - if(!empty($color_i)){ |
|
2142 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
2143 | - } |
|
2144 | - |
|
2145 | - // add any background color rules |
|
2146 | - if(!empty($background)){ |
|
2147 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
2148 | - } |
|
2149 | - if(!empty($background_i)){ |
|
2150 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
2151 | - } |
|
2152 | - |
|
2153 | - // add any border color rules |
|
2154 | - if(!empty($border)){ |
|
2155 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
2156 | - } |
|
2157 | - if(!empty($border_i)){ |
|
2158 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
2159 | - } |
|
2160 | - |
|
2161 | - // add any fill color rules |
|
2162 | - if(!empty($fill)){ |
|
2163 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
2164 | - } |
|
2165 | - if(!empty($fill_i)){ |
|
2166 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
2167 | - } |
|
2168 | - |
|
2169 | - |
|
2170 | - $prefix = $compatibility ? $compatibility . " " : ""; |
|
2171 | - |
|
2172 | - $transition = $is_var ? 'transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,filter 0.15s ease-in-out;' : ''; |
|
2173 | - // darken |
|
2174 | - $darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075"); |
|
2175 | - $darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10"); |
|
2176 | - $darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125"); |
|
2177 | - |
|
2178 | - // lighten |
|
2179 | - $lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25"); |
|
2180 | - |
|
2181 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
2182 | - $op_25 = $color_code."40"; // 25% opacity |
|
2183 | - |
|
2184 | - |
|
2185 | - // button states |
|
2186 | - $output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : ''; |
|
2187 | - $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
2097 | + ); |
|
2098 | + } |
|
2099 | + |
|
2100 | + $important_selectors = array( |
|
2101 | + ".bg-{$type}" => array('b','f'), |
|
2102 | + ".border-{$type}" => array('o'), |
|
2103 | + ".text-{$type}" => array('c'), |
|
2104 | + ); |
|
2105 | + |
|
2106 | + $color = array(); |
|
2107 | + $color_i = array(); |
|
2108 | + $background = array(); |
|
2109 | + $background_i = array(); |
|
2110 | + $border = array(); |
|
2111 | + $border_i = array(); |
|
2112 | + $fill = array(); |
|
2113 | + $fill_i = array(); |
|
2114 | + |
|
2115 | + $output = ''; |
|
2116 | + |
|
2117 | + // build rules into each type |
|
2118 | + foreach($selectors as $selector => $types){ |
|
2119 | + $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
|
2120 | + $types = array_combine($types,$types); |
|
2121 | + if(isset($types['c'])){$color[] = $selector;} |
|
2122 | + if(isset($types['b'])){$background[] = $selector;} |
|
2123 | + if(isset($types['o'])){$border[] = $selector;} |
|
2124 | + if(isset($types['f'])){$fill[] = $selector;} |
|
2125 | + } |
|
2126 | + |
|
2127 | + // build rules into each type |
|
2128 | + foreach($important_selectors as $selector => $types){ |
|
2129 | + $selector = $compatibility ? $compatibility . " ".$selector : $selector; |
|
2130 | + $types = array_combine($types,$types); |
|
2131 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
2132 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
2133 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
2134 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
2135 | + } |
|
2136 | + |
|
2137 | + // add any color rules |
|
2138 | + if(!empty($color)){ |
|
2139 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
2140 | + } |
|
2141 | + if(!empty($color_i)){ |
|
2142 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
2143 | + } |
|
2144 | + |
|
2145 | + // add any background color rules |
|
2146 | + if(!empty($background)){ |
|
2147 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
2148 | + } |
|
2149 | + if(!empty($background_i)){ |
|
2150 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
2151 | + } |
|
2152 | + |
|
2153 | + // add any border color rules |
|
2154 | + if(!empty($border)){ |
|
2155 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
2156 | + } |
|
2157 | + if(!empty($border_i)){ |
|
2158 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
2159 | + } |
|
2160 | + |
|
2161 | + // add any fill color rules |
|
2162 | + if(!empty($fill)){ |
|
2163 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
2164 | + } |
|
2165 | + if(!empty($fill_i)){ |
|
2166 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
2167 | + } |
|
2168 | + |
|
2169 | + |
|
2170 | + $prefix = $compatibility ? $compatibility . " " : ""; |
|
2171 | + |
|
2172 | + $transition = $is_var ? 'transition: color 0.15s ease-in-out,background-color 0.15s ease-in-out,border-color 0.15s ease-in-out,box-shadow 0.15s ease-in-out,filter 0.15s ease-in-out;' : ''; |
|
2173 | + // darken |
|
2174 | + $darker_075 = $is_var ? $color_code.';filter:brightness(0.925)' : self::css_hex_lighten_darken($color_code,"-0.075"); |
|
2175 | + $darker_10 = $is_var ? $color_code.';filter:brightness(0.9)' : self::css_hex_lighten_darken($color_code,"-0.10"); |
|
2176 | + $darker_125 = $is_var ? $color_code.';filter:brightness(0.875)' : self::css_hex_lighten_darken($color_code,"-0.125"); |
|
2177 | + |
|
2178 | + // lighten |
|
2179 | + $lighten_25 = $is_var ? $color_code.';filter:brightness(1.25)' :self::css_hex_lighten_darken($color_code,"0.25"); |
|
2180 | + |
|
2181 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
2182 | + $op_25 = $color_code."40"; // 25% opacity |
|
2183 | + |
|
2184 | + |
|
2185 | + // button states |
|
2186 | + $output .= $is_var ? $prefix ." .btn-{$type}{{$transition }} " : ''; |
|
2187 | + $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
2188 | 2188 | // $output .= $prefix ." .btn-{$type}:hover, $prefix .btn-{$type}:focus, $prefix .btn-{$type}.focus{background-color: #000; border-color: #000;} "; |
2189 | - $output .= $prefix ." .btn-outline-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-{$type}.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2190 | - $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active, $prefix .btn-{$type}:not(:disabled):not(.disabled).active, .show>$prefix .btn-{$type}.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
2191 | - $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-{$type}.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2192 | - |
|
2193 | - if ( $type == 'primary' ) { |
|
2194 | - // dropdown's |
|
2195 | - $output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
2196 | - |
|
2197 | - // input states |
|
2198 | - $output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2199 | - |
|
2200 | - // page link |
|
2201 | - $output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2202 | - } |
|
2203 | - |
|
2204 | - return $output; |
|
2205 | - } |
|
2206 | - |
|
2207 | - /** |
|
2208 | - * |
|
2209 | - * @deprecated 0.1.76 Use css_overwrite() |
|
2210 | - * |
|
2211 | - * @param $color_code |
|
2212 | - * @param $compatibility |
|
2213 | - * @param $use_variable |
|
2214 | - * |
|
2215 | - * @return string |
|
2216 | - */ |
|
2217 | - public static function css_primary($color_code,$compatibility, $use_variable = false){ |
|
2218 | - |
|
2219 | - if(!$use_variable){ |
|
2220 | - $color_code = sanitize_hex_color($color_code); |
|
2221 | - if(!$color_code){return '';} |
|
2222 | - } |
|
2223 | - |
|
2224 | - /** |
|
2225 | - * c = color, b = background color, o = border-color, f = fill |
|
2226 | - */ |
|
2227 | - $selectors = array( |
|
2228 | - 'a' => array('c'), |
|
2229 | - '.btn-primary' => array('b','o'), |
|
2230 | - '.btn-primary.disabled' => array('b','o'), |
|
2231 | - '.btn-primary:disabled' => array('b','o'), |
|
2232 | - '.btn-outline-primary' => array('c','o'), |
|
2233 | - '.btn-outline-primary:hover' => array('b','o'), |
|
2234 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
2235 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
2236 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
2237 | - '.btn-link' => array('c'), |
|
2238 | - '.dropdown-item.active' => array('b'), |
|
2239 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
2240 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
2189 | + $output .= $prefix ." .btn-outline-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-{$type}.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2190 | + $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active, $prefix .btn-{$type}:not(:disabled):not(.disabled).active, .show>$prefix .btn-{$type}.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
2191 | + $output .= $prefix ." .btn-{$type}:not(:disabled):not(.disabled):active:focus, $prefix .btn-{$type}:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-{$type}.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2192 | + |
|
2193 | + if ( $type == 'primary' ) { |
|
2194 | + // dropdown's |
|
2195 | + $output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
2196 | + |
|
2197 | + // input states |
|
2198 | + $output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2199 | + |
|
2200 | + // page link |
|
2201 | + $output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2202 | + } |
|
2203 | + |
|
2204 | + return $output; |
|
2205 | + } |
|
2206 | + |
|
2207 | + /** |
|
2208 | + * |
|
2209 | + * @deprecated 0.1.76 Use css_overwrite() |
|
2210 | + * |
|
2211 | + * @param $color_code |
|
2212 | + * @param $compatibility |
|
2213 | + * @param $use_variable |
|
2214 | + * |
|
2215 | + * @return string |
|
2216 | + */ |
|
2217 | + public static function css_primary($color_code,$compatibility, $use_variable = false){ |
|
2218 | + |
|
2219 | + if(!$use_variable){ |
|
2220 | + $color_code = sanitize_hex_color($color_code); |
|
2221 | + if(!$color_code){return '';} |
|
2222 | + } |
|
2223 | + |
|
2224 | + /** |
|
2225 | + * c = color, b = background color, o = border-color, f = fill |
|
2226 | + */ |
|
2227 | + $selectors = array( |
|
2228 | + 'a' => array('c'), |
|
2229 | + '.btn-primary' => array('b','o'), |
|
2230 | + '.btn-primary.disabled' => array('b','o'), |
|
2231 | + '.btn-primary:disabled' => array('b','o'), |
|
2232 | + '.btn-outline-primary' => array('c','o'), |
|
2233 | + '.btn-outline-primary:hover' => array('b','o'), |
|
2234 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
2235 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
2236 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
2237 | + '.btn-link' => array('c'), |
|
2238 | + '.dropdown-item.active' => array('b'), |
|
2239 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
2240 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
2241 | 2241 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
2242 | 2242 | // '.custom-range::-moz-range-thumb' => array('b'), |
2243 | 2243 | // '.custom-range::-ms-thumb' => array('b'), |
2244 | - '.nav-pills .nav-link.active' => array('b'), |
|
2245 | - '.nav-pills .show>.nav-link' => array('b'), |
|
2246 | - '.page-link' => array('c'), |
|
2247 | - '.page-item.active .page-link' => array('b','o'), |
|
2248 | - '.badge-primary' => array('b'), |
|
2249 | - '.alert-primary' => array('b','o'), |
|
2250 | - '.progress-bar' => array('b'), |
|
2251 | - '.list-group-item.active' => array('b','o'), |
|
2252 | - '.bg-primary' => array('b','f'), |
|
2253 | - '.btn-link.btn-primary' => array('c'), |
|
2254 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
2255 | - ); |
|
2256 | - |
|
2257 | - $important_selectors = array( |
|
2258 | - '.bg-primary' => array('b','f'), |
|
2259 | - '.border-primary' => array('o'), |
|
2260 | - '.text-primary' => array('c'), |
|
2261 | - ); |
|
2262 | - |
|
2263 | - $color = array(); |
|
2264 | - $color_i = array(); |
|
2265 | - $background = array(); |
|
2266 | - $background_i = array(); |
|
2267 | - $border = array(); |
|
2268 | - $border_i = array(); |
|
2269 | - $fill = array(); |
|
2270 | - $fill_i = array(); |
|
2271 | - |
|
2272 | - $output = ''; |
|
2273 | - |
|
2274 | - // build rules into each type |
|
2275 | - foreach($selectors as $selector => $types){ |
|
2276 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2277 | - $types = array_combine($types,$types); |
|
2278 | - if(isset($types['c'])){$color[] = $selector;} |
|
2279 | - if(isset($types['b'])){$background[] = $selector;} |
|
2280 | - if(isset($types['o'])){$border[] = $selector;} |
|
2281 | - if(isset($types['f'])){$fill[] = $selector;} |
|
2282 | - } |
|
2283 | - |
|
2284 | - // build rules into each type |
|
2285 | - foreach($important_selectors as $selector => $types){ |
|
2286 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2287 | - $types = array_combine($types,$types); |
|
2288 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
2289 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
2290 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
2291 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
2292 | - } |
|
2293 | - |
|
2294 | - // add any color rules |
|
2295 | - if(!empty($color)){ |
|
2296 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
2297 | - } |
|
2298 | - if(!empty($color_i)){ |
|
2299 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
2300 | - } |
|
2301 | - |
|
2302 | - // add any background color rules |
|
2303 | - if(!empty($background)){ |
|
2304 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
2305 | - } |
|
2306 | - if(!empty($background_i)){ |
|
2307 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
2308 | - } |
|
2309 | - |
|
2310 | - // add any border color rules |
|
2311 | - if(!empty($border)){ |
|
2312 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
2313 | - } |
|
2314 | - if(!empty($border_i)){ |
|
2315 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
2316 | - } |
|
2317 | - |
|
2318 | - // add any fill color rules |
|
2319 | - if(!empty($fill)){ |
|
2320 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
2321 | - } |
|
2322 | - if(!empty($fill_i)){ |
|
2323 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
2324 | - } |
|
2325 | - |
|
2326 | - |
|
2327 | - $prefix = $compatibility ? ".bsui " : ""; |
|
2328 | - |
|
2329 | - // darken |
|
2330 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
2331 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
2332 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
2333 | - |
|
2334 | - // lighten |
|
2335 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
2336 | - |
|
2337 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
2338 | - $op_25 = $color_code."40"; // 25% opacity |
|
2339 | - |
|
2340 | - |
|
2341 | - // button states |
|
2342 | - $output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
2343 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2344 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
2345 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2346 | - |
|
2347 | - |
|
2348 | - // dropdown's |
|
2349 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
2350 | - |
|
2351 | - |
|
2352 | - // input states |
|
2353 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2354 | - |
|
2355 | - // page link |
|
2356 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2357 | - |
|
2358 | - return $output; |
|
2359 | - } |
|
2360 | - |
|
2361 | - /** |
|
2362 | - * |
|
2363 | - * @deprecated 0.1.76 Use css_overwrite() |
|
2364 | - * |
|
2365 | - * @param $color_code |
|
2366 | - * @param $compatibility |
|
2367 | - * |
|
2368 | - * @return string |
|
2369 | - */ |
|
2370 | - public static function css_secondary($color_code,$compatibility){; |
|
2371 | - $color_code = sanitize_hex_color($color_code); |
|
2372 | - if(!$color_code){return '';} |
|
2373 | - /** |
|
2374 | - * c = color, b = background color, o = border-color, f = fill |
|
2375 | - */ |
|
2376 | - $selectors = array( |
|
2377 | - '.btn-secondary' => array('b','o'), |
|
2378 | - '.btn-secondary.disabled' => array('b','o'), |
|
2379 | - '.btn-secondary:disabled' => array('b','o'), |
|
2380 | - '.btn-outline-secondary' => array('c','o'), |
|
2381 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
2382 | - '.btn-outline-secondary.disabled' => array('c'), |
|
2383 | - '.btn-outline-secondary:disabled' => array('c'), |
|
2384 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
2385 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
2386 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
2387 | - '.badge-secondary' => array('b'), |
|
2388 | - '.alert-secondary' => array('b','o'), |
|
2389 | - '.btn-link.btn-secondary' => array('c'), |
|
2390 | - ); |
|
2391 | - |
|
2392 | - $important_selectors = array( |
|
2393 | - '.bg-secondary' => array('b','f'), |
|
2394 | - '.border-secondary' => array('o'), |
|
2395 | - '.text-secondary' => array('c'), |
|
2396 | - ); |
|
2397 | - |
|
2398 | - $color = array(); |
|
2399 | - $color_i = array(); |
|
2400 | - $background = array(); |
|
2401 | - $background_i = array(); |
|
2402 | - $border = array(); |
|
2403 | - $border_i = array(); |
|
2404 | - $fill = array(); |
|
2405 | - $fill_i = array(); |
|
2406 | - |
|
2407 | - $output = ''; |
|
2408 | - |
|
2409 | - // build rules into each type |
|
2410 | - foreach($selectors as $selector => $types){ |
|
2411 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2412 | - $types = array_combine($types,$types); |
|
2413 | - if(isset($types['c'])){$color[] = $selector;} |
|
2414 | - if(isset($types['b'])){$background[] = $selector;} |
|
2415 | - if(isset($types['o'])){$border[] = $selector;} |
|
2416 | - if(isset($types['f'])){$fill[] = $selector;} |
|
2417 | - } |
|
2418 | - |
|
2419 | - // build rules into each type |
|
2420 | - foreach($important_selectors as $selector => $types){ |
|
2421 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2422 | - $types = array_combine($types,$types); |
|
2423 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
2424 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
2425 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
2426 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
2427 | - } |
|
2428 | - |
|
2429 | - // add any color rules |
|
2430 | - if(!empty($color)){ |
|
2431 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
2432 | - } |
|
2433 | - if(!empty($color_i)){ |
|
2434 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
2435 | - } |
|
2436 | - |
|
2437 | - // add any background color rules |
|
2438 | - if(!empty($background)){ |
|
2439 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
2440 | - } |
|
2441 | - if(!empty($background_i)){ |
|
2442 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
2443 | - } |
|
2444 | - |
|
2445 | - // add any border color rules |
|
2446 | - if(!empty($border)){ |
|
2447 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
2448 | - } |
|
2449 | - if(!empty($border_i)){ |
|
2450 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
2451 | - } |
|
2452 | - |
|
2453 | - // add any fill color rules |
|
2454 | - if(!empty($fill)){ |
|
2455 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
2456 | - } |
|
2457 | - if(!empty($fill_i)){ |
|
2458 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
2459 | - } |
|
2460 | - |
|
2461 | - |
|
2462 | - $prefix = $compatibility ? ".bsui " : ""; |
|
2463 | - |
|
2464 | - // darken |
|
2465 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
2466 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
2467 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
2468 | - |
|
2469 | - // lighten |
|
2470 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
2471 | - |
|
2472 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
2473 | - $op_25 = $color_code."40"; // 25% opacity |
|
2474 | - |
|
2475 | - |
|
2476 | - // button states |
|
2477 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
2478 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2479 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
2480 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2481 | - |
|
2482 | - |
|
2483 | - return $output; |
|
2484 | - } |
|
2485 | - |
|
2486 | - /** |
|
2487 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
2488 | - * |
|
2489 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
2490 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
2491 | - * |
|
2492 | - * @return string |
|
2493 | - */ |
|
2494 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
2495 | - $hexCode = ltrim($hexCode, '#'); |
|
2496 | - |
|
2497 | - if (strlen($hexCode) == 3) { |
|
2498 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
2499 | - } |
|
2500 | - |
|
2501 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
2502 | - |
|
2503 | - foreach ($hexCode as & $color) { |
|
2504 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
2505 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
2506 | - |
|
2507 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
2508 | - } |
|
2509 | - |
|
2510 | - return '#' . implode($hexCode); |
|
2511 | - } |
|
2512 | - |
|
2513 | - /** |
|
2514 | - * Check if we should display examples. |
|
2515 | - */ |
|
2516 | - public function maybe_show_examples(){ |
|
2517 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
2518 | - echo "<head>"; |
|
2519 | - wp_head(); |
|
2520 | - echo "</head>"; |
|
2521 | - echo "<body>"; |
|
2522 | - echo $this->get_examples(); |
|
2523 | - echo "</body>"; |
|
2524 | - exit; |
|
2525 | - } |
|
2526 | - } |
|
2527 | - |
|
2528 | - /** |
|
2529 | - * Get developer examples. |
|
2530 | - * |
|
2531 | - * @return string |
|
2532 | - */ |
|
2533 | - public function get_examples(){ |
|
2534 | - $output = ''; |
|
2535 | - |
|
2536 | - |
|
2537 | - // open form |
|
2538 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
2539 | - |
|
2540 | - // input example |
|
2541 | - $output .= aui()->input(array( |
|
2542 | - 'type' => 'text', |
|
2543 | - 'id' => 'text-example', |
|
2544 | - 'name' => 'text-example', |
|
2545 | - 'placeholder' => 'text placeholder', |
|
2546 | - 'title' => 'Text input example', |
|
2547 | - 'value' => '', |
|
2548 | - 'required' => false, |
|
2549 | - 'help_text' => 'help text', |
|
2550 | - 'label' => 'Text input example label' |
|
2551 | - )); |
|
2552 | - |
|
2553 | - // input example |
|
2554 | - $output .= aui()->input(array( |
|
2555 | - 'type' => 'url', |
|
2556 | - 'id' => 'text-example2', |
|
2557 | - 'name' => 'text-example', |
|
2558 | - 'placeholder' => 'url placeholder', |
|
2559 | - 'title' => 'Text input example', |
|
2560 | - 'value' => '', |
|
2561 | - 'required' => false, |
|
2562 | - 'help_text' => 'help text', |
|
2563 | - 'label' => 'Text input example label' |
|
2564 | - )); |
|
2565 | - |
|
2566 | - // checkbox example |
|
2567 | - $output .= aui()->input(array( |
|
2568 | - 'type' => 'checkbox', |
|
2569 | - 'id' => 'checkbox-example', |
|
2570 | - 'name' => 'checkbox-example', |
|
2571 | - 'placeholder' => 'checkbox-example', |
|
2572 | - 'title' => 'Checkbox example', |
|
2573 | - 'value' => '1', |
|
2574 | - 'checked' => true, |
|
2575 | - 'required' => false, |
|
2576 | - 'help_text' => 'help text', |
|
2577 | - 'label' => 'Checkbox checked' |
|
2578 | - )); |
|
2579 | - |
|
2580 | - // checkbox example |
|
2581 | - $output .= aui()->input(array( |
|
2582 | - 'type' => 'checkbox', |
|
2583 | - 'id' => 'checkbox-example2', |
|
2584 | - 'name' => 'checkbox-example2', |
|
2585 | - 'placeholder' => 'checkbox-example', |
|
2586 | - 'title' => 'Checkbox example', |
|
2587 | - 'value' => '1', |
|
2588 | - 'checked' => false, |
|
2589 | - 'required' => false, |
|
2590 | - 'help_text' => 'help text', |
|
2591 | - 'label' => 'Checkbox un-checked' |
|
2592 | - )); |
|
2593 | - |
|
2594 | - // switch example |
|
2595 | - $output .= aui()->input(array( |
|
2596 | - 'type' => 'checkbox', |
|
2597 | - 'id' => 'switch-example', |
|
2598 | - 'name' => 'switch-example', |
|
2599 | - 'placeholder' => 'checkbox-example', |
|
2600 | - 'title' => 'Switch example', |
|
2601 | - 'value' => '1', |
|
2602 | - 'checked' => true, |
|
2603 | - 'switch' => true, |
|
2604 | - 'required' => false, |
|
2605 | - 'help_text' => 'help text', |
|
2606 | - 'label' => 'Switch on' |
|
2607 | - )); |
|
2608 | - |
|
2609 | - // switch example |
|
2610 | - $output .= aui()->input(array( |
|
2611 | - 'type' => 'checkbox', |
|
2612 | - 'id' => 'switch-example2', |
|
2613 | - 'name' => 'switch-example2', |
|
2614 | - 'placeholder' => 'checkbox-example', |
|
2615 | - 'title' => 'Switch example', |
|
2616 | - 'value' => '1', |
|
2617 | - 'checked' => false, |
|
2618 | - 'switch' => true, |
|
2619 | - 'required' => false, |
|
2620 | - 'help_text' => 'help text', |
|
2621 | - 'label' => 'Switch off' |
|
2622 | - )); |
|
2623 | - |
|
2624 | - // close form |
|
2625 | - $output .= "</form>"; |
|
2626 | - |
|
2627 | - return $output; |
|
2628 | - } |
|
2629 | - |
|
2630 | - /** |
|
2631 | - * Calendar params. |
|
2632 | - * |
|
2633 | - * @since 0.1.44 |
|
2634 | - * |
|
2635 | - * @return array Calendar params. |
|
2636 | - */ |
|
2637 | - public static function calendar_params() { |
|
2638 | - $params = array( |
|
2639 | - 'month_long_1' => __( 'January', 'aui' ), |
|
2640 | - 'month_long_2' => __( 'February', 'aui' ), |
|
2641 | - 'month_long_3' => __( 'March', 'aui' ), |
|
2642 | - 'month_long_4' => __( 'April', 'aui' ), |
|
2643 | - 'month_long_5' => __( 'May', 'aui' ), |
|
2644 | - 'month_long_6' => __( 'June', 'aui' ), |
|
2645 | - 'month_long_7' => __( 'July', 'aui' ), |
|
2646 | - 'month_long_8' => __( 'August', 'aui' ), |
|
2647 | - 'month_long_9' => __( 'September', 'aui' ), |
|
2648 | - 'month_long_10' => __( 'October', 'aui' ), |
|
2649 | - 'month_long_11' => __( 'November', 'aui' ), |
|
2650 | - 'month_long_12' => __( 'December', 'aui' ), |
|
2651 | - 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
2652 | - 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
2653 | - 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
2654 | - 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
2655 | - 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
2656 | - 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
2657 | - 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
2658 | - 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
2659 | - 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
2660 | - 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
2661 | - 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
2662 | - 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
2663 | - 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
2664 | - 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
2665 | - 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
2666 | - 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
2667 | - 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
2668 | - 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
2669 | - 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
2670 | - 'day_s2_1' => __( 'Su', 'aui' ), |
|
2671 | - 'day_s2_2' => __( 'Mo', 'aui' ), |
|
2672 | - 'day_s2_3' => __( 'Tu', 'aui' ), |
|
2673 | - 'day_s2_4' => __( 'We', 'aui' ), |
|
2674 | - 'day_s2_5' => __( 'Th', 'aui' ), |
|
2675 | - 'day_s2_6' => __( 'Fr', 'aui' ), |
|
2676 | - 'day_s2_7' => __( 'Sa', 'aui' ), |
|
2677 | - 'day_s3_1' => __( 'Sun', 'aui' ), |
|
2678 | - 'day_s3_2' => __( 'Mon', 'aui' ), |
|
2679 | - 'day_s3_3' => __( 'Tue', 'aui' ), |
|
2680 | - 'day_s3_4' => __( 'Wed', 'aui' ), |
|
2681 | - 'day_s3_5' => __( 'Thu', 'aui' ), |
|
2682 | - 'day_s3_6' => __( 'Fri', 'aui' ), |
|
2683 | - 'day_s3_7' => __( 'Sat', 'aui' ), |
|
2684 | - 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
2685 | - 'day_s5_2' => __( 'Monday', 'aui' ), |
|
2686 | - 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
2687 | - 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
2688 | - 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
2689 | - 'day_s5_6' => __( 'Friday', 'aui' ), |
|
2690 | - 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
2691 | - 'am_lower' => __( 'am', 'aui' ), |
|
2692 | - 'pm_lower' => __( 'pm', 'aui' ), |
|
2693 | - 'am_upper' => __( 'AM', 'aui' ), |
|
2694 | - 'pm_upper' => __( 'PM', 'aui' ), |
|
2695 | - 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
2696 | - 'time_24hr' => false, |
|
2697 | - 'year' => __( 'Year', 'aui' ), |
|
2698 | - 'hour' => __( 'Hour', 'aui' ), |
|
2699 | - 'minute' => __( 'Minute', 'aui' ), |
|
2700 | - 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
2701 | - 'rangeSeparator' => __( ' to ', 'aui' ), |
|
2702 | - 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
2703 | - 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
2704 | - ); |
|
2705 | - |
|
2706 | - return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
2707 | - } |
|
2708 | - |
|
2709 | - /** |
|
2710 | - * Flatpickr calendar localize. |
|
2711 | - * |
|
2712 | - * @since 0.1.44 |
|
2713 | - * |
|
2714 | - * @return string Calendar locale. |
|
2715 | - */ |
|
2716 | - public static function flatpickr_locale() { |
|
2717 | - $params = self::calendar_params(); |
|
2718 | - |
|
2719 | - if ( is_string( $params ) ) { |
|
2720 | - $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
2721 | - } else { |
|
2722 | - foreach ( (array) $params as $key => $value ) { |
|
2723 | - if ( ! is_scalar( $value ) ) { |
|
2724 | - continue; |
|
2725 | - } |
|
2726 | - |
|
2727 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2728 | - } |
|
2729 | - } |
|
2244 | + '.nav-pills .nav-link.active' => array('b'), |
|
2245 | + '.nav-pills .show>.nav-link' => array('b'), |
|
2246 | + '.page-link' => array('c'), |
|
2247 | + '.page-item.active .page-link' => array('b','o'), |
|
2248 | + '.badge-primary' => array('b'), |
|
2249 | + '.alert-primary' => array('b','o'), |
|
2250 | + '.progress-bar' => array('b'), |
|
2251 | + '.list-group-item.active' => array('b','o'), |
|
2252 | + '.bg-primary' => array('b','f'), |
|
2253 | + '.btn-link.btn-primary' => array('c'), |
|
2254 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
2255 | + ); |
|
2256 | + |
|
2257 | + $important_selectors = array( |
|
2258 | + '.bg-primary' => array('b','f'), |
|
2259 | + '.border-primary' => array('o'), |
|
2260 | + '.text-primary' => array('c'), |
|
2261 | + ); |
|
2262 | + |
|
2263 | + $color = array(); |
|
2264 | + $color_i = array(); |
|
2265 | + $background = array(); |
|
2266 | + $background_i = array(); |
|
2267 | + $border = array(); |
|
2268 | + $border_i = array(); |
|
2269 | + $fill = array(); |
|
2270 | + $fill_i = array(); |
|
2271 | + |
|
2272 | + $output = ''; |
|
2273 | + |
|
2274 | + // build rules into each type |
|
2275 | + foreach($selectors as $selector => $types){ |
|
2276 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2277 | + $types = array_combine($types,$types); |
|
2278 | + if(isset($types['c'])){$color[] = $selector;} |
|
2279 | + if(isset($types['b'])){$background[] = $selector;} |
|
2280 | + if(isset($types['o'])){$border[] = $selector;} |
|
2281 | + if(isset($types['f'])){$fill[] = $selector;} |
|
2282 | + } |
|
2283 | + |
|
2284 | + // build rules into each type |
|
2285 | + foreach($important_selectors as $selector => $types){ |
|
2286 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2287 | + $types = array_combine($types,$types); |
|
2288 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
2289 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
2290 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
2291 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
2292 | + } |
|
2293 | + |
|
2294 | + // add any color rules |
|
2295 | + if(!empty($color)){ |
|
2296 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
2297 | + } |
|
2298 | + if(!empty($color_i)){ |
|
2299 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
2300 | + } |
|
2301 | + |
|
2302 | + // add any background color rules |
|
2303 | + if(!empty($background)){ |
|
2304 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
2305 | + } |
|
2306 | + if(!empty($background_i)){ |
|
2307 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
2308 | + } |
|
2309 | + |
|
2310 | + // add any border color rules |
|
2311 | + if(!empty($border)){ |
|
2312 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
2313 | + } |
|
2314 | + if(!empty($border_i)){ |
|
2315 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
2316 | + } |
|
2317 | + |
|
2318 | + // add any fill color rules |
|
2319 | + if(!empty($fill)){ |
|
2320 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
2321 | + } |
|
2322 | + if(!empty($fill_i)){ |
|
2323 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
2324 | + } |
|
2325 | + |
|
2326 | + |
|
2327 | + $prefix = $compatibility ? ".bsui " : ""; |
|
2328 | + |
|
2329 | + // darken |
|
2330 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
2331 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
2332 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
2333 | + |
|
2334 | + // lighten |
|
2335 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
2336 | + |
|
2337 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
2338 | + $op_25 = $color_code."40"; // 25% opacity |
|
2339 | + |
|
2340 | + |
|
2341 | + // button states |
|
2342 | + $output .= $prefix ." .btn-primary:hover, $prefix .btn-primary:focus, $prefix .btn-primary.focus{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
2343 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2344 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
2345 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2346 | + |
|
2347 | + |
|
2348 | + // dropdown's |
|
2349 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
2350 | + |
|
2351 | + |
|
2352 | + // input states |
|
2353 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2354 | + |
|
2355 | + // page link |
|
2356 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2357 | + |
|
2358 | + return $output; |
|
2359 | + } |
|
2360 | + |
|
2361 | + /** |
|
2362 | + * |
|
2363 | + * @deprecated 0.1.76 Use css_overwrite() |
|
2364 | + * |
|
2365 | + * @param $color_code |
|
2366 | + * @param $compatibility |
|
2367 | + * |
|
2368 | + * @return string |
|
2369 | + */ |
|
2370 | + public static function css_secondary($color_code,$compatibility){; |
|
2371 | + $color_code = sanitize_hex_color($color_code); |
|
2372 | + if(!$color_code){return '';} |
|
2373 | + /** |
|
2374 | + * c = color, b = background color, o = border-color, f = fill |
|
2375 | + */ |
|
2376 | + $selectors = array( |
|
2377 | + '.btn-secondary' => array('b','o'), |
|
2378 | + '.btn-secondary.disabled' => array('b','o'), |
|
2379 | + '.btn-secondary:disabled' => array('b','o'), |
|
2380 | + '.btn-outline-secondary' => array('c','o'), |
|
2381 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
2382 | + '.btn-outline-secondary.disabled' => array('c'), |
|
2383 | + '.btn-outline-secondary:disabled' => array('c'), |
|
2384 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
2385 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
2386 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
2387 | + '.badge-secondary' => array('b'), |
|
2388 | + '.alert-secondary' => array('b','o'), |
|
2389 | + '.btn-link.btn-secondary' => array('c'), |
|
2390 | + ); |
|
2391 | + |
|
2392 | + $important_selectors = array( |
|
2393 | + '.bg-secondary' => array('b','f'), |
|
2394 | + '.border-secondary' => array('o'), |
|
2395 | + '.text-secondary' => array('c'), |
|
2396 | + ); |
|
2397 | + |
|
2398 | + $color = array(); |
|
2399 | + $color_i = array(); |
|
2400 | + $background = array(); |
|
2401 | + $background_i = array(); |
|
2402 | + $border = array(); |
|
2403 | + $border_i = array(); |
|
2404 | + $fill = array(); |
|
2405 | + $fill_i = array(); |
|
2406 | + |
|
2407 | + $output = ''; |
|
2408 | + |
|
2409 | + // build rules into each type |
|
2410 | + foreach($selectors as $selector => $types){ |
|
2411 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2412 | + $types = array_combine($types,$types); |
|
2413 | + if(isset($types['c'])){$color[] = $selector;} |
|
2414 | + if(isset($types['b'])){$background[] = $selector;} |
|
2415 | + if(isset($types['o'])){$border[] = $selector;} |
|
2416 | + if(isset($types['f'])){$fill[] = $selector;} |
|
2417 | + } |
|
2418 | + |
|
2419 | + // build rules into each type |
|
2420 | + foreach($important_selectors as $selector => $types){ |
|
2421 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
2422 | + $types = array_combine($types,$types); |
|
2423 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
2424 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
2425 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
2426 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
2427 | + } |
|
2428 | + |
|
2429 | + // add any color rules |
|
2430 | + if(!empty($color)){ |
|
2431 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
2432 | + } |
|
2433 | + if(!empty($color_i)){ |
|
2434 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
2435 | + } |
|
2436 | + |
|
2437 | + // add any background color rules |
|
2438 | + if(!empty($background)){ |
|
2439 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
2440 | + } |
|
2441 | + if(!empty($background_i)){ |
|
2442 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
2443 | + } |
|
2444 | + |
|
2445 | + // add any border color rules |
|
2446 | + if(!empty($border)){ |
|
2447 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
2448 | + } |
|
2449 | + if(!empty($border_i)){ |
|
2450 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
2451 | + } |
|
2452 | + |
|
2453 | + // add any fill color rules |
|
2454 | + if(!empty($fill)){ |
|
2455 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
2456 | + } |
|
2457 | + if(!empty($fill_i)){ |
|
2458 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
2459 | + } |
|
2460 | + |
|
2461 | + |
|
2462 | + $prefix = $compatibility ? ".bsui " : ""; |
|
2463 | + |
|
2464 | + // darken |
|
2465 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
2466 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
2467 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
2468 | + |
|
2469 | + // lighten |
|
2470 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
2471 | + |
|
2472 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
2473 | + $op_25 = $color_code."40"; // 25% opacity |
|
2474 | + |
|
2475 | + |
|
2476 | + // button states |
|
2477 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
2478 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2479 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
2480 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
2481 | + |
|
2482 | + |
|
2483 | + return $output; |
|
2484 | + } |
|
2485 | + |
|
2486 | + /** |
|
2487 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
2488 | + * |
|
2489 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
2490 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
2491 | + * |
|
2492 | + * @return string |
|
2493 | + */ |
|
2494 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
2495 | + $hexCode = ltrim($hexCode, '#'); |
|
2496 | + |
|
2497 | + if (strlen($hexCode) == 3) { |
|
2498 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
2499 | + } |
|
2500 | + |
|
2501 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
2502 | + |
|
2503 | + foreach ($hexCode as & $color) { |
|
2504 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
2505 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
2506 | + |
|
2507 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
2508 | + } |
|
2509 | + |
|
2510 | + return '#' . implode($hexCode); |
|
2511 | + } |
|
2512 | + |
|
2513 | + /** |
|
2514 | + * Check if we should display examples. |
|
2515 | + */ |
|
2516 | + public function maybe_show_examples(){ |
|
2517 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
2518 | + echo "<head>"; |
|
2519 | + wp_head(); |
|
2520 | + echo "</head>"; |
|
2521 | + echo "<body>"; |
|
2522 | + echo $this->get_examples(); |
|
2523 | + echo "</body>"; |
|
2524 | + exit; |
|
2525 | + } |
|
2526 | + } |
|
2527 | + |
|
2528 | + /** |
|
2529 | + * Get developer examples. |
|
2530 | + * |
|
2531 | + * @return string |
|
2532 | + */ |
|
2533 | + public function get_examples(){ |
|
2534 | + $output = ''; |
|
2535 | + |
|
2536 | + |
|
2537 | + // open form |
|
2538 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
2539 | + |
|
2540 | + // input example |
|
2541 | + $output .= aui()->input(array( |
|
2542 | + 'type' => 'text', |
|
2543 | + 'id' => 'text-example', |
|
2544 | + 'name' => 'text-example', |
|
2545 | + 'placeholder' => 'text placeholder', |
|
2546 | + 'title' => 'Text input example', |
|
2547 | + 'value' => '', |
|
2548 | + 'required' => false, |
|
2549 | + 'help_text' => 'help text', |
|
2550 | + 'label' => 'Text input example label' |
|
2551 | + )); |
|
2552 | + |
|
2553 | + // input example |
|
2554 | + $output .= aui()->input(array( |
|
2555 | + 'type' => 'url', |
|
2556 | + 'id' => 'text-example2', |
|
2557 | + 'name' => 'text-example', |
|
2558 | + 'placeholder' => 'url placeholder', |
|
2559 | + 'title' => 'Text input example', |
|
2560 | + 'value' => '', |
|
2561 | + 'required' => false, |
|
2562 | + 'help_text' => 'help text', |
|
2563 | + 'label' => 'Text input example label' |
|
2564 | + )); |
|
2565 | + |
|
2566 | + // checkbox example |
|
2567 | + $output .= aui()->input(array( |
|
2568 | + 'type' => 'checkbox', |
|
2569 | + 'id' => 'checkbox-example', |
|
2570 | + 'name' => 'checkbox-example', |
|
2571 | + 'placeholder' => 'checkbox-example', |
|
2572 | + 'title' => 'Checkbox example', |
|
2573 | + 'value' => '1', |
|
2574 | + 'checked' => true, |
|
2575 | + 'required' => false, |
|
2576 | + 'help_text' => 'help text', |
|
2577 | + 'label' => 'Checkbox checked' |
|
2578 | + )); |
|
2579 | + |
|
2580 | + // checkbox example |
|
2581 | + $output .= aui()->input(array( |
|
2582 | + 'type' => 'checkbox', |
|
2583 | + 'id' => 'checkbox-example2', |
|
2584 | + 'name' => 'checkbox-example2', |
|
2585 | + 'placeholder' => 'checkbox-example', |
|
2586 | + 'title' => 'Checkbox example', |
|
2587 | + 'value' => '1', |
|
2588 | + 'checked' => false, |
|
2589 | + 'required' => false, |
|
2590 | + 'help_text' => 'help text', |
|
2591 | + 'label' => 'Checkbox un-checked' |
|
2592 | + )); |
|
2593 | + |
|
2594 | + // switch example |
|
2595 | + $output .= aui()->input(array( |
|
2596 | + 'type' => 'checkbox', |
|
2597 | + 'id' => 'switch-example', |
|
2598 | + 'name' => 'switch-example', |
|
2599 | + 'placeholder' => 'checkbox-example', |
|
2600 | + 'title' => 'Switch example', |
|
2601 | + 'value' => '1', |
|
2602 | + 'checked' => true, |
|
2603 | + 'switch' => true, |
|
2604 | + 'required' => false, |
|
2605 | + 'help_text' => 'help text', |
|
2606 | + 'label' => 'Switch on' |
|
2607 | + )); |
|
2608 | + |
|
2609 | + // switch example |
|
2610 | + $output .= aui()->input(array( |
|
2611 | + 'type' => 'checkbox', |
|
2612 | + 'id' => 'switch-example2', |
|
2613 | + 'name' => 'switch-example2', |
|
2614 | + 'placeholder' => 'checkbox-example', |
|
2615 | + 'title' => 'Switch example', |
|
2616 | + 'value' => '1', |
|
2617 | + 'checked' => false, |
|
2618 | + 'switch' => true, |
|
2619 | + 'required' => false, |
|
2620 | + 'help_text' => 'help text', |
|
2621 | + 'label' => 'Switch off' |
|
2622 | + )); |
|
2623 | + |
|
2624 | + // close form |
|
2625 | + $output .= "</form>"; |
|
2626 | + |
|
2627 | + return $output; |
|
2628 | + } |
|
2629 | + |
|
2630 | + /** |
|
2631 | + * Calendar params. |
|
2632 | + * |
|
2633 | + * @since 0.1.44 |
|
2634 | + * |
|
2635 | + * @return array Calendar params. |
|
2636 | + */ |
|
2637 | + public static function calendar_params() { |
|
2638 | + $params = array( |
|
2639 | + 'month_long_1' => __( 'January', 'aui' ), |
|
2640 | + 'month_long_2' => __( 'February', 'aui' ), |
|
2641 | + 'month_long_3' => __( 'March', 'aui' ), |
|
2642 | + 'month_long_4' => __( 'April', 'aui' ), |
|
2643 | + 'month_long_5' => __( 'May', 'aui' ), |
|
2644 | + 'month_long_6' => __( 'June', 'aui' ), |
|
2645 | + 'month_long_7' => __( 'July', 'aui' ), |
|
2646 | + 'month_long_8' => __( 'August', 'aui' ), |
|
2647 | + 'month_long_9' => __( 'September', 'aui' ), |
|
2648 | + 'month_long_10' => __( 'October', 'aui' ), |
|
2649 | + 'month_long_11' => __( 'November', 'aui' ), |
|
2650 | + 'month_long_12' => __( 'December', 'aui' ), |
|
2651 | + 'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ), |
|
2652 | + 'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ), |
|
2653 | + 'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ), |
|
2654 | + 'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ), |
|
2655 | + 'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ), |
|
2656 | + 'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ), |
|
2657 | + 'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ), |
|
2658 | + 'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ), |
|
2659 | + 'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ), |
|
2660 | + 'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ), |
|
2661 | + 'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ), |
|
2662 | + 'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ), |
|
2663 | + 'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ), |
|
2664 | + 'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ), |
|
2665 | + 'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ), |
|
2666 | + 'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ), |
|
2667 | + 'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ), |
|
2668 | + 'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ), |
|
2669 | + 'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ), |
|
2670 | + 'day_s2_1' => __( 'Su', 'aui' ), |
|
2671 | + 'day_s2_2' => __( 'Mo', 'aui' ), |
|
2672 | + 'day_s2_3' => __( 'Tu', 'aui' ), |
|
2673 | + 'day_s2_4' => __( 'We', 'aui' ), |
|
2674 | + 'day_s2_5' => __( 'Th', 'aui' ), |
|
2675 | + 'day_s2_6' => __( 'Fr', 'aui' ), |
|
2676 | + 'day_s2_7' => __( 'Sa', 'aui' ), |
|
2677 | + 'day_s3_1' => __( 'Sun', 'aui' ), |
|
2678 | + 'day_s3_2' => __( 'Mon', 'aui' ), |
|
2679 | + 'day_s3_3' => __( 'Tue', 'aui' ), |
|
2680 | + 'day_s3_4' => __( 'Wed', 'aui' ), |
|
2681 | + 'day_s3_5' => __( 'Thu', 'aui' ), |
|
2682 | + 'day_s3_6' => __( 'Fri', 'aui' ), |
|
2683 | + 'day_s3_7' => __( 'Sat', 'aui' ), |
|
2684 | + 'day_s5_1' => __( 'Sunday', 'aui' ), |
|
2685 | + 'day_s5_2' => __( 'Monday', 'aui' ), |
|
2686 | + 'day_s5_3' => __( 'Tuesday', 'aui' ), |
|
2687 | + 'day_s5_4' => __( 'Wednesday', 'aui' ), |
|
2688 | + 'day_s5_5' => __( 'Thursday', 'aui' ), |
|
2689 | + 'day_s5_6' => __( 'Friday', 'aui' ), |
|
2690 | + 'day_s5_7' => __( 'Saturday', 'aui' ), |
|
2691 | + 'am_lower' => __( 'am', 'aui' ), |
|
2692 | + 'pm_lower' => __( 'pm', 'aui' ), |
|
2693 | + 'am_upper' => __( 'AM', 'aui' ), |
|
2694 | + 'pm_upper' => __( 'PM', 'aui' ), |
|
2695 | + 'firstDayOfWeek' => (int) get_option( 'start_of_week' ), |
|
2696 | + 'time_24hr' => false, |
|
2697 | + 'year' => __( 'Year', 'aui' ), |
|
2698 | + 'hour' => __( 'Hour', 'aui' ), |
|
2699 | + 'minute' => __( 'Minute', 'aui' ), |
|
2700 | + 'weekAbbreviation' => __( 'Wk', 'aui' ), |
|
2701 | + 'rangeSeparator' => __( ' to ', 'aui' ), |
|
2702 | + 'scrollTitle' => __( 'Scroll to increment', 'aui' ), |
|
2703 | + 'toggleTitle' => __( 'Click to toggle', 'aui' ) |
|
2704 | + ); |
|
2705 | + |
|
2706 | + return apply_filters( 'ayecode_ui_calendar_params', $params ); |
|
2707 | + } |
|
2708 | + |
|
2709 | + /** |
|
2710 | + * Flatpickr calendar localize. |
|
2711 | + * |
|
2712 | + * @since 0.1.44 |
|
2713 | + * |
|
2714 | + * @return string Calendar locale. |
|
2715 | + */ |
|
2716 | + public static function flatpickr_locale() { |
|
2717 | + $params = self::calendar_params(); |
|
2718 | + |
|
2719 | + if ( is_string( $params ) ) { |
|
2720 | + $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' ); |
|
2721 | + } else { |
|
2722 | + foreach ( (array) $params as $key => $value ) { |
|
2723 | + if ( ! is_scalar( $value ) ) { |
|
2724 | + continue; |
|
2725 | + } |
|
2726 | + |
|
2727 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2728 | + } |
|
2729 | + } |
|
2730 | 2730 | |
2731 | - $day_s3 = array(); |
|
2732 | - $day_s5 = array(); |
|
2731 | + $day_s3 = array(); |
|
2732 | + $day_s5 = array(); |
|
2733 | 2733 | |
2734 | - for ( $i = 1; $i <= 7; $i ++ ) { |
|
2735 | - $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
2736 | - $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
2737 | - } |
|
2734 | + for ( $i = 1; $i <= 7; $i ++ ) { |
|
2735 | + $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
2736 | + $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] ); |
|
2737 | + } |
|
2738 | 2738 | |
2739 | - $month_s = array(); |
|
2740 | - $month_long = array(); |
|
2739 | + $month_s = array(); |
|
2740 | + $month_long = array(); |
|
2741 | 2741 | |
2742 | - for ( $i = 1; $i <= 12; $i ++ ) { |
|
2743 | - $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
2744 | - $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
2745 | - } |
|
2742 | + for ( $i = 1; $i <= 12; $i ++ ) { |
|
2743 | + $month_s[] = addslashes( $params[ 'month_s_' . $i ] ); |
|
2744 | + $month_long[] = addslashes( $params[ 'month_long_' . $i ] ); |
|
2745 | + } |
|
2746 | 2746 | |
2747 | - ob_start(); |
|
2748 | - if ( 0 ) { ?><script><?php } ?> |
|
2747 | + ob_start(); |
|
2748 | + if ( 0 ) { ?><script><?php } ?> |
|
2749 | 2749 | { |
2750 | 2750 | weekdays: { |
2751 | 2751 | shorthand: ['<?php echo implode( "','", $day_s3 ); ?>'], |
@@ -2784,189 +2784,189 @@ discard block |
||
2784 | 2784 | } |
2785 | 2785 | <?php if ( 0 ) { ?></script><?php } ?> |
2786 | 2786 | <?php |
2787 | - $locale = ob_get_clean(); |
|
2788 | - |
|
2789 | - return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
2790 | - } |
|
2791 | - |
|
2792 | - /** |
|
2793 | - * Select2 JS params. |
|
2794 | - * |
|
2795 | - * @since 0.1.44 |
|
2796 | - * |
|
2797 | - * @return array Select2 JS params. |
|
2798 | - */ |
|
2799 | - public static function select2_params() { |
|
2800 | - $params = array( |
|
2801 | - 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
2802 | - 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
2803 | - 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
2804 | - 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
2805 | - 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
2806 | - 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
2807 | - 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
2808 | - 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
2809 | - 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
2810 | - 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
2811 | - 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
2812 | - ); |
|
2813 | - |
|
2814 | - return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
2815 | - } |
|
2816 | - |
|
2817 | - /** |
|
2818 | - * Select2 JS localize. |
|
2819 | - * |
|
2820 | - * @since 0.1.44 |
|
2821 | - * |
|
2822 | - * @return string Select2 JS locale. |
|
2823 | - */ |
|
2824 | - public static function select2_locale() { |
|
2825 | - $params = self::select2_params(); |
|
2826 | - |
|
2827 | - foreach ( (array) $params as $key => $value ) { |
|
2828 | - if ( ! is_scalar( $value ) ) { |
|
2829 | - continue; |
|
2830 | - } |
|
2787 | + $locale = ob_get_clean(); |
|
2788 | + |
|
2789 | + return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) ); |
|
2790 | + } |
|
2791 | + |
|
2792 | + /** |
|
2793 | + * Select2 JS params. |
|
2794 | + * |
|
2795 | + * @since 0.1.44 |
|
2796 | + * |
|
2797 | + * @return array Select2 JS params. |
|
2798 | + */ |
|
2799 | + public static function select2_params() { |
|
2800 | + $params = array( |
|
2801 | + 'i18n_select_state_text' => esc_attr__( 'Select an option…', 'aui' ), |
|
2802 | + 'i18n_no_matches' => _x( 'No matches found', 'enhanced select', 'aui' ), |
|
2803 | + 'i18n_ajax_error' => _x( 'Loading failed', 'enhanced select', 'aui' ), |
|
2804 | + 'i18n_input_too_short_1' => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ), |
|
2805 | + 'i18n_input_too_short_n' => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ), |
|
2806 | + 'i18n_input_too_long_1' => _x( 'Please delete 1 character', 'enhanced select', 'aui' ), |
|
2807 | + 'i18n_input_too_long_n' => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ), |
|
2808 | + 'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ), |
|
2809 | + 'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ), |
|
2810 | + 'i18n_load_more' => _x( 'Loading more results…', 'enhanced select', 'aui' ), |
|
2811 | + 'i18n_searching' => _x( 'Searching…', 'enhanced select', 'aui' ) |
|
2812 | + ); |
|
2813 | + |
|
2814 | + return apply_filters( 'ayecode_ui_select2_params', $params ); |
|
2815 | + } |
|
2816 | + |
|
2817 | + /** |
|
2818 | + * Select2 JS localize. |
|
2819 | + * |
|
2820 | + * @since 0.1.44 |
|
2821 | + * |
|
2822 | + * @return string Select2 JS locale. |
|
2823 | + */ |
|
2824 | + public static function select2_locale() { |
|
2825 | + $params = self::select2_params(); |
|
2826 | + |
|
2827 | + foreach ( (array) $params as $key => $value ) { |
|
2828 | + if ( ! is_scalar( $value ) ) { |
|
2829 | + continue; |
|
2830 | + } |
|
2831 | 2831 | |
2832 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2833 | - } |
|
2834 | - |
|
2835 | - $locale = json_encode( $params ); |
|
2836 | - |
|
2837 | - return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
2838 | - } |
|
2839 | - |
|
2840 | - /** |
|
2841 | - * Time ago JS localize. |
|
2842 | - * |
|
2843 | - * @since 0.1.47 |
|
2844 | - * |
|
2845 | - * @return string Time ago JS locale. |
|
2846 | - */ |
|
2847 | - public static function timeago_locale() { |
|
2848 | - $params = array( |
|
2849 | - 'prefix_ago' => '', |
|
2850 | - 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ), |
|
2851 | - 'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ', |
|
2852 | - 'suffix_after' => '', |
|
2853 | - 'seconds' => _x( 'less than a minute', 'time ago', 'aui' ), |
|
2854 | - 'minute' => _x( 'about a minute', 'time ago', 'aui' ), |
|
2855 | - 'minutes' => _x( '%d minutes', 'time ago', 'aui' ), |
|
2856 | - 'hour' => _x( 'about an hour', 'time ago', 'aui' ), |
|
2857 | - 'hours' => _x( 'about %d hours', 'time ago', 'aui' ), |
|
2858 | - 'day' => _x( 'a day', 'time ago', 'aui' ), |
|
2859 | - 'days' => _x( '%d days', 'time ago', 'aui' ), |
|
2860 | - 'month' => _x( 'about a month', 'time ago', 'aui' ), |
|
2861 | - 'months' => _x( '%d months', 'time ago', 'aui' ), |
|
2862 | - 'year' => _x( 'about a year', 'time ago', 'aui' ), |
|
2863 | - 'years' => _x( '%d years', 'time ago', 'aui' ), |
|
2864 | - ); |
|
2865 | - |
|
2866 | - $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
|
2867 | - |
|
2868 | - foreach ( (array) $params as $key => $value ) { |
|
2869 | - if ( ! is_scalar( $value ) ) { |
|
2870 | - continue; |
|
2871 | - } |
|
2832 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2833 | + } |
|
2834 | + |
|
2835 | + $locale = json_encode( $params ); |
|
2836 | + |
|
2837 | + return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) ); |
|
2838 | + } |
|
2839 | + |
|
2840 | + /** |
|
2841 | + * Time ago JS localize. |
|
2842 | + * |
|
2843 | + * @since 0.1.47 |
|
2844 | + * |
|
2845 | + * @return string Time ago JS locale. |
|
2846 | + */ |
|
2847 | + public static function timeago_locale() { |
|
2848 | + $params = array( |
|
2849 | + 'prefix_ago' => '', |
|
2850 | + 'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ), |
|
2851 | + 'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ', |
|
2852 | + 'suffix_after' => '', |
|
2853 | + 'seconds' => _x( 'less than a minute', 'time ago', 'aui' ), |
|
2854 | + 'minute' => _x( 'about a minute', 'time ago', 'aui' ), |
|
2855 | + 'minutes' => _x( '%d minutes', 'time ago', 'aui' ), |
|
2856 | + 'hour' => _x( 'about an hour', 'time ago', 'aui' ), |
|
2857 | + 'hours' => _x( 'about %d hours', 'time ago', 'aui' ), |
|
2858 | + 'day' => _x( 'a day', 'time ago', 'aui' ), |
|
2859 | + 'days' => _x( '%d days', 'time ago', 'aui' ), |
|
2860 | + 'month' => _x( 'about a month', 'time ago', 'aui' ), |
|
2861 | + 'months' => _x( '%d months', 'time ago', 'aui' ), |
|
2862 | + 'year' => _x( 'about a year', 'time ago', 'aui' ), |
|
2863 | + 'years' => _x( '%d years', 'time ago', 'aui' ), |
|
2864 | + ); |
|
2865 | + |
|
2866 | + $params = apply_filters( 'ayecode_ui_timeago_params', $params ); |
|
2867 | + |
|
2868 | + foreach ( (array) $params as $key => $value ) { |
|
2869 | + if ( ! is_scalar( $value ) ) { |
|
2870 | + continue; |
|
2871 | + } |
|
2872 | 2872 | |
2873 | - $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2874 | - } |
|
2875 | - |
|
2876 | - $locale = json_encode( $params ); |
|
2877 | - |
|
2878 | - return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
|
2879 | - } |
|
2880 | - |
|
2881 | - /** |
|
2882 | - * JavaScript Minifier |
|
2883 | - * |
|
2884 | - * @param $input |
|
2885 | - * |
|
2886 | - * @return mixed |
|
2887 | - */ |
|
2888 | - public static function minify_js($input) { |
|
2889 | - if(trim($input) === "") return $input; |
|
2890 | - return preg_replace( |
|
2891 | - array( |
|
2892 | - // Remove comment(s) |
|
2893 | - '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
|
2894 | - // Remove white-space(s) outside the string and regex |
|
2895 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
|
2896 | - // Remove the last semicolon |
|
2897 | - '#;+\}#', |
|
2898 | - // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
|
2899 | - '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
|
2900 | - // --ibid. From `foo['bar']` to `foo.bar` |
|
2901 | - '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
|
2902 | - ), |
|
2903 | - array( |
|
2904 | - '$1', |
|
2905 | - '$1$2', |
|
2906 | - '}', |
|
2907 | - '$1$3', |
|
2908 | - '$1.$3' |
|
2909 | - ), |
|
2910 | - $input); |
|
2911 | - } |
|
2912 | - |
|
2913 | - /** |
|
2914 | - * Minify CSS |
|
2915 | - * |
|
2916 | - * @param $input |
|
2917 | - * |
|
2918 | - * @return mixed |
|
2919 | - */ |
|
2920 | - public static function minify_css($input) { |
|
2921 | - if(trim($input) === "") return $input; |
|
2922 | - return preg_replace( |
|
2923 | - array( |
|
2924 | - // Remove comment(s) |
|
2925 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', |
|
2926 | - // Remove unused white-space(s) |
|
2927 | - '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', |
|
2928 | - // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` |
|
2929 | - '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', |
|
2930 | - // Replace `:0 0 0 0` with `:0` |
|
2931 | - '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', |
|
2932 | - // Replace `background-position:0` with `background-position:0 0` |
|
2933 | - '#(background-position):0(?=[;\}])#si', |
|
2934 | - // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space |
|
2935 | - '#(?<=[\s:,\-])0+\.(\d+)#s', |
|
2936 | - // Minify string value |
|
2937 | - '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', |
|
2938 | - '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', |
|
2939 | - // Minify HEX color code |
|
2940 | - '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', |
|
2941 | - // Replace `(border|outline):none` with `(border|outline):0` |
|
2942 | - '#(?<=[\{;])(border|outline):none(?=[;\}\!])#', |
|
2943 | - // Remove empty selector(s) |
|
2944 | - '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' |
|
2945 | - ), |
|
2946 | - array( |
|
2947 | - '$1', |
|
2948 | - '$1$2$3$4$5$6$7', |
|
2949 | - '$1', |
|
2950 | - ':0', |
|
2951 | - '$1:0 0', |
|
2952 | - '.$1', |
|
2953 | - '$1$3', |
|
2954 | - '$1$2$4$5', |
|
2955 | - '$1$2$3', |
|
2956 | - '$1:0', |
|
2957 | - '$1$2' |
|
2958 | - ), |
|
2959 | - $input); |
|
2960 | - } |
|
2961 | - |
|
2962 | - /** |
|
2963 | - * Get the conditional fields JavaScript. |
|
2964 | - * |
|
2965 | - * @return mixed |
|
2966 | - */ |
|
2967 | - public function conditional_fields_js() { |
|
2968 | - ob_start(); |
|
2969 | - ?> |
|
2873 | + $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' ); |
|
2874 | + } |
|
2875 | + |
|
2876 | + $locale = json_encode( $params ); |
|
2877 | + |
|
2878 | + return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) ); |
|
2879 | + } |
|
2880 | + |
|
2881 | + /** |
|
2882 | + * JavaScript Minifier |
|
2883 | + * |
|
2884 | + * @param $input |
|
2885 | + * |
|
2886 | + * @return mixed |
|
2887 | + */ |
|
2888 | + public static function minify_js($input) { |
|
2889 | + if(trim($input) === "") return $input; |
|
2890 | + return preg_replace( |
|
2891 | + array( |
|
2892 | + // Remove comment(s) |
|
2893 | + '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
|
2894 | + // Remove white-space(s) outside the string and regex |
|
2895 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
|
2896 | + // Remove the last semicolon |
|
2897 | + '#;+\}#', |
|
2898 | + // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
|
2899 | + '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
|
2900 | + // --ibid. From `foo['bar']` to `foo.bar` |
|
2901 | + '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
|
2902 | + ), |
|
2903 | + array( |
|
2904 | + '$1', |
|
2905 | + '$1$2', |
|
2906 | + '}', |
|
2907 | + '$1$3', |
|
2908 | + '$1.$3' |
|
2909 | + ), |
|
2910 | + $input); |
|
2911 | + } |
|
2912 | + |
|
2913 | + /** |
|
2914 | + * Minify CSS |
|
2915 | + * |
|
2916 | + * @param $input |
|
2917 | + * |
|
2918 | + * @return mixed |
|
2919 | + */ |
|
2920 | + public static function minify_css($input) { |
|
2921 | + if(trim($input) === "") return $input; |
|
2922 | + return preg_replace( |
|
2923 | + array( |
|
2924 | + // Remove comment(s) |
|
2925 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s', |
|
2926 | + // Remove unused white-space(s) |
|
2927 | + '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si', |
|
2928 | + // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0` |
|
2929 | + '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si', |
|
2930 | + // Replace `:0 0 0 0` with `:0` |
|
2931 | + '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i', |
|
2932 | + // Replace `background-position:0` with `background-position:0 0` |
|
2933 | + '#(background-position):0(?=[;\}])#si', |
|
2934 | + // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space |
|
2935 | + '#(?<=[\s:,\-])0+\.(\d+)#s', |
|
2936 | + // Minify string value |
|
2937 | + '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si', |
|
2938 | + '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si', |
|
2939 | + // Minify HEX color code |
|
2940 | + '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i', |
|
2941 | + // Replace `(border|outline):none` with `(border|outline):0` |
|
2942 | + '#(?<=[\{;])(border|outline):none(?=[;\}\!])#', |
|
2943 | + // Remove empty selector(s) |
|
2944 | + '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s' |
|
2945 | + ), |
|
2946 | + array( |
|
2947 | + '$1', |
|
2948 | + '$1$2$3$4$5$6$7', |
|
2949 | + '$1', |
|
2950 | + ':0', |
|
2951 | + '$1:0 0', |
|
2952 | + '.$1', |
|
2953 | + '$1$3', |
|
2954 | + '$1$2$4$5', |
|
2955 | + '$1$2$3', |
|
2956 | + '$1:0', |
|
2957 | + '$1$2' |
|
2958 | + ), |
|
2959 | + $input); |
|
2960 | + } |
|
2961 | + |
|
2962 | + /** |
|
2963 | + * Get the conditional fields JavaScript. |
|
2964 | + * |
|
2965 | + * @return mixed |
|
2966 | + */ |
|
2967 | + public function conditional_fields_js() { |
|
2968 | + ob_start(); |
|
2969 | + ?> |
|
2970 | 2970 | <script> |
2971 | 2971 | /** |
2972 | 2972 | * Conditional Fields |
@@ -3469,14 +3469,14 @@ discard block |
||
3469 | 3469 | <?php do_action( 'aui_conditional_fields_js', $this ); ?> |
3470 | 3470 | </script> |
3471 | 3471 | <?php |
3472 | - $output = ob_get_clean(); |
|
3472 | + $output = ob_get_clean(); |
|
3473 | 3473 | |
3474 | - return str_replace( array( '<script>', '</script>' ), '', self::minify_js( $output ) ); |
|
3475 | - } |
|
3476 | - } |
|
3474 | + return str_replace( array( '<script>', '</script>' ), '', self::minify_js( $output ) ); |
|
3475 | + } |
|
3476 | + } |
|
3477 | 3477 | |
3478 | - /** |
|
3479 | - * Run the class if found. |
|
3480 | - */ |
|
3481 | - AyeCode_UI_Settings::instance(); |
|
3478 | + /** |
|
3479 | + * Run the class if found. |
|
3480 | + */ |
|
3481 | + AyeCode_UI_Settings::instance(); |
|
3482 | 3482 | } |
3483 | 3483 | \ No newline at end of file |