@@ -13,449 +13,449 @@ discard block |
||
13 | 13 | */ |
14 | 14 | abstract class GetPaid_Payment_Gateway { |
15 | 15 | |
16 | - /** |
|
17 | - * Set if the place checkout button should be renamed on selection. |
|
18 | - * |
|
19 | - * @var string |
|
20 | - */ |
|
21 | - public $checkout_button_text; |
|
22 | - |
|
23 | - /** |
|
24 | - * Boolean whether the method is enabled. |
|
25 | - * |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - public $enabled = true; |
|
29 | - |
|
30 | - /** |
|
31 | - * Payment method id. |
|
32 | - * |
|
33 | - * @var string |
|
34 | - */ |
|
35 | - public $id; |
|
36 | - |
|
37 | - /** |
|
38 | - * Payment method order. |
|
39 | - * |
|
40 | - * @var int |
|
41 | - */ |
|
42 | - public $order = 10; |
|
43 | - |
|
44 | - /** |
|
45 | - * Payment method title for the frontend. |
|
46 | - * |
|
47 | - * @var string |
|
48 | - */ |
|
49 | - public $title; |
|
50 | - |
|
51 | - /** |
|
52 | - * Payment method description for the frontend. |
|
53 | - * |
|
54 | - * @var string |
|
55 | - */ |
|
56 | - public $description; |
|
57 | - |
|
58 | - /** |
|
59 | - * Gateway title. |
|
60 | - * |
|
61 | - * @var string |
|
62 | - */ |
|
63 | - public $method_title = ''; |
|
64 | - |
|
65 | - /** |
|
66 | - * Gateway description. |
|
67 | - * |
|
68 | - * @var string |
|
69 | - */ |
|
70 | - public $method_description = ''; |
|
71 | - |
|
72 | - /** |
|
73 | - * Countries this gateway is allowed for. |
|
74 | - * |
|
75 | - * @var array |
|
76 | - */ |
|
77 | - public $countries; |
|
78 | - |
|
79 | - /** |
|
80 | - * Currencies this gateway is allowed for. |
|
81 | - * |
|
82 | - * @var array |
|
83 | - */ |
|
84 | - public $currencies; |
|
85 | - |
|
86 | - /** |
|
87 | - * Currencies this gateway is not allowed for. |
|
88 | - * |
|
89 | - * @var array |
|
90 | - */ |
|
91 | - public $exclude_currencies; |
|
92 | - |
|
93 | - /** |
|
94 | - * Maximum transaction amount, zero does not define a maximum. |
|
95 | - * |
|
96 | - * @var int |
|
97 | - */ |
|
98 | - public $max_amount = 0; |
|
99 | - |
|
100 | - /** |
|
101 | - * Optional URL to view a transaction. |
|
102 | - * |
|
103 | - * @var string |
|
104 | - */ |
|
105 | - public $view_transaction_url = ''; |
|
106 | - |
|
107 | - /** |
|
108 | - * Optional URL to view a subscription. |
|
109 | - * |
|
110 | - * @var string |
|
111 | - */ |
|
112 | - public $view_subscription_url = ''; |
|
113 | - |
|
114 | - /** |
|
115 | - * Optional label to show for "new payment method" in the payment |
|
116 | - * method/token selection radio selection. |
|
117 | - * |
|
118 | - * @var string |
|
119 | - */ |
|
120 | - public $new_method_label = ''; |
|
121 | - |
|
122 | - /** |
|
123 | - * Contains a user's saved tokens for this gateway. |
|
124 | - * |
|
125 | - * @var array |
|
126 | - */ |
|
127 | - protected $tokens = array(); |
|
128 | - |
|
129 | - /** |
|
130 | - * An array of features that this gateway supports. |
|
131 | - * |
|
132 | - * @var array |
|
133 | - */ |
|
134 | - protected $supports = array(); |
|
135 | - |
|
136 | - /** |
|
137 | - * Class constructor. |
|
138 | - */ |
|
139 | - public function __construct() { |
|
140 | - $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
141 | - |
|
142 | - // Register gateway. |
|
143 | - add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
144 | - |
|
145 | - // Enable Subscriptions. |
|
146 | - if ( $this->supports( 'subscription' ) ) { |
|
147 | - add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
148 | - } |
|
149 | - |
|
150 | - // Enable sandbox. |
|
151 | - if ( $this->supports( 'sandbox' ) ) { |
|
152 | - add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
153 | - } |
|
154 | - |
|
155 | - // Gateway settings. |
|
156 | - add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
16 | + /** |
|
17 | + * Set if the place checkout button should be renamed on selection. |
|
18 | + * |
|
19 | + * @var string |
|
20 | + */ |
|
21 | + public $checkout_button_text; |
|
22 | + |
|
23 | + /** |
|
24 | + * Boolean whether the method is enabled. |
|
25 | + * |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + public $enabled = true; |
|
29 | + |
|
30 | + /** |
|
31 | + * Payment method id. |
|
32 | + * |
|
33 | + * @var string |
|
34 | + */ |
|
35 | + public $id; |
|
36 | + |
|
37 | + /** |
|
38 | + * Payment method order. |
|
39 | + * |
|
40 | + * @var int |
|
41 | + */ |
|
42 | + public $order = 10; |
|
43 | + |
|
44 | + /** |
|
45 | + * Payment method title for the frontend. |
|
46 | + * |
|
47 | + * @var string |
|
48 | + */ |
|
49 | + public $title; |
|
50 | + |
|
51 | + /** |
|
52 | + * Payment method description for the frontend. |
|
53 | + * |
|
54 | + * @var string |
|
55 | + */ |
|
56 | + public $description; |
|
57 | + |
|
58 | + /** |
|
59 | + * Gateway title. |
|
60 | + * |
|
61 | + * @var string |
|
62 | + */ |
|
63 | + public $method_title = ''; |
|
64 | + |
|
65 | + /** |
|
66 | + * Gateway description. |
|
67 | + * |
|
68 | + * @var string |
|
69 | + */ |
|
70 | + public $method_description = ''; |
|
71 | + |
|
72 | + /** |
|
73 | + * Countries this gateway is allowed for. |
|
74 | + * |
|
75 | + * @var array |
|
76 | + */ |
|
77 | + public $countries; |
|
78 | + |
|
79 | + /** |
|
80 | + * Currencies this gateway is allowed for. |
|
81 | + * |
|
82 | + * @var array |
|
83 | + */ |
|
84 | + public $currencies; |
|
85 | + |
|
86 | + /** |
|
87 | + * Currencies this gateway is not allowed for. |
|
88 | + * |
|
89 | + * @var array |
|
90 | + */ |
|
91 | + public $exclude_currencies; |
|
92 | + |
|
93 | + /** |
|
94 | + * Maximum transaction amount, zero does not define a maximum. |
|
95 | + * |
|
96 | + * @var int |
|
97 | + */ |
|
98 | + public $max_amount = 0; |
|
99 | + |
|
100 | + /** |
|
101 | + * Optional URL to view a transaction. |
|
102 | + * |
|
103 | + * @var string |
|
104 | + */ |
|
105 | + public $view_transaction_url = ''; |
|
106 | + |
|
107 | + /** |
|
108 | + * Optional URL to view a subscription. |
|
109 | + * |
|
110 | + * @var string |
|
111 | + */ |
|
112 | + public $view_subscription_url = ''; |
|
113 | + |
|
114 | + /** |
|
115 | + * Optional label to show for "new payment method" in the payment |
|
116 | + * method/token selection radio selection. |
|
117 | + * |
|
118 | + * @var string |
|
119 | + */ |
|
120 | + public $new_method_label = ''; |
|
121 | + |
|
122 | + /** |
|
123 | + * Contains a user's saved tokens for this gateway. |
|
124 | + * |
|
125 | + * @var array |
|
126 | + */ |
|
127 | + protected $tokens = array(); |
|
128 | + |
|
129 | + /** |
|
130 | + * An array of features that this gateway supports. |
|
131 | + * |
|
132 | + * @var array |
|
133 | + */ |
|
134 | + protected $supports = array(); |
|
135 | + |
|
136 | + /** |
|
137 | + * Class constructor. |
|
138 | + */ |
|
139 | + public function __construct() { |
|
140 | + $this->enabled = wpinv_is_gateway_active( $this->id ); |
|
141 | + |
|
142 | + // Register gateway. |
|
143 | + add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) ); |
|
144 | + |
|
145 | + // Enable Subscriptions. |
|
146 | + if ( $this->supports( 'subscription' ) ) { |
|
147 | + add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' ); |
|
148 | + } |
|
149 | + |
|
150 | + // Enable sandbox. |
|
151 | + if ( $this->supports( 'sandbox' ) ) { |
|
152 | + add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' ); |
|
153 | + } |
|
154 | + |
|
155 | + // Gateway settings. |
|
156 | + add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) ); |
|
157 | 157 | |
158 | 158 | |
159 | - // Gateway checkout fiellds. |
|
160 | - add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
161 | - |
|
162 | - // Process payment. |
|
163 | - add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
159 | + // Gateway checkout fiellds. |
|
160 | + add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 ); |
|
161 | + |
|
162 | + // Process payment. |
|
163 | + add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 ); |
|
164 | + |
|
165 | + // Change the checkout button text. |
|
166 | + if ( ! empty( $this->checkout_button_text ) ) { |
|
167 | + add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | + } |
|
169 | + |
|
170 | + // Check if a gateway is valid for a given currency. |
|
171 | + add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
172 | + |
|
173 | + // Generate the transaction url. |
|
174 | + add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
175 | + |
|
176 | + // Generate the subscription url. |
|
177 | + add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
178 | + |
|
179 | + // Confirm payments. |
|
180 | + add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
181 | + |
|
182 | + // Verify IPNs. |
|
183 | + add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
184 | + |
|
185 | + } |
|
186 | + |
|
187 | + /** |
|
188 | + * Checks if this gateway is a given gateway. |
|
189 | + * |
|
190 | + * @since 1.0.19 |
|
191 | + * @return bool |
|
192 | + */ |
|
193 | + public function is( $gateway ) { |
|
194 | + return $gateway == $this->id; |
|
195 | + } |
|
196 | + |
|
197 | + /** |
|
198 | + * Returns a users saved tokens for this gateway. |
|
199 | + * |
|
200 | + * @since 1.0.19 |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public function get_tokens( $sandbox = null ) { |
|
204 | + |
|
205 | + if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
206 | + $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | + |
|
208 | + if ( is_array( $tokens ) ) { |
|
209 | + $this->tokens = $tokens; |
|
210 | + } |
|
211 | + |
|
212 | + } |
|
213 | + |
|
214 | + if ( ! is_bool( $sandbox ) ) { |
|
215 | + return $this->tokens; |
|
216 | + } |
|
217 | + |
|
218 | + $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
219 | + return wp_list_filter( $this->tokens, $args ); |
|
220 | + |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Saves a token for this gateway. |
|
225 | + * |
|
226 | + * @since 1.0.19 |
|
227 | + */ |
|
228 | + public function save_token( $token ) { |
|
229 | + |
|
230 | + $tokens = $this->get_tokens(); |
|
231 | + $tokens[] = $token; |
|
232 | + |
|
233 | + update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
234 | + |
|
235 | + $this->tokens = $tokens; |
|
236 | + |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Return the title for admin screens. |
|
241 | + * |
|
242 | + * @return string |
|
243 | + */ |
|
244 | + public function get_method_title() { |
|
245 | + return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Return the description for admin screens. |
|
250 | + * |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function get_method_description() { |
|
254 | + return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * Get the success url. |
|
259 | + * |
|
260 | + * @param WPInv_Invoice $invoice Invoice object. |
|
261 | + * @return string |
|
262 | + */ |
|
263 | + public function get_return_url( $invoice ) { |
|
264 | + |
|
265 | + // Payment success url |
|
266 | + $return_url = add_query_arg( |
|
267 | + array( |
|
268 | + 'payment-confirm' => $this->id, |
|
269 | + 'invoice_key' => $invoice->get_key(), |
|
270 | + 'utm_nooverride' => 1 |
|
271 | + ), |
|
272 | + wpinv_get_success_page_uri() |
|
273 | + ); |
|
274 | + |
|
275 | + return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Confirms payments when rendering the success page. |
|
280 | + * |
|
281 | + * @param string $content Success page content. |
|
282 | + * @return string |
|
283 | + */ |
|
284 | + public function confirm_payment( $content ) { |
|
285 | + |
|
286 | + // Retrieve the invoice. |
|
287 | + $invoice_id = getpaid_get_current_invoice_id(); |
|
288 | + $invoice = wpinv_get_invoice( $invoice_id ); |
|
289 | + |
|
290 | + // Ensure that it exists and that it is pending payment. |
|
291 | + if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
292 | + return $content; |
|
293 | + } |
|
294 | + |
|
295 | + // Can the user view this invoice?? |
|
296 | + if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
297 | + return $content; |
|
298 | + } |
|
299 | + |
|
300 | + // Show payment processing indicator. |
|
301 | + return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Processes ipns and marks payments as complete. |
|
306 | + * |
|
307 | + * @return void |
|
308 | + */ |
|
309 | + public function verify_ipn() {} |
|
310 | + |
|
311 | + /** |
|
312 | + * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
313 | + * |
|
314 | + * @param string $transaction_url transaction url. |
|
315 | + * @param WPInv_Invoice $invoice Invoice object. |
|
316 | + * @return string transaction URL, or empty string. |
|
317 | + */ |
|
318 | + public function filter_transaction_url( $transaction_url, $invoice ) { |
|
319 | + |
|
320 | + $transaction_id = $invoice->get_transaction_id(); |
|
321 | + |
|
322 | + if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
323 | + $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
324 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
325 | + $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
326 | + } |
|
327 | + |
|
328 | + return $transaction_url; |
|
329 | + } |
|
330 | + |
|
331 | + /** |
|
332 | + * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
333 | + * |
|
334 | + * @param string $subscription_url transaction url. |
|
335 | + * @param WPInv_Invoice $invoice Invoice object. |
|
336 | + * @return string subscription URL, or empty string. |
|
337 | + */ |
|
338 | + public function filter_subscription_url( $subscription_url, $invoice ) { |
|
339 | + |
|
340 | + $profile_id = $invoice->get_subscription_id(); |
|
341 | + |
|
342 | + if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
343 | + |
|
344 | + $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
345 | + $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
346 | + $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
347 | + |
|
348 | + } |
|
349 | + |
|
350 | + return $subscription_url; |
|
351 | + } |
|
352 | + |
|
353 | + /** |
|
354 | + * Check if the gateway is available for use. |
|
355 | + * |
|
356 | + * @return bool |
|
357 | + */ |
|
358 | + public function is_available() { |
|
359 | + return ! empty( $this->enabled ); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Return the gateway's title. |
|
364 | + * |
|
365 | + * @return string |
|
366 | + */ |
|
367 | + public function get_title() { |
|
368 | + return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Return the gateway's description. |
|
373 | + * |
|
374 | + * @return string |
|
375 | + */ |
|
376 | + public function get_description() { |
|
377 | + return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
378 | + } |
|
379 | + |
|
380 | + /** |
|
381 | + * Process Payment. |
|
382 | + * |
|
383 | + * |
|
384 | + * @param WPInv_Invoice $invoice Invoice. |
|
385 | + * @param array $submission_data Posted checkout fields. |
|
386 | + * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
387 | + * @return void |
|
388 | + */ |
|
389 | + public function process_payment( $invoice, $submission_data, $submission ) { |
|
390 | + // Process the payment then either redirect to the success page or the gateway. |
|
391 | + do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
392 | + } |
|
393 | + |
|
394 | + /** |
|
395 | + * Process refund. |
|
396 | + * |
|
397 | + * If the gateway declares 'refunds' support, this will allow it to refund. |
|
398 | + * a passed in amount. |
|
399 | + * |
|
400 | + * @param WPInv_Invoice $invoice Invoice. |
|
401 | + * @param float $amount Refund amount. |
|
402 | + * @param string $reason Refund reason. |
|
403 | + * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
404 | + */ |
|
405 | + public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
406 | + return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
407 | + } |
|
408 | + |
|
409 | + /** |
|
410 | + * Displays the payment fields, credit cards etc. |
|
411 | + * |
|
412 | + * @param int $invoice_id 0 or invoice id. |
|
413 | + * @param GetPaid_Payment_Form $form Current payment form. |
|
414 | + */ |
|
415 | + public function payment_fields( $invoice_id, $form ) { |
|
416 | + do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Filters the gateway settings. |
|
421 | + * |
|
422 | + * @param array $admin_settings |
|
423 | + */ |
|
424 | + public function admin_settings( $admin_settings ) { |
|
425 | + return $admin_settings; |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Retrieves the value of a gateway setting. |
|
430 | + * |
|
431 | + * @param string $option |
|
432 | + */ |
|
433 | + public function get_option( $option, $default = false ) { |
|
434 | + return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
435 | + } |
|
436 | + |
|
437 | + /** |
|
438 | + * Check if a gateway supports a given feature. |
|
439 | + * |
|
440 | + * Gateways should override this to declare support (or lack of support) for a feature. |
|
441 | + * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
442 | + * |
|
443 | + * @param string $feature string The name of a feature to test support for. |
|
444 | + * @return bool True if the gateway supports the feature, false otherwise. |
|
445 | + * @since 1.0.19 |
|
446 | + */ |
|
447 | + public function supports( $feature ) { |
|
448 | + return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
449 | + } |
|
164 | 450 | |
165 | - // Change the checkout button text. |
|
166 | - if ( ! empty( $this->checkout_button_text ) ) { |
|
167 | - add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) ); |
|
168 | - } |
|
169 | - |
|
170 | - // Check if a gateway is valid for a given currency. |
|
171 | - add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 ); |
|
172 | - |
|
173 | - // Generate the transaction url. |
|
174 | - add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 ); |
|
175 | - |
|
176 | - // Generate the subscription url. |
|
177 | - add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 ); |
|
178 | - |
|
179 | - // Confirm payments. |
|
180 | - add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 ); |
|
181 | - |
|
182 | - // Verify IPNs. |
|
183 | - add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) ); |
|
184 | - |
|
185 | - } |
|
186 | - |
|
187 | - /** |
|
188 | - * Checks if this gateway is a given gateway. |
|
189 | - * |
|
190 | - * @since 1.0.19 |
|
191 | - * @return bool |
|
192 | - */ |
|
193 | - public function is( $gateway ) { |
|
194 | - return $gateway == $this->id; |
|
195 | - } |
|
196 | - |
|
197 | - /** |
|
198 | - * Returns a users saved tokens for this gateway. |
|
199 | - * |
|
200 | - * @since 1.0.19 |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public function get_tokens( $sandbox = null ) { |
|
204 | - |
|
205 | - if ( is_user_logged_in() && $this->supports( 'tokens' ) && 0 == count( $this->tokens ) ) { |
|
206 | - $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true ); |
|
207 | - |
|
208 | - if ( is_array( $tokens ) ) { |
|
209 | - $this->tokens = $tokens; |
|
210 | - } |
|
211 | - |
|
212 | - } |
|
213 | - |
|
214 | - if ( ! is_bool( $sandbox ) ) { |
|
215 | - return $this->tokens; |
|
216 | - } |
|
217 | - |
|
218 | - $args = array( 'type' => $sandbox ? 'sandbox' : 'live' ); |
|
219 | - return wp_list_filter( $this->tokens, $args ); |
|
220 | - |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Saves a token for this gateway. |
|
225 | - * |
|
226 | - * @since 1.0.19 |
|
227 | - */ |
|
228 | - public function save_token( $token ) { |
|
229 | - |
|
230 | - $tokens = $this->get_tokens(); |
|
231 | - $tokens[] = $token; |
|
232 | - |
|
233 | - update_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", $tokens ); |
|
234 | - |
|
235 | - $this->tokens = $tokens; |
|
236 | - |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Return the title for admin screens. |
|
241 | - * |
|
242 | - * @return string |
|
243 | - */ |
|
244 | - public function get_method_title() { |
|
245 | - return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this ); |
|
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Return the description for admin screens. |
|
250 | - * |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function get_method_description() { |
|
254 | - return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this ); |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * Get the success url. |
|
259 | - * |
|
260 | - * @param WPInv_Invoice $invoice Invoice object. |
|
261 | - * @return string |
|
262 | - */ |
|
263 | - public function get_return_url( $invoice ) { |
|
264 | - |
|
265 | - // Payment success url |
|
266 | - $return_url = add_query_arg( |
|
267 | - array( |
|
268 | - 'payment-confirm' => $this->id, |
|
269 | - 'invoice_key' => $invoice->get_key(), |
|
270 | - 'utm_nooverride' => 1 |
|
271 | - ), |
|
272 | - wpinv_get_success_page_uri() |
|
273 | - ); |
|
274 | - |
|
275 | - return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this ); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Confirms payments when rendering the success page. |
|
280 | - * |
|
281 | - * @param string $content Success page content. |
|
282 | - * @return string |
|
283 | - */ |
|
284 | - public function confirm_payment( $content ) { |
|
285 | - |
|
286 | - // Retrieve the invoice. |
|
287 | - $invoice_id = getpaid_get_current_invoice_id(); |
|
288 | - $invoice = wpinv_get_invoice( $invoice_id ); |
|
289 | - |
|
290 | - // Ensure that it exists and that it is pending payment. |
|
291 | - if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) { |
|
292 | - return $content; |
|
293 | - } |
|
294 | - |
|
295 | - // Can the user view this invoice?? |
|
296 | - if ( ! wpinv_user_can_view_invoice( $invoice ) ) { |
|
297 | - return $content; |
|
298 | - } |
|
299 | - |
|
300 | - // Show payment processing indicator. |
|
301 | - return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) ); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Processes ipns and marks payments as complete. |
|
306 | - * |
|
307 | - * @return void |
|
308 | - */ |
|
309 | - public function verify_ipn() {} |
|
310 | - |
|
311 | - /** |
|
312 | - * Get a link to the transaction on the 3rd party gateway site (if applicable). |
|
313 | - * |
|
314 | - * @param string $transaction_url transaction url. |
|
315 | - * @param WPInv_Invoice $invoice Invoice object. |
|
316 | - * @return string transaction URL, or empty string. |
|
317 | - */ |
|
318 | - public function filter_transaction_url( $transaction_url, $invoice ) { |
|
319 | - |
|
320 | - $transaction_id = $invoice->get_transaction_id(); |
|
321 | - |
|
322 | - if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) { |
|
323 | - $transaction_url = sprintf( $this->view_transaction_url, $transaction_id ); |
|
324 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
325 | - $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url ); |
|
326 | - } |
|
327 | - |
|
328 | - return $transaction_url; |
|
329 | - } |
|
330 | - |
|
331 | - /** |
|
332 | - * Get a link to the subscription on the 3rd party gateway site (if applicable). |
|
333 | - * |
|
334 | - * @param string $subscription_url transaction url. |
|
335 | - * @param WPInv_Invoice $invoice Invoice object. |
|
336 | - * @return string subscription URL, or empty string. |
|
337 | - */ |
|
338 | - public function filter_subscription_url( $subscription_url, $invoice ) { |
|
339 | - |
|
340 | - $profile_id = $invoice->get_subscription_id(); |
|
341 | - |
|
342 | - if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) { |
|
343 | - |
|
344 | - $subscription_url = sprintf( $this->view_subscription_url, $profile_id ); |
|
345 | - $replace = $this->is_sandbox( $invoice ) ? 'sandbox' : ''; |
|
346 | - $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url ); |
|
347 | - |
|
348 | - } |
|
349 | - |
|
350 | - return $subscription_url; |
|
351 | - } |
|
352 | - |
|
353 | - /** |
|
354 | - * Check if the gateway is available for use. |
|
355 | - * |
|
356 | - * @return bool |
|
357 | - */ |
|
358 | - public function is_available() { |
|
359 | - return ! empty( $this->enabled ); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Return the gateway's title. |
|
364 | - * |
|
365 | - * @return string |
|
366 | - */ |
|
367 | - public function get_title() { |
|
368 | - return apply_filters( 'getpaid_gateway_title', $this->title, $this ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Return the gateway's description. |
|
373 | - * |
|
374 | - * @return string |
|
375 | - */ |
|
376 | - public function get_description() { |
|
377 | - return apply_filters( 'getpaid_gateway_description', $this->description, $this ); |
|
378 | - } |
|
379 | - |
|
380 | - /** |
|
381 | - * Process Payment. |
|
382 | - * |
|
383 | - * |
|
384 | - * @param WPInv_Invoice $invoice Invoice. |
|
385 | - * @param array $submission_data Posted checkout fields. |
|
386 | - * @param GetPaid_Payment_Form_Submission $submission Checkout submission. |
|
387 | - * @return void |
|
388 | - */ |
|
389 | - public function process_payment( $invoice, $submission_data, $submission ) { |
|
390 | - // Process the payment then either redirect to the success page or the gateway. |
|
391 | - do_action( 'getpaid_process_invoice_payment_' . $this->id, $invoice, $submission_data, $submission ); |
|
392 | - } |
|
393 | - |
|
394 | - /** |
|
395 | - * Process refund. |
|
396 | - * |
|
397 | - * If the gateway declares 'refunds' support, this will allow it to refund. |
|
398 | - * a passed in amount. |
|
399 | - * |
|
400 | - * @param WPInv_Invoice $invoice Invoice. |
|
401 | - * @param float $amount Refund amount. |
|
402 | - * @param string $reason Refund reason. |
|
403 | - * @return WP_Error|bool True or false based on success, or a WP_Error object. |
|
404 | - */ |
|
405 | - public function process_refund( $invoice, $amount = null, $reason = '' ) { |
|
406 | - return apply_filters( 'getpaid_process_invoice_refund_' . $this->id, false, $invoice, $amount, $reason ); |
|
407 | - } |
|
408 | - |
|
409 | - /** |
|
410 | - * Displays the payment fields, credit cards etc. |
|
411 | - * |
|
412 | - * @param int $invoice_id 0 or invoice id. |
|
413 | - * @param GetPaid_Payment_Form $form Current payment form. |
|
414 | - */ |
|
415 | - public function payment_fields( $invoice_id, $form ) { |
|
416 | - do_action( 'getpaid_getpaid_gateway_payment_fields_' . $this->id, $invoice_id, $form ); |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Filters the gateway settings. |
|
421 | - * |
|
422 | - * @param array $admin_settings |
|
423 | - */ |
|
424 | - public function admin_settings( $admin_settings ) { |
|
425 | - return $admin_settings; |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Retrieves the value of a gateway setting. |
|
430 | - * |
|
431 | - * @param string $option |
|
432 | - */ |
|
433 | - public function get_option( $option, $default = false ) { |
|
434 | - return wpinv_get_option( $this->id . '_' . $option, $default ); |
|
435 | - } |
|
436 | - |
|
437 | - /** |
|
438 | - * Check if a gateway supports a given feature. |
|
439 | - * |
|
440 | - * Gateways should override this to declare support (or lack of support) for a feature. |
|
441 | - * For backward compatibility, gateways support 'products' by default, but nothing else. |
|
442 | - * |
|
443 | - * @param string $feature string The name of a feature to test support for. |
|
444 | - * @return bool True if the gateway supports the feature, false otherwise. |
|
445 | - * @since 1.0.19 |
|
446 | - */ |
|
447 | - public function supports( $feature ) { |
|
448 | - return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this ); |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * Returns the credit card form html. |
|
453 | - * |
|
454 | - * @param bool $save whether or not to display the save button. |
|
455 | - */ |
|
451 | + /** |
|
452 | + * Returns the credit card form html. |
|
453 | + * |
|
454 | + * @param bool $save whether or not to display the save button. |
|
455 | + */ |
|
456 | 456 | public function get_cc_form( $save = false ) { |
457 | 457 | |
458 | - ob_start(); |
|
458 | + ob_start(); |
|
459 | 459 | |
460 | 460 | $id_prefix = esc_attr( uniqid( $this->id ) ); |
461 | 461 | |
@@ -561,175 +561,175 @@ discard block |
||
561 | 561 | |
562 | 562 | <?php |
563 | 563 | |
564 | - if ( $save ) { |
|
565 | - echo $this->save_payment_method_checkbox(); |
|
566 | - } |
|
564 | + if ( $save ) { |
|
565 | + echo $this->save_payment_method_checkbox(); |
|
566 | + } |
|
567 | 567 | |
568 | - ?> |
|
568 | + ?> |
|
569 | 569 | </div> |
570 | 570 | |
571 | 571 | </div> |
572 | 572 | <?php |
573 | 573 | |
574 | - return ob_get_clean(); |
|
574 | + return ob_get_clean(); |
|
575 | 575 | |
576 | 576 | } |
577 | 577 | |
578 | - /** |
|
579 | - * Displays a new payment method entry form. |
|
580 | - * |
|
581 | - * @since 1.0.19 |
|
582 | - */ |
|
583 | - public function new_payment_method_entry( $form ) { |
|
584 | - echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
585 | - } |
|
586 | - |
|
587 | - /** |
|
588 | - * Grab and display our saved payment methods. |
|
589 | - * |
|
590 | - * @since 1.0.19 |
|
591 | - */ |
|
592 | - public function saved_payment_methods() { |
|
593 | - $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
594 | - |
|
595 | - foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
596 | - $html .= $this->get_saved_payment_method_option_html( $token ); |
|
597 | - } |
|
598 | - |
|
599 | - $html .= $this->get_new_payment_method_option_html(); |
|
600 | - $html .= '</ul>'; |
|
601 | - |
|
602 | - echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
603 | - } |
|
604 | - |
|
605 | - /** |
|
606 | - * Gets saved payment method HTML from a token. |
|
607 | - * |
|
608 | - * @since 1.0.19 |
|
609 | - * @param array $token Payment Token. |
|
610 | - * @return string Generated payment method HTML |
|
611 | - */ |
|
612 | - public function get_saved_payment_method_option_html( $token ) { |
|
613 | - |
|
614 | - return sprintf( |
|
615 | - '<li class="getpaid-payment-method form-group"> |
|
578 | + /** |
|
579 | + * Displays a new payment method entry form. |
|
580 | + * |
|
581 | + * @since 1.0.19 |
|
582 | + */ |
|
583 | + public function new_payment_method_entry( $form ) { |
|
584 | + echo "<div class='getpaid-new-payment-method-form' style='display:none;'>$form</div>"; |
|
585 | + } |
|
586 | + |
|
587 | + /** |
|
588 | + * Grab and display our saved payment methods. |
|
589 | + * |
|
590 | + * @since 1.0.19 |
|
591 | + */ |
|
592 | + public function saved_payment_methods() { |
|
593 | + $html = '<ul class="getpaid-saved-payment-methods m-0 mt-2" data-count="' . esc_attr( count( $this->get_tokens( $this->is_sandbox() ) ) ) . '">'; |
|
594 | + |
|
595 | + foreach ( $this->get_tokens( $this->is_sandbox() ) as $token ) { |
|
596 | + $html .= $this->get_saved_payment_method_option_html( $token ); |
|
597 | + } |
|
598 | + |
|
599 | + $html .= $this->get_new_payment_method_option_html(); |
|
600 | + $html .= '</ul>'; |
|
601 | + |
|
602 | + echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this ); |
|
603 | + } |
|
604 | + |
|
605 | + /** |
|
606 | + * Gets saved payment method HTML from a token. |
|
607 | + * |
|
608 | + * @since 1.0.19 |
|
609 | + * @param array $token Payment Token. |
|
610 | + * @return string Generated payment method HTML |
|
611 | + */ |
|
612 | + public function get_saved_payment_method_option_html( $token ) { |
|
613 | + |
|
614 | + return sprintf( |
|
615 | + '<li class="getpaid-payment-method form-group"> |
|
616 | 616 | <label> |
617 | 617 | <input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s /> |
618 | 618 | <span>%3$s</span> |
619 | 619 | </label> |
620 | 620 | </li>', |
621 | - esc_attr( $this->id ), |
|
622 | - esc_attr( $token['id'] ), |
|
623 | - esc_html( $token['name'] ), |
|
624 | - checked( empty( $token['default'] ), false, false ) |
|
625 | - ); |
|
621 | + esc_attr( $this->id ), |
|
622 | + esc_attr( $token['id'] ), |
|
623 | + esc_html( $token['name'] ), |
|
624 | + checked( empty( $token['default'] ), false, false ) |
|
625 | + ); |
|
626 | 626 | |
627 | - } |
|
627 | + } |
|
628 | 628 | |
629 | - /** |
|
630 | - * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
631 | - * |
|
632 | - * @since 1.0.19 |
|
633 | - */ |
|
634 | - public function get_new_payment_method_option_html() { |
|
629 | + /** |
|
630 | + * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method. |
|
631 | + * |
|
632 | + * @since 1.0.19 |
|
633 | + */ |
|
634 | + public function get_new_payment_method_option_html() { |
|
635 | 635 | |
636 | - $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
636 | + $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this ); |
|
637 | 637 | |
638 | - return sprintf( |
|
639 | - '<li class="getpaid-new-payment-method"> |
|
638 | + return sprintf( |
|
639 | + '<li class="getpaid-new-payment-method"> |
|
640 | 640 | <label> |
641 | 641 | <input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" /> |
642 | 642 | <span>%2$s</span> |
643 | 643 | </label> |
644 | 644 | </li>', |
645 | - esc_attr( $this->id ), |
|
646 | - esc_html( $label ) |
|
647 | - ); |
|
645 | + esc_attr( $this->id ), |
|
646 | + esc_html( $label ) |
|
647 | + ); |
|
648 | 648 | |
649 | - } |
|
649 | + } |
|
650 | 650 | |
651 | - /** |
|
652 | - * Outputs a checkbox for saving a new payment method to the database. |
|
653 | - * |
|
654 | - * @since 1.0.19 |
|
655 | - */ |
|
656 | - public function save_payment_method_checkbox() { |
|
651 | + /** |
|
652 | + * Outputs a checkbox for saving a new payment method to the database. |
|
653 | + * |
|
654 | + * @since 1.0.19 |
|
655 | + */ |
|
656 | + public function save_payment_method_checkbox() { |
|
657 | 657 | |
658 | - return sprintf( |
|
659 | - '<p class="form-group getpaid-save-payment-method"> |
|
658 | + return sprintf( |
|
659 | + '<p class="form-group getpaid-save-payment-method"> |
|
660 | 660 | <label> |
661 | 661 | <input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" /> |
662 | 662 | <span>%2$s</span> |
663 | 663 | </label> |
664 | 664 | </p>', |
665 | - esc_attr( $this->id ), |
|
666 | - esc_html__( 'Save payment method', 'invoicing' ) |
|
667 | - ); |
|
665 | + esc_attr( $this->id ), |
|
666 | + esc_html__( 'Save payment method', 'invoicing' ) |
|
667 | + ); |
|
668 | 668 | |
669 | - } |
|
669 | + } |
|
670 | 670 | |
671 | - /** |
|
672 | - * Registers the gateway. |
|
673 | - * |
|
674 | - * @return array |
|
675 | - */ |
|
676 | - public function register_gateway( $gateways ) { |
|
671 | + /** |
|
672 | + * Registers the gateway. |
|
673 | + * |
|
674 | + * @return array |
|
675 | + */ |
|
676 | + public function register_gateway( $gateways ) { |
|
677 | 677 | |
678 | - $gateways[ $this->id ] = array( |
|
678 | + $gateways[ $this->id ] = array( |
|
679 | 679 | |
680 | - 'admin_label' => $this->method_title, |
|
680 | + 'admin_label' => $this->method_title, |
|
681 | 681 | 'checkout_label' => $this->title, |
682 | - 'ordering' => $this->order, |
|
683 | - |
|
684 | - ); |
|
685 | - |
|
686 | - return $gateways; |
|
687 | - |
|
688 | - } |
|
689 | - |
|
690 | - /** |
|
691 | - * Checks whether or not this is a sandbox request. |
|
692 | - * |
|
693 | - * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
694 | - * @return bool |
|
695 | - */ |
|
696 | - public function is_sandbox( $invoice = null ) { |
|
697 | - |
|
698 | - if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
699 | - return $invoice->get_mode() == 'test'; |
|
700 | - } |
|
701 | - |
|
702 | - return wpinv_is_test_mode( $this->id ); |
|
703 | - |
|
704 | - } |
|
705 | - |
|
706 | - /** |
|
707 | - * Renames the checkout button |
|
708 | - * |
|
709 | - * @return string |
|
710 | - */ |
|
711 | - public function rename_checkout_button() { |
|
712 | - return $this->checkout_button_text; |
|
713 | - } |
|
714 | - |
|
715 | - /** |
|
716 | - * Validate gateway currency |
|
717 | - * |
|
718 | - * @return bool |
|
719 | - */ |
|
720 | - public function validate_currency( $validation, $currency ) { |
|
721 | - |
|
722 | - // Required currencies. |
|
723 | - if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
724 | - return false; |
|
725 | - } |
|
726 | - |
|
727 | - // Excluded currencies. |
|
728 | - if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
729 | - return false; |
|
730 | - } |
|
731 | - |
|
732 | - return $validation; |
|
733 | - } |
|
682 | + 'ordering' => $this->order, |
|
683 | + |
|
684 | + ); |
|
685 | + |
|
686 | + return $gateways; |
|
687 | + |
|
688 | + } |
|
689 | + |
|
690 | + /** |
|
691 | + * Checks whether or not this is a sandbox request. |
|
692 | + * |
|
693 | + * @param WPInv_Invoice|null $invoice Invoice object or null. |
|
694 | + * @return bool |
|
695 | + */ |
|
696 | + public function is_sandbox( $invoice = null ) { |
|
697 | + |
|
698 | + if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) { |
|
699 | + return $invoice->get_mode() == 'test'; |
|
700 | + } |
|
701 | + |
|
702 | + return wpinv_is_test_mode( $this->id ); |
|
703 | + |
|
704 | + } |
|
705 | + |
|
706 | + /** |
|
707 | + * Renames the checkout button |
|
708 | + * |
|
709 | + * @return string |
|
710 | + */ |
|
711 | + public function rename_checkout_button() { |
|
712 | + return $this->checkout_button_text; |
|
713 | + } |
|
714 | + |
|
715 | + /** |
|
716 | + * Validate gateway currency |
|
717 | + * |
|
718 | + * @return bool |
|
719 | + */ |
|
720 | + public function validate_currency( $validation, $currency ) { |
|
721 | + |
|
722 | + // Required currencies. |
|
723 | + if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) { |
|
724 | + return false; |
|
725 | + } |
|
726 | + |
|
727 | + // Excluded currencies. |
|
728 | + if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) { |
|
729 | + return false; |
|
730 | + } |
|
731 | + |
|
732 | + return $validation; |
|
733 | + } |
|
734 | 734 | |
735 | 735 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,1012 +11,1012 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI_Component_Input { |
13 | 13 | |
14 | - /** |
|
15 | - * Build the component. |
|
16 | - * |
|
17 | - * @param array $args |
|
18 | - * |
|
19 | - * @return string The rendered component. |
|
20 | - */ |
|
21 | - public static function input($args = array()){ |
|
22 | - $defaults = array( |
|
23 | - 'type' => 'text', |
|
24 | - 'name' => '', |
|
25 | - 'class' => '', |
|
26 | - 'wrap_class' => '', |
|
27 | - 'id' => '', |
|
28 | - 'placeholder'=> '', |
|
29 | - 'title' => '', |
|
30 | - 'value' => '', |
|
31 | - 'required' => false, |
|
32 | - 'label' => '', |
|
33 | - 'label_after'=> false, |
|
34 | - 'label_class'=> '', |
|
35 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | - 'help_text' => '', |
|
37 | - 'validation_text' => '', |
|
38 | - 'validation_pattern' => '', |
|
39 | - 'no_wrap' => false, |
|
40 | - 'input_group_right' => '', |
|
41 | - 'input_group_left' => '', |
|
42 | - 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | - 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | - 'step' => '', |
|
45 | - 'switch' => false, // to show checkbox as a switch |
|
46 | - 'checked' => false, // set a checkbox or radio as selected |
|
47 | - 'password_toggle' => true, // toggle view/hide password |
|
48 | - 'element_require' => '', // [%element_id%] == "1" |
|
49 | - 'extra_attributes' => array() // an array of extra attributes |
|
50 | - ); |
|
51 | - |
|
52 | - /** |
|
53 | - * Parse incoming $args into an array and merge it with $defaults |
|
54 | - */ |
|
55 | - $args = wp_parse_args( $args, $defaults ); |
|
56 | - $output = ''; |
|
57 | - if ( ! empty( $args['type'] ) ) { |
|
58 | - // hidden label option needs to be empty |
|
59 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | - |
|
61 | - $type = sanitize_html_class( $args['type'] ); |
|
62 | - |
|
63 | - $help_text = ''; |
|
64 | - $label = ''; |
|
65 | - $label_after = $args['label_after']; |
|
66 | - $label_args = array( |
|
67 | - 'title'=> $args['label'], |
|
68 | - 'for'=> $args['id'], |
|
69 | - 'class' => $args['label_class']." ", |
|
70 | - 'label_type' => $args['label_type'] |
|
71 | - ); |
|
72 | - |
|
73 | - // floating labels need label after |
|
74 | - if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | - $label_after = true; |
|
76 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | - } |
|
78 | - |
|
79 | - // Some special sauce for files |
|
80 | - if($type=='file' ){ |
|
81 | - $label_after = true; // if type file we need the label after |
|
82 | - $args['class'] .= ' custom-file-input '; |
|
83 | - }elseif($type=='checkbox'){ |
|
84 | - $label_after = true; // if type file we need the label after |
|
85 | - $args['class'] .= ' custom-control-input '; |
|
86 | - }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | - $type = 'text'; |
|
88 | - //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | - $args['class'] .= ' bg-initial '; |
|
90 | - |
|
91 | - $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | - // enqueue the script |
|
93 | - $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | - $aui_settings->enqueue_flatpickr(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - // open/type |
|
99 | - $output .= '<input type="' . $type . '" '; |
|
100 | - |
|
101 | - // name |
|
102 | - if(!empty($args['name'])){ |
|
103 | - $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | - } |
|
105 | - |
|
106 | - // id |
|
107 | - if(!empty($args['id'])){ |
|
108 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | - } |
|
110 | - |
|
111 | - // placeholder |
|
112 | - if(!empty($args['placeholder'])){ |
|
113 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | - } |
|
115 | - |
|
116 | - // title |
|
117 | - if(!empty($args['title'])){ |
|
118 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | - } |
|
120 | - |
|
121 | - // value |
|
122 | - if(!empty($args['value'])){ |
|
123 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | - } |
|
125 | - |
|
126 | - // checked, for radio and checkboxes |
|
127 | - if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | - $output .= ' checked '; |
|
129 | - } |
|
130 | - |
|
131 | - // validation text |
|
132 | - if(!empty($args['validation_text'])){ |
|
133 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | - } |
|
136 | - |
|
137 | - // validation_pattern |
|
138 | - if(!empty($args['validation_pattern'])){ |
|
139 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | - } |
|
141 | - |
|
142 | - // step (for numbers) |
|
143 | - if(!empty($args['step'])){ |
|
144 | - $output .= ' step="'.$args['step'].'" '; |
|
145 | - } |
|
146 | - |
|
147 | - // required |
|
148 | - if(!empty($args['required'])){ |
|
149 | - $output .= ' required '; |
|
150 | - } |
|
151 | - |
|
152 | - // class |
|
153 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | - $output .= ' class="form-control '.$class.'" '; |
|
155 | - |
|
156 | - // data-attributes |
|
157 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | - |
|
159 | - // extra attributes |
|
160 | - if(!empty($args['extra_attributes'])){ |
|
161 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | - } |
|
163 | - |
|
164 | - // close |
|
165 | - $output .= ' >'; |
|
166 | - |
|
167 | - |
|
168 | - // label |
|
169 | - if(!empty($args['label'])){ |
|
170 | - if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | - elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | - $label = self::label( $label_args, $type ); |
|
173 | - } |
|
174 | - |
|
175 | - // help text |
|
176 | - if(!empty($args['help_text'])){ |
|
177 | - $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - // set help text in the correct possition |
|
182 | - if($label_after){ |
|
183 | - $output .= $label . $help_text; |
|
184 | - } |
|
185 | - |
|
186 | - // some input types need a separate wrap |
|
187 | - if($type == 'file') { |
|
188 | - $output = self::wrap( array( |
|
189 | - 'content' => $output, |
|
190 | - 'class' => 'form-group custom-file' |
|
191 | - ) ); |
|
192 | - }elseif($type == 'checkbox'){ |
|
193 | - $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | - $output = self::wrap( array( |
|
195 | - 'content' => $output, |
|
196 | - 'class' => 'custom-control '.$wrap_class |
|
197 | - ) ); |
|
198 | - |
|
199 | - if($args['label_type']=='horizontal'){ |
|
200 | - $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | - } |
|
202 | - }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | - |
|
204 | - |
|
205 | - // allow password field to toggle view |
|
206 | - $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
14 | + /** |
|
15 | + * Build the component. |
|
16 | + * |
|
17 | + * @param array $args |
|
18 | + * |
|
19 | + * @return string The rendered component. |
|
20 | + */ |
|
21 | + public static function input($args = array()){ |
|
22 | + $defaults = array( |
|
23 | + 'type' => 'text', |
|
24 | + 'name' => '', |
|
25 | + 'class' => '', |
|
26 | + 'wrap_class' => '', |
|
27 | + 'id' => '', |
|
28 | + 'placeholder'=> '', |
|
29 | + 'title' => '', |
|
30 | + 'value' => '', |
|
31 | + 'required' => false, |
|
32 | + 'label' => '', |
|
33 | + 'label_after'=> false, |
|
34 | + 'label_class'=> '', |
|
35 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
36 | + 'help_text' => '', |
|
37 | + 'validation_text' => '', |
|
38 | + 'validation_pattern' => '', |
|
39 | + 'no_wrap' => false, |
|
40 | + 'input_group_right' => '', |
|
41 | + 'input_group_left' => '', |
|
42 | + 'input_group_right_inside' => false, // forces the input group inside the input |
|
43 | + 'input_group_left_inside' => false, // forces the input group inside the input |
|
44 | + 'step' => '', |
|
45 | + 'switch' => false, // to show checkbox as a switch |
|
46 | + 'checked' => false, // set a checkbox or radio as selected |
|
47 | + 'password_toggle' => true, // toggle view/hide password |
|
48 | + 'element_require' => '', // [%element_id%] == "1" |
|
49 | + 'extra_attributes' => array() // an array of extra attributes |
|
50 | + ); |
|
51 | + |
|
52 | + /** |
|
53 | + * Parse incoming $args into an array and merge it with $defaults |
|
54 | + */ |
|
55 | + $args = wp_parse_args( $args, $defaults ); |
|
56 | + $output = ''; |
|
57 | + if ( ! empty( $args['type'] ) ) { |
|
58 | + // hidden label option needs to be empty |
|
59 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
60 | + |
|
61 | + $type = sanitize_html_class( $args['type'] ); |
|
62 | + |
|
63 | + $help_text = ''; |
|
64 | + $label = ''; |
|
65 | + $label_after = $args['label_after']; |
|
66 | + $label_args = array( |
|
67 | + 'title'=> $args['label'], |
|
68 | + 'for'=> $args['id'], |
|
69 | + 'class' => $args['label_class']." ", |
|
70 | + 'label_type' => $args['label_type'] |
|
71 | + ); |
|
72 | + |
|
73 | + // floating labels need label after |
|
74 | + if( $args['label_type'] == 'floating' && $type != 'checkbox' ){ |
|
75 | + $label_after = true; |
|
76 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
77 | + } |
|
78 | + |
|
79 | + // Some special sauce for files |
|
80 | + if($type=='file' ){ |
|
81 | + $label_after = true; // if type file we need the label after |
|
82 | + $args['class'] .= ' custom-file-input '; |
|
83 | + }elseif($type=='checkbox'){ |
|
84 | + $label_after = true; // if type file we need the label after |
|
85 | + $args['class'] .= ' custom-control-input '; |
|
86 | + }elseif($type=='datepicker' || $type=='timepicker'){ |
|
87 | + $type = 'text'; |
|
88 | + //$args['class'] .= ' aui-flatpickr bg-initial '; |
|
89 | + $args['class'] .= ' bg-initial '; |
|
90 | + |
|
91 | + $args['extra_attributes']['data-aui-init'] = 'flatpickr'; |
|
92 | + // enqueue the script |
|
93 | + $aui_settings = AyeCode_UI_Settings::instance(); |
|
94 | + $aui_settings->enqueue_flatpickr(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + // open/type |
|
99 | + $output .= '<input type="' . $type . '" '; |
|
100 | + |
|
101 | + // name |
|
102 | + if(!empty($args['name'])){ |
|
103 | + $output .= ' name="'.esc_attr($args['name']).'" '; |
|
104 | + } |
|
105 | + |
|
106 | + // id |
|
107 | + if(!empty($args['id'])){ |
|
108 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
109 | + } |
|
110 | + |
|
111 | + // placeholder |
|
112 | + if(!empty($args['placeholder'])){ |
|
113 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
114 | + } |
|
115 | + |
|
116 | + // title |
|
117 | + if(!empty($args['title'])){ |
|
118 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
119 | + } |
|
120 | + |
|
121 | + // value |
|
122 | + if(!empty($args['value'])){ |
|
123 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
124 | + } |
|
125 | + |
|
126 | + // checked, for radio and checkboxes |
|
127 | + if( ( $type == 'checkbox' || $type == 'radio' ) && $args['checked'] ){ |
|
128 | + $output .= ' checked '; |
|
129 | + } |
|
130 | + |
|
131 | + // validation text |
|
132 | + if(!empty($args['validation_text'])){ |
|
133 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
134 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
135 | + } |
|
136 | + |
|
137 | + // validation_pattern |
|
138 | + if(!empty($args['validation_pattern'])){ |
|
139 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
140 | + } |
|
141 | + |
|
142 | + // step (for numbers) |
|
143 | + if(!empty($args['step'])){ |
|
144 | + $output .= ' step="'.$args['step'].'" '; |
|
145 | + } |
|
146 | + |
|
147 | + // required |
|
148 | + if(!empty($args['required'])){ |
|
149 | + $output .= ' required '; |
|
150 | + } |
|
151 | + |
|
152 | + // class |
|
153 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
154 | + $output .= ' class="form-control '.$class.'" '; |
|
155 | + |
|
156 | + // data-attributes |
|
157 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
158 | + |
|
159 | + // extra attributes |
|
160 | + if(!empty($args['extra_attributes'])){ |
|
161 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
162 | + } |
|
163 | + |
|
164 | + // close |
|
165 | + $output .= ' >'; |
|
166 | + |
|
167 | + |
|
168 | + // label |
|
169 | + if(!empty($args['label'])){ |
|
170 | + if($type == 'file'){$label_args['class'] .= 'custom-file-label';} |
|
171 | + elseif($type == 'checkbox'){$label_args['class'] .= 'custom-control-label';} |
|
172 | + $label = self::label( $label_args, $type ); |
|
173 | + } |
|
174 | + |
|
175 | + // help text |
|
176 | + if(!empty($args['help_text'])){ |
|
177 | + $help_text = AUI_Component_Helper::help_text($args['help_text']); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + // set help text in the correct possition |
|
182 | + if($label_after){ |
|
183 | + $output .= $label . $help_text; |
|
184 | + } |
|
185 | + |
|
186 | + // some input types need a separate wrap |
|
187 | + if($type == 'file') { |
|
188 | + $output = self::wrap( array( |
|
189 | + 'content' => $output, |
|
190 | + 'class' => 'form-group custom-file' |
|
191 | + ) ); |
|
192 | + }elseif($type == 'checkbox'){ |
|
193 | + $wrap_class = $args['switch'] ? 'custom-switch' : 'custom-checkbox'; |
|
194 | + $output = self::wrap( array( |
|
195 | + 'content' => $output, |
|
196 | + 'class' => 'custom-control '.$wrap_class |
|
197 | + ) ); |
|
198 | + |
|
199 | + if($args['label_type']=='horizontal'){ |
|
200 | + $output = '<div class="col-sm-2 col-form-label"></div><div class="col-sm-10">' . $output . '</div>'; |
|
201 | + } |
|
202 | + }elseif($type == 'password' && $args['password_toggle'] && !$args['input_group_right']){ |
|
203 | + |
|
204 | + |
|
205 | + // allow password field to toggle view |
|
206 | + $args['input_group_right'] = '<span class="input-group-text c-pointer px-3" |
|
207 | 207 | onclick="var $el = jQuery(this).find(\'i\');$el.toggleClass(\'fa-eye fa-eye-slash\'); |
208 | 208 | var $eli = jQuery(this).parent().parent().find(\'input\'); |
209 | 209 | if($el.hasClass(\'fa-eye\')) |
210 | 210 | {$eli.attr(\'type\',\'text\');} |
211 | 211 | else{$eli.attr(\'type\',\'password\');}" |
212 | 212 | ><i class="far fa-fw fa-eye-slash"></i></span>'; |
213 | - } |
|
214 | - |
|
215 | - // input group wraps |
|
216 | - if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | - $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | - if($args['input_group_left']){ |
|
219 | - $output = self::wrap( array( |
|
220 | - 'content' => $output, |
|
221 | - 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | - 'input_group_left' => $args['input_group_left'], |
|
223 | - 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | - ) ); |
|
225 | - } |
|
226 | - if($args['input_group_right']){ |
|
227 | - $output = self::wrap( array( |
|
228 | - 'content' => $output, |
|
229 | - 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | - 'input_group_right' => $args['input_group_right'], |
|
231 | - 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | - ) ); |
|
233 | - } |
|
234 | - |
|
235 | - } |
|
236 | - |
|
237 | - if(!$label_after){ |
|
238 | - $output .= $help_text; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | - $output = self::wrap( array( |
|
244 | - 'content' => $output, |
|
245 | - 'class' => 'col-sm-10', |
|
246 | - ) ); |
|
247 | - } |
|
248 | - |
|
249 | - if(!$label_after){ |
|
250 | - $output = $label . $output; |
|
251 | - } |
|
252 | - |
|
253 | - // wrap |
|
254 | - if(!$args['no_wrap']){ |
|
255 | - |
|
256 | - $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | - $output = self::wrap(array( |
|
260 | - 'content' => $output, |
|
261 | - 'class' => $wrap_class, |
|
262 | - 'element_require' => $args['element_require'], |
|
263 | - 'argument_id' => $args['id'] |
|
264 | - )); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - |
|
269 | - } |
|
270 | - |
|
271 | - return $output; |
|
272 | - } |
|
273 | - |
|
274 | - /** |
|
275 | - * Build the component. |
|
276 | - * |
|
277 | - * @param array $args |
|
278 | - * |
|
279 | - * @return string The rendered component. |
|
280 | - */ |
|
281 | - public static function textarea($args = array()){ |
|
282 | - $defaults = array( |
|
283 | - 'name' => '', |
|
284 | - 'class' => '', |
|
285 | - 'wrap_class' => '', |
|
286 | - 'id' => '', |
|
287 | - 'placeholder'=> '', |
|
288 | - 'title' => '', |
|
289 | - 'value' => '', |
|
290 | - 'required' => false, |
|
291 | - 'label' => '', |
|
292 | - 'label_after'=> false, |
|
293 | - 'label_class' => '', |
|
294 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | - 'help_text' => '', |
|
296 | - 'validation_text' => '', |
|
297 | - 'validation_pattern' => '', |
|
298 | - 'no_wrap' => false, |
|
299 | - 'rows' => '', |
|
300 | - 'wysiwyg' => false, |
|
301 | - 'element_require' => '', // [%element_id%] == "1" |
|
302 | - ); |
|
303 | - |
|
304 | - /** |
|
305 | - * Parse incoming $args into an array and merge it with $defaults |
|
306 | - */ |
|
307 | - $args = wp_parse_args( $args, $defaults ); |
|
308 | - $output = ''; |
|
309 | - |
|
310 | - // hidden label option needs to be empty |
|
311 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | - |
|
313 | - // floating labels don't work with wysiwyg so set it as top |
|
314 | - if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | - $args['label_type'] = 'top'; |
|
316 | - } |
|
317 | - |
|
318 | - $label_after = $args['label_after']; |
|
319 | - |
|
320 | - // floating labels need label after |
|
321 | - if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | - $label_after = true; |
|
323 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | - } |
|
325 | - |
|
326 | - // label |
|
327 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | - }elseif(!empty($args['label']) && !$label_after){ |
|
329 | - $label_args = array( |
|
330 | - 'title'=> $args['label'], |
|
331 | - 'for'=> $args['id'], |
|
332 | - 'class' => $args['label_class']." ", |
|
333 | - 'label_type' => $args['label_type'] |
|
334 | - ); |
|
335 | - $output .= self::label( $label_args ); |
|
336 | - } |
|
337 | - |
|
338 | - // maybe horizontal label |
|
339 | - if($args['label_type']=='horizontal'){ |
|
340 | - $output .= '<div class="col-sm-10">'; |
|
341 | - } |
|
342 | - |
|
343 | - if(!empty($args['wysiwyg'])){ |
|
344 | - ob_start(); |
|
345 | - $content = $args['value']; |
|
346 | - $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | - $settings = array( |
|
348 | - 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | - 'quicktags' => false, |
|
350 | - 'media_buttons' => false, |
|
351 | - 'editor_class' => 'form-control', |
|
352 | - 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | - 'teeny' => true, |
|
354 | - ); |
|
355 | - |
|
356 | - // maybe set settings if array |
|
357 | - if(is_array($args['wysiwyg'])){ |
|
358 | - $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | - } |
|
360 | - |
|
361 | - wp_editor( $content, $editor_id, $settings ); |
|
362 | - $output .= ob_get_clean(); |
|
363 | - }else{ |
|
364 | - |
|
365 | - // open |
|
366 | - $output .= '<textarea '; |
|
367 | - |
|
368 | - // name |
|
369 | - if(!empty($args['name'])){ |
|
370 | - $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | - } |
|
372 | - |
|
373 | - // id |
|
374 | - if(!empty($args['id'])){ |
|
375 | - $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | - } |
|
377 | - |
|
378 | - // placeholder |
|
379 | - if(!empty($args['placeholder'])){ |
|
380 | - $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | - } |
|
382 | - |
|
383 | - // title |
|
384 | - if(!empty($args['title'])){ |
|
385 | - $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | - } |
|
387 | - |
|
388 | - // validation text |
|
389 | - if(!empty($args['validation_text'])){ |
|
390 | - $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | - $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | - } |
|
393 | - |
|
394 | - // validation_pattern |
|
395 | - if(!empty($args['validation_pattern'])){ |
|
396 | - $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | - } |
|
398 | - |
|
399 | - // required |
|
400 | - if(!empty($args['required'])){ |
|
401 | - $output .= ' required '; |
|
402 | - } |
|
403 | - |
|
404 | - // rows |
|
405 | - if(!empty($args['rows'])){ |
|
406 | - $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - // class |
|
411 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | - $output .= ' class="form-control '.$class.'" '; |
|
413 | - |
|
414 | - |
|
415 | - // close tag |
|
416 | - $output .= ' >'; |
|
417 | - |
|
418 | - // value |
|
419 | - if(!empty($args['value'])){ |
|
420 | - $output .= sanitize_textarea_field($args['value']); |
|
421 | - } |
|
422 | - |
|
423 | - // closing tag |
|
424 | - $output .= '</textarea>'; |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - if(!empty($args['label']) && $label_after){ |
|
429 | - $label_args = array( |
|
430 | - 'title'=> $args['label'], |
|
431 | - 'for'=> $args['id'], |
|
432 | - 'class' => $args['label_class']." ", |
|
433 | - 'label_type' => $args['label_type'] |
|
434 | - ); |
|
435 | - $output .= self::label( $label_args ); |
|
436 | - } |
|
437 | - |
|
438 | - // help text |
|
439 | - if(!empty($args['help_text'])){ |
|
440 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | - } |
|
442 | - |
|
443 | - // maybe horizontal label |
|
444 | - if($args['label_type']=='horizontal'){ |
|
445 | - $output .= '</div>'; |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - // wrap |
|
450 | - if(!$args['no_wrap']){ |
|
451 | - $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | - $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | - $output = self::wrap(array( |
|
455 | - 'content' => $output, |
|
456 | - 'class' => $wrap_class, |
|
457 | - 'element_require' => $args['element_require'], |
|
458 | - 'argument_id' => $args['id'] |
|
459 | - )); |
|
460 | - } |
|
461 | - |
|
462 | - |
|
463 | - return $output; |
|
464 | - } |
|
465 | - |
|
466 | - public static function label($args = array(), $type = ''){ |
|
467 | - //<label for="exampleInputEmail1">Email address</label> |
|
468 | - $defaults = array( |
|
469 | - 'title' => 'div', |
|
470 | - 'for' => '', |
|
471 | - 'class' => '', |
|
472 | - 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | - ); |
|
474 | - |
|
475 | - /** |
|
476 | - * Parse incoming $args into an array and merge it with $defaults |
|
477 | - */ |
|
478 | - $args = wp_parse_args( $args, $defaults ); |
|
479 | - $output = ''; |
|
480 | - |
|
481 | - if($args['title']){ |
|
482 | - |
|
483 | - // maybe hide labels //@todo set a global option for visibility class |
|
484 | - if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | - $class = $args['class']; |
|
486 | - }else{ |
|
487 | - $class = 'sr-only '.$args['class']; |
|
488 | - } |
|
489 | - |
|
490 | - // maybe horizontal |
|
491 | - if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | - $class .= ' col-sm-2 col-form-label'; |
|
493 | - } |
|
494 | - |
|
495 | - // open |
|
496 | - $output .= '<label '; |
|
497 | - |
|
498 | - // for |
|
499 | - if(!empty($args['for'])){ |
|
500 | - $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | - } |
|
502 | - |
|
503 | - // class |
|
504 | - $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | - $output .= ' class="'.$class.'" '; |
|
506 | - |
|
507 | - // close |
|
508 | - $output .= '>'; |
|
509 | - |
|
510 | - |
|
511 | - // title, don't escape fully as can contain html |
|
512 | - if(!empty($args['title'])){ |
|
513 | - $output .= wp_kses_post($args['title']); |
|
514 | - } |
|
515 | - |
|
516 | - // close wrap |
|
517 | - $output .= '</label>'; |
|
518 | - |
|
519 | - |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - return $output; |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Wrap some content in a HTML wrapper. |
|
528 | - * |
|
529 | - * @param array $args |
|
530 | - * |
|
531 | - * @return string |
|
532 | - */ |
|
533 | - public static function wrap($args = array()){ |
|
534 | - $defaults = array( |
|
535 | - 'type' => 'div', |
|
536 | - 'class' => 'form-group', |
|
537 | - 'content' => '', |
|
538 | - 'input_group_left' => '', |
|
539 | - 'input_group_right' => '', |
|
540 | - 'input_group_left_inside' => false, |
|
541 | - 'input_group_right_inside' => false, |
|
542 | - 'element_require' => '', |
|
543 | - 'argument_id' => '', |
|
544 | - ); |
|
545 | - |
|
546 | - /** |
|
547 | - * Parse incoming $args into an array and merge it with $defaults |
|
548 | - */ |
|
549 | - $args = wp_parse_args( $args, $defaults ); |
|
550 | - $output = ''; |
|
551 | - if($args['type']){ |
|
552 | - |
|
553 | - // open |
|
554 | - $output .= '<'.sanitize_html_class($args['type']); |
|
555 | - |
|
556 | - // element require |
|
557 | - if(!empty($args['element_require'])){ |
|
558 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | - $args['class'] .= " aui-conditional-field"; |
|
560 | - } |
|
561 | - |
|
562 | - // argument_id |
|
563 | - if( !empty($args['argument_id']) ){ |
|
564 | - $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | - } |
|
566 | - |
|
567 | - // class |
|
568 | - $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | - $output .= ' class="'.$class.'" '; |
|
570 | - |
|
571 | - // close wrap |
|
572 | - $output .= ' >'; |
|
573 | - |
|
574 | - |
|
575 | - // Input group left |
|
576 | - if(!empty($args['input_group_left'])){ |
|
577 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | - $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | - $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | - } |
|
581 | - |
|
582 | - // content |
|
583 | - $output .= $args['content']; |
|
584 | - |
|
585 | - // Input group right |
|
586 | - if(!empty($args['input_group_right'])){ |
|
587 | - $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | - $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | - $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - // close wrap |
|
594 | - $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | - |
|
596 | - |
|
597 | - }else{ |
|
598 | - $output = $args['content']; |
|
599 | - } |
|
600 | - |
|
601 | - return $output; |
|
602 | - } |
|
603 | - |
|
604 | - /** |
|
605 | - * Build the component. |
|
606 | - * |
|
607 | - * @param array $args |
|
608 | - * |
|
609 | - * @return string The rendered component. |
|
610 | - */ |
|
611 | - public static function select($args = array()){ |
|
612 | - $defaults = array( |
|
613 | - 'class' => '', |
|
614 | - 'wrap_class' => '', |
|
615 | - 'id' => '', |
|
616 | - 'title' => '', |
|
617 | - 'value' => '', // can be an array or a string |
|
618 | - 'required' => false, |
|
619 | - 'label' => '', |
|
620 | - 'label_after'=> false, |
|
621 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | - 'label_class' => '', |
|
623 | - 'help_text' => '', |
|
624 | - 'placeholder'=> '', |
|
625 | - 'options' => array(), // array or string |
|
626 | - 'icon' => '', |
|
627 | - 'multiple' => false, |
|
628 | - 'select2' => false, |
|
629 | - 'no_wrap' => false, |
|
630 | - 'element_require' => '', // [%element_id%] == "1" |
|
631 | - 'extra_attributes' => array(), // an array of extra attributes |
|
632 | - ); |
|
633 | - |
|
634 | - /** |
|
635 | - * Parse incoming $args into an array and merge it with $defaults |
|
636 | - */ |
|
637 | - $args = wp_parse_args( $args, $defaults ); |
|
638 | - $output = ''; |
|
639 | - |
|
640 | - // for now lets hide floating labels |
|
641 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | - |
|
643 | - // hidden label option needs to be empty |
|
644 | - $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | - |
|
646 | - |
|
647 | - $label_after = $args['label_after']; |
|
648 | - |
|
649 | - // floating labels need label after |
|
650 | - if( $args['label_type'] == 'floating' ){ |
|
651 | - $label_after = true; |
|
652 | - $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | - } |
|
654 | - |
|
655 | - // Maybe setup select2 |
|
656 | - $is_select2 = false; |
|
657 | - if(!empty($args['select2'])){ |
|
658 | - $args['class'] .= ' aui-select2'; |
|
659 | - $is_select2 = true; |
|
660 | - }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | - $is_select2 = true; |
|
662 | - } |
|
663 | - |
|
664 | - // select2 tags |
|
665 | - if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | - $args['data-tags'] = 'true'; |
|
667 | - $args['data-token-separators'] = "[',']"; |
|
668 | - $args['multiple'] = true; |
|
669 | - } |
|
670 | - |
|
671 | - // select2 placeholder |
|
672 | - if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){ |
|
673 | - $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | - $args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']); |
|
675 | - } |
|
676 | - |
|
677 | - // label |
|
678 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | - }elseif(!empty($args['label']) && !$label_after){ |
|
680 | - $label_args = array( |
|
681 | - 'title'=> $args['label'], |
|
682 | - 'for'=> $args['id'], |
|
683 | - 'class' => $args['label_class']." ", |
|
684 | - 'label_type' => $args['label_type'] |
|
685 | - ); |
|
686 | - $output .= self::label($label_args); |
|
687 | - } |
|
688 | - |
|
689 | - // maybe horizontal label |
|
690 | - if($args['label_type']=='horizontal'){ |
|
691 | - $output .= '<div class="col-sm-10">'; |
|
692 | - } |
|
693 | - |
|
694 | - // open/type |
|
695 | - $output .= '<select '; |
|
696 | - |
|
697 | - // style |
|
698 | - if($is_select2){ |
|
699 | - $output .= " style='width:100%;' "; |
|
700 | - } |
|
701 | - |
|
702 | - // element require |
|
703 | - if(!empty($args['element_require'])){ |
|
704 | - $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | - $args['class'] .= " aui-conditional-field"; |
|
706 | - } |
|
707 | - |
|
708 | - // class |
|
709 | - $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | - $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | - |
|
712 | - // name |
|
713 | - if(!empty($args['name'])){ |
|
714 | - $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | - } |
|
716 | - |
|
717 | - // id |
|
718 | - if(!empty($args['id'])){ |
|
719 | - $output .= AUI_Component_Helper::id($args['id']); |
|
720 | - } |
|
721 | - |
|
722 | - // title |
|
723 | - if(!empty($args['title'])){ |
|
724 | - $output .= AUI_Component_Helper::title($args['title']); |
|
725 | - } |
|
726 | - |
|
727 | - // data-attributes |
|
728 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | - |
|
730 | - // aria-attributes |
|
731 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | - |
|
733 | - // extra attributes |
|
734 | - if(!empty($args['extra_attributes'])){ |
|
735 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | - } |
|
737 | - |
|
738 | - // required |
|
739 | - if(!empty($args['required'])){ |
|
740 | - $output .= ' required '; |
|
741 | - } |
|
742 | - |
|
743 | - // multiple |
|
744 | - if(!empty($args['multiple'])){ |
|
745 | - $output .= ' multiple '; |
|
746 | - } |
|
747 | - |
|
748 | - // close opening tag |
|
749 | - $output .= ' >'; |
|
750 | - |
|
751 | - // placeholder |
|
752 | - if(!empty($args['placeholder']) && !$is_select2){ |
|
753 | - $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | - }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | - $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | - } |
|
757 | - |
|
758 | - // Options |
|
759 | - if(!empty($args['options'])){ |
|
760 | - |
|
761 | - if(!is_array($args['options'])){ |
|
762 | - $output .= $args['options']; // not the preferred way but an option |
|
763 | - }else{ |
|
764 | - foreach($args['options'] as $val => $name){ |
|
765 | - $selected = ''; |
|
766 | - if(is_array($name)){ |
|
767 | - if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | - |
|
770 | - $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | - } else { |
|
772 | - $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | - $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | - if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | - $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | - } elseif(!empty($args['value'])) { |
|
777 | - $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | - } |
|
779 | - |
|
780 | - $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | - } |
|
782 | - }else{ |
|
783 | - if(!empty($args['value'])){ |
|
784 | - if(is_array($args['value'])){ |
|
785 | - $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | - } elseif(!empty($args['value'])) { |
|
787 | - $selected = selected( $args['value'], $val, false); |
|
788 | - } |
|
789 | - } |
|
790 | - $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | - } |
|
792 | - } |
|
793 | - } |
|
794 | - |
|
795 | - } |
|
796 | - |
|
797 | - // closing tag |
|
798 | - $output .= '</select>'; |
|
799 | - |
|
800 | - if(!empty($args['label']) && $label_after){ |
|
801 | - $label_args = array( |
|
802 | - 'title'=> $args['label'], |
|
803 | - 'for'=> $args['id'], |
|
804 | - 'class' => $args['label_class']." ", |
|
805 | - 'label_type' => $args['label_type'] |
|
806 | - ); |
|
807 | - $output .= self::label($label_args); |
|
808 | - } |
|
809 | - |
|
810 | - // help text |
|
811 | - if(!empty($args['help_text'])){ |
|
812 | - $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | - } |
|
814 | - |
|
815 | - // maybe horizontal label |
|
816 | - if($args['label_type']=='horizontal'){ |
|
817 | - $output .= '</div>'; |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - // wrap |
|
822 | - if(!$args['no_wrap']){ |
|
823 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | - $output = self::wrap(array( |
|
826 | - 'content' => $output, |
|
827 | - 'class' => $wrap_class, |
|
828 | - 'element_require' => $args['element_require'], |
|
829 | - 'argument_id' => $args['id'] |
|
830 | - )); |
|
831 | - } |
|
832 | - |
|
833 | - |
|
834 | - return $output; |
|
835 | - } |
|
836 | - |
|
837 | - /** |
|
838 | - * Build the component. |
|
839 | - * |
|
840 | - * @param array $args |
|
841 | - * |
|
842 | - * @return string The rendered component. |
|
843 | - */ |
|
844 | - public static function radio($args = array()){ |
|
845 | - $defaults = array( |
|
846 | - 'class' => '', |
|
847 | - 'wrap_class' => '', |
|
848 | - 'id' => '', |
|
849 | - 'title' => '', |
|
850 | - 'horizontal' => false, // sets the lable horizontal |
|
851 | - 'value' => '', |
|
852 | - 'label' => '', |
|
853 | - 'label_class'=> '', |
|
854 | - 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | - 'inline' => true, |
|
856 | - 'required' => false, |
|
857 | - 'options' => array(), |
|
858 | - 'icon' => '', |
|
859 | - 'no_wrap' => false, |
|
860 | - 'element_require' => '', // [%element_id%] == "1" |
|
861 | - 'extra_attributes' => array() // an array of extra attributes |
|
862 | - ); |
|
863 | - |
|
864 | - /** |
|
865 | - * Parse incoming $args into an array and merge it with $defaults |
|
866 | - */ |
|
867 | - $args = wp_parse_args( $args, $defaults ); |
|
868 | - |
|
869 | - // for now lets use horizontal for floating |
|
870 | - if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | - |
|
872 | - $label_args = array( |
|
873 | - 'title'=> $args['label'], |
|
874 | - 'class' => $args['label_class']." pt-0 ", |
|
875 | - 'label_type' => $args['label_type'] |
|
876 | - ); |
|
877 | - |
|
878 | - $output = ''; |
|
879 | - |
|
880 | - |
|
881 | - |
|
882 | - // label before |
|
883 | - if(!empty($args['label'])){ |
|
884 | - $output .= self::label( $label_args, 'radio' ); |
|
885 | - } |
|
886 | - |
|
887 | - // maybe horizontal label |
|
888 | - if($args['label_type']=='horizontal'){ |
|
889 | - $output .= '<div class="col-sm-10">'; |
|
890 | - } |
|
891 | - |
|
892 | - if(!empty($args['options'])){ |
|
893 | - $count = 0; |
|
894 | - foreach($args['options'] as $value => $label){ |
|
895 | - $option_args = $args; |
|
896 | - $option_args['value'] = $value; |
|
897 | - $option_args['label'] = $label; |
|
898 | - $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | - $output .= self::radio_option($option_args,$count); |
|
900 | - $count++; |
|
901 | - } |
|
902 | - } |
|
903 | - |
|
904 | - // maybe horizontal label |
|
905 | - if($args['label_type']=='horizontal'){ |
|
906 | - $output .= '</div>'; |
|
907 | - } |
|
908 | - |
|
909 | - |
|
910 | - // wrap |
|
911 | - $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | - $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | - $output = self::wrap(array( |
|
914 | - 'content' => $output, |
|
915 | - 'class' => $wrap_class, |
|
916 | - 'element_require' => $args['element_require'], |
|
917 | - 'argument_id' => $args['id'] |
|
918 | - )); |
|
919 | - |
|
920 | - |
|
921 | - return $output; |
|
922 | - } |
|
923 | - |
|
924 | - /** |
|
925 | - * Build the component. |
|
926 | - * |
|
927 | - * @param array $args |
|
928 | - * |
|
929 | - * @return string The rendered component. |
|
930 | - */ |
|
931 | - public static function radio_option($args = array(),$count = ''){ |
|
932 | - $defaults = array( |
|
933 | - 'class' => '', |
|
934 | - 'id' => '', |
|
935 | - 'title' => '', |
|
936 | - 'value' => '', |
|
937 | - 'required' => false, |
|
938 | - 'inline' => true, |
|
939 | - 'label' => '', |
|
940 | - 'options' => array(), |
|
941 | - 'icon' => '', |
|
942 | - 'no_wrap' => false, |
|
943 | - 'extra_attributes' => array() // an array of extra attributes |
|
944 | - ); |
|
945 | - |
|
946 | - /** |
|
947 | - * Parse incoming $args into an array and merge it with $defaults |
|
948 | - */ |
|
949 | - $args = wp_parse_args( $args, $defaults ); |
|
950 | - |
|
951 | - $output = ''; |
|
952 | - |
|
953 | - // open/type |
|
954 | - $output .= '<input type="radio"'; |
|
955 | - |
|
956 | - // class |
|
957 | - $output .= ' class="form-check-input" '; |
|
958 | - |
|
959 | - // name |
|
960 | - if(!empty($args['name'])){ |
|
961 | - $output .= AUI_Component_Helper::name($args['name']); |
|
962 | - } |
|
963 | - |
|
964 | - // id |
|
965 | - if(!empty($args['id'])){ |
|
966 | - $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | - } |
|
968 | - |
|
969 | - // title |
|
970 | - if(!empty($args['title'])){ |
|
971 | - $output .= AUI_Component_Helper::title($args['title']); |
|
972 | - } |
|
973 | - |
|
974 | - // value |
|
975 | - if(isset($args['value'])){ |
|
976 | - $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | - } |
|
978 | - |
|
979 | - // checked, for radio and checkboxes |
|
980 | - if( $args['checked'] ){ |
|
981 | - $output .= ' checked '; |
|
982 | - } |
|
983 | - |
|
984 | - // data-attributes |
|
985 | - $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | - |
|
987 | - // aria-attributes |
|
988 | - $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | - |
|
990 | - // extra attributes |
|
991 | - if(!empty($args['extra_attributes'])){ |
|
992 | - $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | - } |
|
994 | - |
|
995 | - // required |
|
996 | - if(!empty($args['required'])){ |
|
997 | - $output .= ' required '; |
|
998 | - } |
|
999 | - |
|
1000 | - // close opening tag |
|
1001 | - $output .= ' >'; |
|
1002 | - |
|
1003 | - // label |
|
1004 | - if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | - }elseif(!empty($args['label'])){ |
|
1006 | - $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | - } |
|
1008 | - |
|
1009 | - // wrap |
|
1010 | - if(!$args['no_wrap']){ |
|
1011 | - $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | - $output = self::wrap(array( |
|
1013 | - 'content' => $output, |
|
1014 | - 'class' => $wrap_class |
|
1015 | - )); |
|
1016 | - } |
|
1017 | - |
|
1018 | - |
|
1019 | - return $output; |
|
1020 | - } |
|
213 | + } |
|
214 | + |
|
215 | + // input group wraps |
|
216 | + if($args['input_group_left'] || $args['input_group_right']){ |
|
217 | + $w100 = strpos($args['class'], 'w-100') !== false ? ' w-100' : ''; |
|
218 | + if($args['input_group_left']){ |
|
219 | + $output = self::wrap( array( |
|
220 | + 'content' => $output, |
|
221 | + 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
222 | + 'input_group_left' => $args['input_group_left'], |
|
223 | + 'input_group_left_inside' => $args['input_group_left_inside'] |
|
224 | + ) ); |
|
225 | + } |
|
226 | + if($args['input_group_right']){ |
|
227 | + $output = self::wrap( array( |
|
228 | + 'content' => $output, |
|
229 | + 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative'.$w100 : 'input-group', |
|
230 | + 'input_group_right' => $args['input_group_right'], |
|
231 | + 'input_group_right_inside' => $args['input_group_right_inside'] |
|
232 | + ) ); |
|
233 | + } |
|
234 | + |
|
235 | + } |
|
236 | + |
|
237 | + if(!$label_after){ |
|
238 | + $output .= $help_text; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
243 | + $output = self::wrap( array( |
|
244 | + 'content' => $output, |
|
245 | + 'class' => 'col-sm-10', |
|
246 | + ) ); |
|
247 | + } |
|
248 | + |
|
249 | + if(!$label_after){ |
|
250 | + $output = $label . $output; |
|
251 | + } |
|
252 | + |
|
253 | + // wrap |
|
254 | + if(!$args['no_wrap']){ |
|
255 | + |
|
256 | + $form_group_class = $args['label_type']=='floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; |
|
257 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
258 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
259 | + $output = self::wrap(array( |
|
260 | + 'content' => $output, |
|
261 | + 'class' => $wrap_class, |
|
262 | + 'element_require' => $args['element_require'], |
|
263 | + 'argument_id' => $args['id'] |
|
264 | + )); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + |
|
269 | + } |
|
270 | + |
|
271 | + return $output; |
|
272 | + } |
|
273 | + |
|
274 | + /** |
|
275 | + * Build the component. |
|
276 | + * |
|
277 | + * @param array $args |
|
278 | + * |
|
279 | + * @return string The rendered component. |
|
280 | + */ |
|
281 | + public static function textarea($args = array()){ |
|
282 | + $defaults = array( |
|
283 | + 'name' => '', |
|
284 | + 'class' => '', |
|
285 | + 'wrap_class' => '', |
|
286 | + 'id' => '', |
|
287 | + 'placeholder'=> '', |
|
288 | + 'title' => '', |
|
289 | + 'value' => '', |
|
290 | + 'required' => false, |
|
291 | + 'label' => '', |
|
292 | + 'label_after'=> false, |
|
293 | + 'label_class' => '', |
|
294 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
295 | + 'help_text' => '', |
|
296 | + 'validation_text' => '', |
|
297 | + 'validation_pattern' => '', |
|
298 | + 'no_wrap' => false, |
|
299 | + 'rows' => '', |
|
300 | + 'wysiwyg' => false, |
|
301 | + 'element_require' => '', // [%element_id%] == "1" |
|
302 | + ); |
|
303 | + |
|
304 | + /** |
|
305 | + * Parse incoming $args into an array and merge it with $defaults |
|
306 | + */ |
|
307 | + $args = wp_parse_args( $args, $defaults ); |
|
308 | + $output = ''; |
|
309 | + |
|
310 | + // hidden label option needs to be empty |
|
311 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
312 | + |
|
313 | + // floating labels don't work with wysiwyg so set it as top |
|
314 | + if($args['label_type'] == 'floating' && !empty($args['wysiwyg'])){ |
|
315 | + $args['label_type'] = 'top'; |
|
316 | + } |
|
317 | + |
|
318 | + $label_after = $args['label_after']; |
|
319 | + |
|
320 | + // floating labels need label after |
|
321 | + if( $args['label_type'] == 'floating' && empty($args['wysiwyg']) ){ |
|
322 | + $label_after = true; |
|
323 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
324 | + } |
|
325 | + |
|
326 | + // label |
|
327 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
328 | + }elseif(!empty($args['label']) && !$label_after){ |
|
329 | + $label_args = array( |
|
330 | + 'title'=> $args['label'], |
|
331 | + 'for'=> $args['id'], |
|
332 | + 'class' => $args['label_class']." ", |
|
333 | + 'label_type' => $args['label_type'] |
|
334 | + ); |
|
335 | + $output .= self::label( $label_args ); |
|
336 | + } |
|
337 | + |
|
338 | + // maybe horizontal label |
|
339 | + if($args['label_type']=='horizontal'){ |
|
340 | + $output .= '<div class="col-sm-10">'; |
|
341 | + } |
|
342 | + |
|
343 | + if(!empty($args['wysiwyg'])){ |
|
344 | + ob_start(); |
|
345 | + $content = $args['value']; |
|
346 | + $editor_id = !empty($args['id']) ? sanitize_html_class($args['id']) : 'wp_editor'; |
|
347 | + $settings = array( |
|
348 | + 'textarea_rows' => !empty(absint($args['rows'])) ? absint($args['rows']) : 4, |
|
349 | + 'quicktags' => false, |
|
350 | + 'media_buttons' => false, |
|
351 | + 'editor_class' => 'form-control', |
|
352 | + 'textarea_name' => !empty($args['name']) ? sanitize_html_class($args['name']) : sanitize_html_class($args['id']), |
|
353 | + 'teeny' => true, |
|
354 | + ); |
|
355 | + |
|
356 | + // maybe set settings if array |
|
357 | + if(is_array($args['wysiwyg'])){ |
|
358 | + $settings = wp_parse_args( $args['wysiwyg'], $settings ); |
|
359 | + } |
|
360 | + |
|
361 | + wp_editor( $content, $editor_id, $settings ); |
|
362 | + $output .= ob_get_clean(); |
|
363 | + }else{ |
|
364 | + |
|
365 | + // open |
|
366 | + $output .= '<textarea '; |
|
367 | + |
|
368 | + // name |
|
369 | + if(!empty($args['name'])){ |
|
370 | + $output .= ' name="'.sanitize_html_class($args['name']).'" '; |
|
371 | + } |
|
372 | + |
|
373 | + // id |
|
374 | + if(!empty($args['id'])){ |
|
375 | + $output .= ' id="'.sanitize_html_class($args['id']).'" '; |
|
376 | + } |
|
377 | + |
|
378 | + // placeholder |
|
379 | + if(!empty($args['placeholder'])){ |
|
380 | + $output .= ' placeholder="'.esc_attr($args['placeholder']).'" '; |
|
381 | + } |
|
382 | + |
|
383 | + // title |
|
384 | + if(!empty($args['title'])){ |
|
385 | + $output .= ' title="'.esc_attr($args['title']).'" '; |
|
386 | + } |
|
387 | + |
|
388 | + // validation text |
|
389 | + if(!empty($args['validation_text'])){ |
|
390 | + $output .= ' oninvalid="setCustomValidity(\''.esc_attr($args['validation_text']).'\')" '; |
|
391 | + $output .= ' onchange="try{setCustomValidity(\'\')}catch(e){}" '; |
|
392 | + } |
|
393 | + |
|
394 | + // validation_pattern |
|
395 | + if(!empty($args['validation_pattern'])){ |
|
396 | + $output .= ' pattern="'.$args['validation_pattern'].'" '; |
|
397 | + } |
|
398 | + |
|
399 | + // required |
|
400 | + if(!empty($args['required'])){ |
|
401 | + $output .= ' required '; |
|
402 | + } |
|
403 | + |
|
404 | + // rows |
|
405 | + if(!empty($args['rows'])){ |
|
406 | + $output .= ' rows="'.absint($args['rows']).'" '; |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + // class |
|
411 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
412 | + $output .= ' class="form-control '.$class.'" '; |
|
413 | + |
|
414 | + |
|
415 | + // close tag |
|
416 | + $output .= ' >'; |
|
417 | + |
|
418 | + // value |
|
419 | + if(!empty($args['value'])){ |
|
420 | + $output .= sanitize_textarea_field($args['value']); |
|
421 | + } |
|
422 | + |
|
423 | + // closing tag |
|
424 | + $output .= '</textarea>'; |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + if(!empty($args['label']) && $label_after){ |
|
429 | + $label_args = array( |
|
430 | + 'title'=> $args['label'], |
|
431 | + 'for'=> $args['id'], |
|
432 | + 'class' => $args['label_class']." ", |
|
433 | + 'label_type' => $args['label_type'] |
|
434 | + ); |
|
435 | + $output .= self::label( $label_args ); |
|
436 | + } |
|
437 | + |
|
438 | + // help text |
|
439 | + if(!empty($args['help_text'])){ |
|
440 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
441 | + } |
|
442 | + |
|
443 | + // maybe horizontal label |
|
444 | + if($args['label_type']=='horizontal'){ |
|
445 | + $output .= '</div>'; |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + // wrap |
|
450 | + if(!$args['no_wrap']){ |
|
451 | + $form_group_class = $args['label_type']=='floating' ? 'form-label-group' : 'form-group'; |
|
452 | + $wrap_class = $args['label_type']=='horizontal' ? $form_group_class . ' row' : $form_group_class; |
|
453 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
454 | + $output = self::wrap(array( |
|
455 | + 'content' => $output, |
|
456 | + 'class' => $wrap_class, |
|
457 | + 'element_require' => $args['element_require'], |
|
458 | + 'argument_id' => $args['id'] |
|
459 | + )); |
|
460 | + } |
|
461 | + |
|
462 | + |
|
463 | + return $output; |
|
464 | + } |
|
465 | + |
|
466 | + public static function label($args = array(), $type = ''){ |
|
467 | + //<label for="exampleInputEmail1">Email address</label> |
|
468 | + $defaults = array( |
|
469 | + 'title' => 'div', |
|
470 | + 'for' => '', |
|
471 | + 'class' => '', |
|
472 | + 'label_type' => '', // empty = hidden, top, horizontal |
|
473 | + ); |
|
474 | + |
|
475 | + /** |
|
476 | + * Parse incoming $args into an array and merge it with $defaults |
|
477 | + */ |
|
478 | + $args = wp_parse_args( $args, $defaults ); |
|
479 | + $output = ''; |
|
480 | + |
|
481 | + if($args['title']){ |
|
482 | + |
|
483 | + // maybe hide labels //@todo set a global option for visibility class |
|
484 | + if($type == 'file' || $type == 'checkbox' || $type == 'radio' || !empty($args['label_type']) ){ |
|
485 | + $class = $args['class']; |
|
486 | + }else{ |
|
487 | + $class = 'sr-only '.$args['class']; |
|
488 | + } |
|
489 | + |
|
490 | + // maybe horizontal |
|
491 | + if($args['label_type']=='horizontal' && $type != 'checkbox'){ |
|
492 | + $class .= ' col-sm-2 col-form-label'; |
|
493 | + } |
|
494 | + |
|
495 | + // open |
|
496 | + $output .= '<label '; |
|
497 | + |
|
498 | + // for |
|
499 | + if(!empty($args['for'])){ |
|
500 | + $output .= ' for="'.sanitize_text_field($args['for']).'" '; |
|
501 | + } |
|
502 | + |
|
503 | + // class |
|
504 | + $class = $class ? AUI_Component_Helper::esc_classes( $class ) : ''; |
|
505 | + $output .= ' class="'.$class.'" '; |
|
506 | + |
|
507 | + // close |
|
508 | + $output .= '>'; |
|
509 | + |
|
510 | + |
|
511 | + // title, don't escape fully as can contain html |
|
512 | + if(!empty($args['title'])){ |
|
513 | + $output .= wp_kses_post($args['title']); |
|
514 | + } |
|
515 | + |
|
516 | + // close wrap |
|
517 | + $output .= '</label>'; |
|
518 | + |
|
519 | + |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + return $output; |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Wrap some content in a HTML wrapper. |
|
528 | + * |
|
529 | + * @param array $args |
|
530 | + * |
|
531 | + * @return string |
|
532 | + */ |
|
533 | + public static function wrap($args = array()){ |
|
534 | + $defaults = array( |
|
535 | + 'type' => 'div', |
|
536 | + 'class' => 'form-group', |
|
537 | + 'content' => '', |
|
538 | + 'input_group_left' => '', |
|
539 | + 'input_group_right' => '', |
|
540 | + 'input_group_left_inside' => false, |
|
541 | + 'input_group_right_inside' => false, |
|
542 | + 'element_require' => '', |
|
543 | + 'argument_id' => '', |
|
544 | + ); |
|
545 | + |
|
546 | + /** |
|
547 | + * Parse incoming $args into an array and merge it with $defaults |
|
548 | + */ |
|
549 | + $args = wp_parse_args( $args, $defaults ); |
|
550 | + $output = ''; |
|
551 | + if($args['type']){ |
|
552 | + |
|
553 | + // open |
|
554 | + $output .= '<'.sanitize_html_class($args['type']); |
|
555 | + |
|
556 | + // element require |
|
557 | + if(!empty($args['element_require'])){ |
|
558 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
559 | + $args['class'] .= " aui-conditional-field"; |
|
560 | + } |
|
561 | + |
|
562 | + // argument_id |
|
563 | + if( !empty($args['argument_id']) ){ |
|
564 | + $output .= ' data-argument="'.esc_attr($args['argument_id']).'"'; |
|
565 | + } |
|
566 | + |
|
567 | + // class |
|
568 | + $class = !empty($args['class']) ? AUI_Component_Helper::esc_classes( $args['class'] ) : ''; |
|
569 | + $output .= ' class="'.$class.'" '; |
|
570 | + |
|
571 | + // close wrap |
|
572 | + $output .= ' >'; |
|
573 | + |
|
574 | + |
|
575 | + // Input group left |
|
576 | + if(!empty($args['input_group_left'])){ |
|
577 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
578 | + $input_group_left = strpos($args['input_group_left'], '<') !== false ? $args['input_group_left'] : '<span class="input-group-text">'.$args['input_group_left'].'</span>'; |
|
579 | + $output .= '<div class="input-group-prepend '.$position_class.'">'.$input_group_left.'</div>'; |
|
580 | + } |
|
581 | + |
|
582 | + // content |
|
583 | + $output .= $args['content']; |
|
584 | + |
|
585 | + // Input group right |
|
586 | + if(!empty($args['input_group_right'])){ |
|
587 | + $position_class = !empty($args['input_group_left_inside']) ? 'position-absolute h-100' : ''; |
|
588 | + $input_group_right = strpos($args['input_group_right'], '<') !== false ? $args['input_group_right'] : '<span class="input-group-text">'.$args['input_group_right'].'</span>'; |
|
589 | + $output .= '<div class="input-group-append '.$position_class.'">'.$input_group_right.'</div>'; |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + // close wrap |
|
594 | + $output .= '</'.sanitize_html_class($args['type']).'>'; |
|
595 | + |
|
596 | + |
|
597 | + }else{ |
|
598 | + $output = $args['content']; |
|
599 | + } |
|
600 | + |
|
601 | + return $output; |
|
602 | + } |
|
603 | + |
|
604 | + /** |
|
605 | + * Build the component. |
|
606 | + * |
|
607 | + * @param array $args |
|
608 | + * |
|
609 | + * @return string The rendered component. |
|
610 | + */ |
|
611 | + public static function select($args = array()){ |
|
612 | + $defaults = array( |
|
613 | + 'class' => '', |
|
614 | + 'wrap_class' => '', |
|
615 | + 'id' => '', |
|
616 | + 'title' => '', |
|
617 | + 'value' => '', // can be an array or a string |
|
618 | + 'required' => false, |
|
619 | + 'label' => '', |
|
620 | + 'label_after'=> false, |
|
621 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
622 | + 'label_class' => '', |
|
623 | + 'help_text' => '', |
|
624 | + 'placeholder'=> '', |
|
625 | + 'options' => array(), // array or string |
|
626 | + 'icon' => '', |
|
627 | + 'multiple' => false, |
|
628 | + 'select2' => false, |
|
629 | + 'no_wrap' => false, |
|
630 | + 'element_require' => '', // [%element_id%] == "1" |
|
631 | + 'extra_attributes' => array(), // an array of extra attributes |
|
632 | + ); |
|
633 | + |
|
634 | + /** |
|
635 | + * Parse incoming $args into an array and merge it with $defaults |
|
636 | + */ |
|
637 | + $args = wp_parse_args( $args, $defaults ); |
|
638 | + $output = ''; |
|
639 | + |
|
640 | + // for now lets hide floating labels |
|
641 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'hidden';} |
|
642 | + |
|
643 | + // hidden label option needs to be empty |
|
644 | + $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; |
|
645 | + |
|
646 | + |
|
647 | + $label_after = $args['label_after']; |
|
648 | + |
|
649 | + // floating labels need label after |
|
650 | + if( $args['label_type'] == 'floating' ){ |
|
651 | + $label_after = true; |
|
652 | + $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. |
|
653 | + } |
|
654 | + |
|
655 | + // Maybe setup select2 |
|
656 | + $is_select2 = false; |
|
657 | + if(!empty($args['select2'])){ |
|
658 | + $args['class'] .= ' aui-select2'; |
|
659 | + $is_select2 = true; |
|
660 | + }elseif( strpos($args['class'], 'aui-select2') !== false){ |
|
661 | + $is_select2 = true; |
|
662 | + } |
|
663 | + |
|
664 | + // select2 tags |
|
665 | + if( !empty($args['select2']) && $args['select2'] === 'tags'){ // triple equals needed here for some reason |
|
666 | + $args['data-tags'] = 'true'; |
|
667 | + $args['data-token-separators'] = "[',']"; |
|
668 | + $args['multiple'] = true; |
|
669 | + } |
|
670 | + |
|
671 | + // select2 placeholder |
|
672 | + if($is_select2 && !empty($args['placeholder']) && empty($args['data-placeholder'])){ |
|
673 | + $args['data-placeholder'] = esc_attr($args['placeholder']); |
|
674 | + $args['data-allow-clear'] = empty($args['data-allow-clear']) ? true : esc_attr($args['data-allow-clear']); |
|
675 | + } |
|
676 | + |
|
677 | + // label |
|
678 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
679 | + }elseif(!empty($args['label']) && !$label_after){ |
|
680 | + $label_args = array( |
|
681 | + 'title'=> $args['label'], |
|
682 | + 'for'=> $args['id'], |
|
683 | + 'class' => $args['label_class']." ", |
|
684 | + 'label_type' => $args['label_type'] |
|
685 | + ); |
|
686 | + $output .= self::label($label_args); |
|
687 | + } |
|
688 | + |
|
689 | + // maybe horizontal label |
|
690 | + if($args['label_type']=='horizontal'){ |
|
691 | + $output .= '<div class="col-sm-10">'; |
|
692 | + } |
|
693 | + |
|
694 | + // open/type |
|
695 | + $output .= '<select '; |
|
696 | + |
|
697 | + // style |
|
698 | + if($is_select2){ |
|
699 | + $output .= " style='width:100%;' "; |
|
700 | + } |
|
701 | + |
|
702 | + // element require |
|
703 | + if(!empty($args['element_require'])){ |
|
704 | + $output .= AUI_Component_Helper::element_require($args['element_require']); |
|
705 | + $args['class'] .= " aui-conditional-field"; |
|
706 | + } |
|
707 | + |
|
708 | + // class |
|
709 | + $class = !empty($args['class']) ? $args['class'] : ''; |
|
710 | + $output .= AUI_Component_Helper::class_attr('custom-select '.$class); |
|
711 | + |
|
712 | + // name |
|
713 | + if(!empty($args['name'])){ |
|
714 | + $output .= AUI_Component_Helper::name($args['name'],$args['multiple']); |
|
715 | + } |
|
716 | + |
|
717 | + // id |
|
718 | + if(!empty($args['id'])){ |
|
719 | + $output .= AUI_Component_Helper::id($args['id']); |
|
720 | + } |
|
721 | + |
|
722 | + // title |
|
723 | + if(!empty($args['title'])){ |
|
724 | + $output .= AUI_Component_Helper::title($args['title']); |
|
725 | + } |
|
726 | + |
|
727 | + // data-attributes |
|
728 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
729 | + |
|
730 | + // aria-attributes |
|
731 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
732 | + |
|
733 | + // extra attributes |
|
734 | + if(!empty($args['extra_attributes'])){ |
|
735 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
736 | + } |
|
737 | + |
|
738 | + // required |
|
739 | + if(!empty($args['required'])){ |
|
740 | + $output .= ' required '; |
|
741 | + } |
|
742 | + |
|
743 | + // multiple |
|
744 | + if(!empty($args['multiple'])){ |
|
745 | + $output .= ' multiple '; |
|
746 | + } |
|
747 | + |
|
748 | + // close opening tag |
|
749 | + $output .= ' >'; |
|
750 | + |
|
751 | + // placeholder |
|
752 | + if(!empty($args['placeholder']) && !$is_select2){ |
|
753 | + $output .= '<option value="" disabled selected hidden>'.esc_attr($args['placeholder']).'</option>'; |
|
754 | + }elseif($is_select2 && !empty($args['placeholder'])){ |
|
755 | + $output .= "<option></option>"; // select2 needs an empty select to fill the placeholder |
|
756 | + } |
|
757 | + |
|
758 | + // Options |
|
759 | + if(!empty($args['options'])){ |
|
760 | + |
|
761 | + if(!is_array($args['options'])){ |
|
762 | + $output .= $args['options']; // not the preferred way but an option |
|
763 | + }else{ |
|
764 | + foreach($args['options'] as $val => $name){ |
|
765 | + $selected = ''; |
|
766 | + if(is_array($name)){ |
|
767 | + if (isset($name['optgroup']) && ($name['optgroup'] == 'start' || $name['optgroup'] == 'end')) { |
|
768 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
769 | + |
|
770 | + $output .= $name['optgroup'] == 'start' ? '<optgroup label="' . esc_attr($option_label) . '">' : '</optgroup>'; |
|
771 | + } else { |
|
772 | + $option_label = isset($name['label']) ? $name['label'] : ''; |
|
773 | + $option_value = isset($name['value']) ? $name['value'] : ''; |
|
774 | + if(!empty($args['multiple']) && !empty($args['value']) && is_array($args['value']) ){ |
|
775 | + $selected = in_array($option_value, stripslashes_deep($args['value'])) ? "selected" : ""; |
|
776 | + } elseif(!empty($args['value'])) { |
|
777 | + $selected = selected($option_value,stripslashes_deep($args['value']), false); |
|
778 | + } |
|
779 | + |
|
780 | + $output .= '<option value="' . esc_attr($option_value) . '" ' . $selected . '>' . $option_label . '</option>'; |
|
781 | + } |
|
782 | + }else{ |
|
783 | + if(!empty($args['value'])){ |
|
784 | + if(is_array($args['value'])){ |
|
785 | + $selected = in_array($val,$args['value']) ? 'selected="selected"' : ''; |
|
786 | + } elseif(!empty($args['value'])) { |
|
787 | + $selected = selected( $args['value'], $val, false); |
|
788 | + } |
|
789 | + } |
|
790 | + $output .= '<option value="'.esc_attr($val).'" '.$selected.'>'.esc_attr($name).'</option>'; |
|
791 | + } |
|
792 | + } |
|
793 | + } |
|
794 | + |
|
795 | + } |
|
796 | + |
|
797 | + // closing tag |
|
798 | + $output .= '</select>'; |
|
799 | + |
|
800 | + if(!empty($args['label']) && $label_after){ |
|
801 | + $label_args = array( |
|
802 | + 'title'=> $args['label'], |
|
803 | + 'for'=> $args['id'], |
|
804 | + 'class' => $args['label_class']." ", |
|
805 | + 'label_type' => $args['label_type'] |
|
806 | + ); |
|
807 | + $output .= self::label($label_args); |
|
808 | + } |
|
809 | + |
|
810 | + // help text |
|
811 | + if(!empty($args['help_text'])){ |
|
812 | + $output .= AUI_Component_Helper::help_text($args['help_text']); |
|
813 | + } |
|
814 | + |
|
815 | + // maybe horizontal label |
|
816 | + if($args['label_type']=='horizontal'){ |
|
817 | + $output .= '</div>'; |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + // wrap |
|
822 | + if(!$args['no_wrap']){ |
|
823 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
824 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
825 | + $output = self::wrap(array( |
|
826 | + 'content' => $output, |
|
827 | + 'class' => $wrap_class, |
|
828 | + 'element_require' => $args['element_require'], |
|
829 | + 'argument_id' => $args['id'] |
|
830 | + )); |
|
831 | + } |
|
832 | + |
|
833 | + |
|
834 | + return $output; |
|
835 | + } |
|
836 | + |
|
837 | + /** |
|
838 | + * Build the component. |
|
839 | + * |
|
840 | + * @param array $args |
|
841 | + * |
|
842 | + * @return string The rendered component. |
|
843 | + */ |
|
844 | + public static function radio($args = array()){ |
|
845 | + $defaults = array( |
|
846 | + 'class' => '', |
|
847 | + 'wrap_class' => '', |
|
848 | + 'id' => '', |
|
849 | + 'title' => '', |
|
850 | + 'horizontal' => false, // sets the lable horizontal |
|
851 | + 'value' => '', |
|
852 | + 'label' => '', |
|
853 | + 'label_class'=> '', |
|
854 | + 'label_type' => '', // sets the label type, default: hidden. Options: hidden, top, horizontal, floating |
|
855 | + 'inline' => true, |
|
856 | + 'required' => false, |
|
857 | + 'options' => array(), |
|
858 | + 'icon' => '', |
|
859 | + 'no_wrap' => false, |
|
860 | + 'element_require' => '', // [%element_id%] == "1" |
|
861 | + 'extra_attributes' => array() // an array of extra attributes |
|
862 | + ); |
|
863 | + |
|
864 | + /** |
|
865 | + * Parse incoming $args into an array and merge it with $defaults |
|
866 | + */ |
|
867 | + $args = wp_parse_args( $args, $defaults ); |
|
868 | + |
|
869 | + // for now lets use horizontal for floating |
|
870 | + if( $args['label_type'] == 'floating' ){$args['label_type'] = 'horizontal';} |
|
871 | + |
|
872 | + $label_args = array( |
|
873 | + 'title'=> $args['label'], |
|
874 | + 'class' => $args['label_class']." pt-0 ", |
|
875 | + 'label_type' => $args['label_type'] |
|
876 | + ); |
|
877 | + |
|
878 | + $output = ''; |
|
879 | + |
|
880 | + |
|
881 | + |
|
882 | + // label before |
|
883 | + if(!empty($args['label'])){ |
|
884 | + $output .= self::label( $label_args, 'radio' ); |
|
885 | + } |
|
886 | + |
|
887 | + // maybe horizontal label |
|
888 | + if($args['label_type']=='horizontal'){ |
|
889 | + $output .= '<div class="col-sm-10">'; |
|
890 | + } |
|
891 | + |
|
892 | + if(!empty($args['options'])){ |
|
893 | + $count = 0; |
|
894 | + foreach($args['options'] as $value => $label){ |
|
895 | + $option_args = $args; |
|
896 | + $option_args['value'] = $value; |
|
897 | + $option_args['label'] = $label; |
|
898 | + $option_args['checked'] = $value == $args['value'] ? true : false; |
|
899 | + $output .= self::radio_option($option_args,$count); |
|
900 | + $count++; |
|
901 | + } |
|
902 | + } |
|
903 | + |
|
904 | + // maybe horizontal label |
|
905 | + if($args['label_type']=='horizontal'){ |
|
906 | + $output .= '</div>'; |
|
907 | + } |
|
908 | + |
|
909 | + |
|
910 | + // wrap |
|
911 | + $wrap_class = $args['label_type']=='horizontal' ? 'form-group row' : 'form-group'; |
|
912 | + $wrap_class = !empty($args['wrap_class']) ? $wrap_class." ".$args['wrap_class'] : $wrap_class; |
|
913 | + $output = self::wrap(array( |
|
914 | + 'content' => $output, |
|
915 | + 'class' => $wrap_class, |
|
916 | + 'element_require' => $args['element_require'], |
|
917 | + 'argument_id' => $args['id'] |
|
918 | + )); |
|
919 | + |
|
920 | + |
|
921 | + return $output; |
|
922 | + } |
|
923 | + |
|
924 | + /** |
|
925 | + * Build the component. |
|
926 | + * |
|
927 | + * @param array $args |
|
928 | + * |
|
929 | + * @return string The rendered component. |
|
930 | + */ |
|
931 | + public static function radio_option($args = array(),$count = ''){ |
|
932 | + $defaults = array( |
|
933 | + 'class' => '', |
|
934 | + 'id' => '', |
|
935 | + 'title' => '', |
|
936 | + 'value' => '', |
|
937 | + 'required' => false, |
|
938 | + 'inline' => true, |
|
939 | + 'label' => '', |
|
940 | + 'options' => array(), |
|
941 | + 'icon' => '', |
|
942 | + 'no_wrap' => false, |
|
943 | + 'extra_attributes' => array() // an array of extra attributes |
|
944 | + ); |
|
945 | + |
|
946 | + /** |
|
947 | + * Parse incoming $args into an array and merge it with $defaults |
|
948 | + */ |
|
949 | + $args = wp_parse_args( $args, $defaults ); |
|
950 | + |
|
951 | + $output = ''; |
|
952 | + |
|
953 | + // open/type |
|
954 | + $output .= '<input type="radio"'; |
|
955 | + |
|
956 | + // class |
|
957 | + $output .= ' class="form-check-input" '; |
|
958 | + |
|
959 | + // name |
|
960 | + if(!empty($args['name'])){ |
|
961 | + $output .= AUI_Component_Helper::name($args['name']); |
|
962 | + } |
|
963 | + |
|
964 | + // id |
|
965 | + if(!empty($args['id'])){ |
|
966 | + $output .= AUI_Component_Helper::id($args['id'].$count); |
|
967 | + } |
|
968 | + |
|
969 | + // title |
|
970 | + if(!empty($args['title'])){ |
|
971 | + $output .= AUI_Component_Helper::title($args['title']); |
|
972 | + } |
|
973 | + |
|
974 | + // value |
|
975 | + if(isset($args['value'])){ |
|
976 | + $output .= ' value="'.sanitize_text_field($args['value']).'" '; |
|
977 | + } |
|
978 | + |
|
979 | + // checked, for radio and checkboxes |
|
980 | + if( $args['checked'] ){ |
|
981 | + $output .= ' checked '; |
|
982 | + } |
|
983 | + |
|
984 | + // data-attributes |
|
985 | + $output .= AUI_Component_Helper::data_attributes($args); |
|
986 | + |
|
987 | + // aria-attributes |
|
988 | + $output .= AUI_Component_Helper::aria_attributes($args); |
|
989 | + |
|
990 | + // extra attributes |
|
991 | + if(!empty($args['extra_attributes'])){ |
|
992 | + $output .= AUI_Component_Helper::extra_attributes($args['extra_attributes']); |
|
993 | + } |
|
994 | + |
|
995 | + // required |
|
996 | + if(!empty($args['required'])){ |
|
997 | + $output .= ' required '; |
|
998 | + } |
|
999 | + |
|
1000 | + // close opening tag |
|
1001 | + $output .= ' >'; |
|
1002 | + |
|
1003 | + // label |
|
1004 | + if(!empty($args['label']) && is_array($args['label'])){ |
|
1005 | + }elseif(!empty($args['label'])){ |
|
1006 | + $output .= self::label(array('title'=>$args['label'],'for'=>$args['id'].$count,'class'=>'form-check-label'),'radio'); |
|
1007 | + } |
|
1008 | + |
|
1009 | + // wrap |
|
1010 | + if(!$args['no_wrap']){ |
|
1011 | + $wrap_class = $args['inline'] ? 'form-check form-check-inline' : 'form-check'; |
|
1012 | + $output = self::wrap(array( |
|
1013 | + 'content' => $output, |
|
1014 | + 'class' => $wrap_class |
|
1015 | + )); |
|
1016 | + } |
|
1017 | + |
|
1018 | + |
|
1019 | + return $output; |
|
1020 | + } |
|
1021 | 1021 | |
1022 | 1022 | } |
1023 | 1023 | \ No newline at end of file |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | * Bail if we are not in WP. |
14 | 14 | */ |
15 | 15 | if ( ! defined( 'ABSPATH' ) ) { |
16 | - exit; |
|
16 | + exit; |
|
17 | 17 | } |
18 | 18 | |
19 | 19 | /** |
@@ -21,199 +21,199 @@ discard block |
||
21 | 21 | */ |
22 | 22 | if ( ! class_exists( 'AyeCode_UI_Settings' ) ) { |
23 | 23 | |
24 | - /** |
|
25 | - * A Class to be able to change settings for Font Awesome. |
|
26 | - * |
|
27 | - * Class AyeCode_UI_Settings |
|
28 | - * @ver 1.0.0 |
|
29 | - * @todo decide how to implement textdomain |
|
30 | - */ |
|
31 | - class AyeCode_UI_Settings { |
|
32 | - |
|
33 | - /** |
|
34 | - * Class version version. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - public $version = '1.0.1'; |
|
39 | - |
|
40 | - /** |
|
41 | - * Class textdomain. |
|
42 | - * |
|
43 | - * @var string |
|
44 | - */ |
|
45 | - public $textdomain = 'aui'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Latest version of Bootstrap at time of publish published. |
|
49 | - * |
|
50 | - * @var string |
|
51 | - */ |
|
52 | - public $latest = "4.3.1"; |
|
53 | - |
|
54 | - /** |
|
55 | - * Current version of select2 being used. |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - public $select2_version = "4.0.11"; |
|
60 | - |
|
61 | - /** |
|
62 | - * The title. |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public $name = 'AyeCode UI'; |
|
67 | - |
|
68 | - /** |
|
69 | - * The relative url to the assets. |
|
70 | - * |
|
71 | - * @var string |
|
72 | - */ |
|
73 | - public $url = ''; |
|
74 | - |
|
75 | - /** |
|
76 | - * Holds the settings values. |
|
77 | - * |
|
78 | - * @var array |
|
79 | - */ |
|
80 | - private $settings; |
|
81 | - |
|
82 | - /** |
|
83 | - * AyeCode_UI_Settings instance. |
|
84 | - * |
|
85 | - * @access private |
|
86 | - * @since 1.0.0 |
|
87 | - * @var AyeCode_UI_Settings There can be only one! |
|
88 | - */ |
|
89 | - private static $instance = null; |
|
90 | - |
|
91 | - /** |
|
92 | - * Main AyeCode_UI_Settings Instance. |
|
93 | - * |
|
94 | - * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | - * |
|
96 | - * @since 1.0.0 |
|
97 | - * @static |
|
98 | - * @return AyeCode_UI_Settings - Main instance. |
|
99 | - */ |
|
100 | - public static function instance() { |
|
101 | - if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | - |
|
103 | - self::$instance = new AyeCode_UI_Settings; |
|
104 | - |
|
105 | - add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | - |
|
107 | - if ( is_admin() ) { |
|
108 | - add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | - add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | - |
|
111 | - // Maybe show example page |
|
112 | - add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | - } |
|
24 | + /** |
|
25 | + * A Class to be able to change settings for Font Awesome. |
|
26 | + * |
|
27 | + * Class AyeCode_UI_Settings |
|
28 | + * @ver 1.0.0 |
|
29 | + * @todo decide how to implement textdomain |
|
30 | + */ |
|
31 | + class AyeCode_UI_Settings { |
|
32 | + |
|
33 | + /** |
|
34 | + * Class version version. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + public $version = '1.0.1'; |
|
39 | + |
|
40 | + /** |
|
41 | + * Class textdomain. |
|
42 | + * |
|
43 | + * @var string |
|
44 | + */ |
|
45 | + public $textdomain = 'aui'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Latest version of Bootstrap at time of publish published. |
|
49 | + * |
|
50 | + * @var string |
|
51 | + */ |
|
52 | + public $latest = "4.3.1"; |
|
53 | + |
|
54 | + /** |
|
55 | + * Current version of select2 being used. |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + public $select2_version = "4.0.11"; |
|
60 | + |
|
61 | + /** |
|
62 | + * The title. |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public $name = 'AyeCode UI'; |
|
67 | + |
|
68 | + /** |
|
69 | + * The relative url to the assets. |
|
70 | + * |
|
71 | + * @var string |
|
72 | + */ |
|
73 | + public $url = ''; |
|
74 | + |
|
75 | + /** |
|
76 | + * Holds the settings values. |
|
77 | + * |
|
78 | + * @var array |
|
79 | + */ |
|
80 | + private $settings; |
|
81 | + |
|
82 | + /** |
|
83 | + * AyeCode_UI_Settings instance. |
|
84 | + * |
|
85 | + * @access private |
|
86 | + * @since 1.0.0 |
|
87 | + * @var AyeCode_UI_Settings There can be only one! |
|
88 | + */ |
|
89 | + private static $instance = null; |
|
90 | + |
|
91 | + /** |
|
92 | + * Main AyeCode_UI_Settings Instance. |
|
93 | + * |
|
94 | + * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded. |
|
95 | + * |
|
96 | + * @since 1.0.0 |
|
97 | + * @static |
|
98 | + * @return AyeCode_UI_Settings - Main instance. |
|
99 | + */ |
|
100 | + public static function instance() { |
|
101 | + if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) { |
|
102 | + |
|
103 | + self::$instance = new AyeCode_UI_Settings; |
|
104 | + |
|
105 | + add_action( 'init', array( self::$instance, 'init' ) ); // set settings |
|
106 | + |
|
107 | + if ( is_admin() ) { |
|
108 | + add_action( 'admin_menu', array( self::$instance, 'menu_item' ) ); |
|
109 | + add_action( 'admin_init', array( self::$instance, 'register_settings' ) ); |
|
110 | + |
|
111 | + // Maybe show example page |
|
112 | + add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) ); |
|
113 | + } |
|
114 | 114 | |
115 | - add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | - |
|
117 | - do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | - } |
|
119 | - |
|
120 | - return self::$instance; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Setup some constants. |
|
125 | - */ |
|
126 | - public function constants(){ |
|
127 | - define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | - define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | - if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | - if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Initiate the settings and add the required action hooks. |
|
135 | - */ |
|
136 | - public function init() { |
|
137 | - $this->constants(); |
|
138 | - $this->settings = $this->get_settings(); |
|
139 | - $this->url = $this->get_url(); |
|
140 | - |
|
141 | - /** |
|
142 | - * Maybe load CSS |
|
143 | - * |
|
144 | - * We load super early in case there is a theme version that might change the colors |
|
145 | - */ |
|
146 | - if ( $this->settings['css'] ) { |
|
147 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | - } |
|
149 | - if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | - } |
|
152 | - |
|
153 | - // maybe load JS |
|
154 | - if ( $this->settings['js'] ) { |
|
155 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
156 | - } |
|
157 | - if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
158 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
159 | - } |
|
160 | - |
|
161 | - // Maybe set the HTML font size |
|
162 | - if ( $this->settings['html_font_size'] ) { |
|
163 | - add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * Check if we should load the admin scripts or not. |
|
171 | - * |
|
172 | - * @return bool |
|
173 | - */ |
|
174 | - public function load_admin_scripts(){ |
|
175 | - $result = true; |
|
176 | - |
|
177 | - if(!empty($this->settings['disable_admin'])){ |
|
178 | - $url_parts = explode("\n",$this->settings['disable_admin']); |
|
179 | - foreach($url_parts as $part){ |
|
180 | - if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
181 | - return false; // return early, no point checking further |
|
182 | - } |
|
183 | - } |
|
184 | - } |
|
115 | + add_action( 'customize_register', array( self::$instance, 'customizer_settings' )); |
|
116 | + |
|
117 | + do_action( 'ayecode_ui_settings_loaded' ); |
|
118 | + } |
|
119 | + |
|
120 | + return self::$instance; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Setup some constants. |
|
125 | + */ |
|
126 | + public function constants(){ |
|
127 | + define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be"); |
|
128 | + define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d'); |
|
129 | + if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL); |
|
130 | + if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Initiate the settings and add the required action hooks. |
|
135 | + */ |
|
136 | + public function init() { |
|
137 | + $this->constants(); |
|
138 | + $this->settings = $this->get_settings(); |
|
139 | + $this->url = $this->get_url(); |
|
140 | + |
|
141 | + /** |
|
142 | + * Maybe load CSS |
|
143 | + * |
|
144 | + * We load super early in case there is a theme version that might change the colors |
|
145 | + */ |
|
146 | + if ( $this->settings['css'] ) { |
|
147 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
148 | + } |
|
149 | + if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) { |
|
150 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 ); |
|
151 | + } |
|
152 | + |
|
153 | + // maybe load JS |
|
154 | + if ( $this->settings['js'] ) { |
|
155 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
156 | + } |
|
157 | + if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) { |
|
158 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 ); |
|
159 | + } |
|
160 | + |
|
161 | + // Maybe set the HTML font size |
|
162 | + if ( $this->settings['html_font_size'] ) { |
|
163 | + add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 ); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * Check if we should load the admin scripts or not. |
|
171 | + * |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | + public function load_admin_scripts(){ |
|
175 | + $result = true; |
|
176 | + |
|
177 | + if(!empty($this->settings['disable_admin'])){ |
|
178 | + $url_parts = explode("\n",$this->settings['disable_admin']); |
|
179 | + foreach($url_parts as $part){ |
|
180 | + if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){ |
|
181 | + return false; // return early, no point checking further |
|
182 | + } |
|
183 | + } |
|
184 | + } |
|
185 | 185 | |
186 | - return $result; |
|
187 | - } |
|
186 | + return $result; |
|
187 | + } |
|
188 | 188 | |
189 | - /** |
|
190 | - * Add a html font size to the footer. |
|
191 | - */ |
|
192 | - public function html_font_size(){ |
|
193 | - $this->settings = $this->get_settings(); |
|
194 | - echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
195 | - } |
|
189 | + /** |
|
190 | + * Add a html font size to the footer. |
|
191 | + */ |
|
192 | + public function html_font_size(){ |
|
193 | + $this->settings = $this->get_settings(); |
|
194 | + echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>"; |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * Adds the Font Awesome styles. |
|
199 | - */ |
|
200 | - public function enqueue_style() { |
|
197 | + /** |
|
198 | + * Adds the Font Awesome styles. |
|
199 | + */ |
|
200 | + public function enqueue_style() { |
|
201 | 201 | |
202 | - $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
202 | + $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend'; |
|
203 | 203 | |
204 | - if($this->settings[$css_setting]){ |
|
205 | - $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
206 | - $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
207 | - wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
208 | - wp_enqueue_style( 'ayecode-ui' ); |
|
204 | + if($this->settings[$css_setting]){ |
|
205 | + $compatibility = $this->settings[$css_setting]=='core' ? false : true; |
|
206 | + $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui.css' : $this->url.'assets/css/ayecode-ui-compatibility.css'; |
|
207 | + wp_register_style( 'ayecode-ui', $url, array(), $this->latest ); |
|
208 | + wp_enqueue_style( 'ayecode-ui' ); |
|
209 | 209 | |
210 | - // flatpickr |
|
211 | - wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
210 | + // flatpickr |
|
211 | + wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest ); |
|
212 | 212 | |
213 | 213 | |
214 | - // fix some wp-admin issues |
|
215 | - if(is_admin()){ |
|
216 | - $custom_css = " |
|
214 | + // fix some wp-admin issues |
|
215 | + if(is_admin()){ |
|
216 | + $custom_css = " |
|
217 | 217 | body{ |
218 | 218 | background-color: #f1f1f1; |
219 | 219 | font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif; |
@@ -249,29 +249,29 @@ discard block |
||
249 | 249 | } |
250 | 250 | "; |
251 | 251 | |
252 | - // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
253 | - $custom_css .= " |
|
252 | + // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377 |
|
253 | + $custom_css .= " |
|
254 | 254 | .edit-post-sidebar input[type=color].components-text-control__input{ |
255 | 255 | padding: 0; |
256 | 256 | } |
257 | 257 | "; |
258 | - wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
259 | - } |
|
258 | + wp_add_inline_style( 'ayecode-ui', $custom_css ); |
|
259 | + } |
|
260 | 260 | |
261 | - // custom changes |
|
262 | - wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
261 | + // custom changes |
|
262 | + wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) ); |
|
263 | 263 | |
264 | - } |
|
265 | - } |
|
264 | + } |
|
265 | + } |
|
266 | 266 | |
267 | - /** |
|
268 | - * Get inline script used if bootstrap enqueued |
|
269 | - * |
|
270 | - * If this remains small then its best to use this than to add another JS file. |
|
271 | - */ |
|
272 | - public function inline_script(){ |
|
273 | - ob_start(); |
|
274 | - ?> |
|
267 | + /** |
|
268 | + * Get inline script used if bootstrap enqueued |
|
269 | + * |
|
270 | + * If this remains small then its best to use this than to add another JS file. |
|
271 | + */ |
|
272 | + public function inline_script(){ |
|
273 | + ob_start(); |
|
274 | + ?> |
|
275 | 275 | <script> |
276 | 276 | |
277 | 277 | /** |
@@ -758,25 +758,25 @@ discard block |
||
758 | 758 | |
759 | 759 | </script> |
760 | 760 | <?php |
761 | - $output = ob_get_clean(); |
|
761 | + $output = ob_get_clean(); |
|
762 | 762 | |
763 | - /* |
|
763 | + /* |
|
764 | 764 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
765 | 765 | */ |
766 | - return str_replace( array( |
|
767 | - '<script>', |
|
768 | - '</script>' |
|
769 | - ), '', $output ); |
|
770 | - } |
|
771 | - |
|
772 | - /** |
|
773 | - * Get inline script used if bootstrap file browser enqueued. |
|
774 | - * |
|
775 | - * If this remains small then its best to use this than to add another JS file. |
|
776 | - */ |
|
777 | - public function inline_script_file_browser(){ |
|
778 | - ob_start(); |
|
779 | - ?> |
|
766 | + return str_replace( array( |
|
767 | + '<script>', |
|
768 | + '</script>' |
|
769 | + ), '', $output ); |
|
770 | + } |
|
771 | + |
|
772 | + /** |
|
773 | + * Get inline script used if bootstrap file browser enqueued. |
|
774 | + * |
|
775 | + * If this remains small then its best to use this than to add another JS file. |
|
776 | + */ |
|
777 | + public function inline_script_file_browser(){ |
|
778 | + ob_start(); |
|
779 | + ?> |
|
780 | 780 | <script> |
781 | 781 | // run on doc ready |
782 | 782 | jQuery(document).ready(function () { |
@@ -784,184 +784,184 @@ discard block |
||
784 | 784 | }); |
785 | 785 | </script> |
786 | 786 | <?php |
787 | - $output = ob_get_clean(); |
|
787 | + $output = ob_get_clean(); |
|
788 | 788 | |
789 | - /* |
|
789 | + /* |
|
790 | 790 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
791 | 791 | */ |
792 | - return str_replace( array( |
|
793 | - '<script>', |
|
794 | - '</script>' |
|
795 | - ), '', $output ); |
|
796 | - } |
|
797 | - |
|
798 | - /** |
|
799 | - * Adds the Font Awesome JS. |
|
800 | - */ |
|
801 | - public function enqueue_scripts() { |
|
802 | - |
|
803 | - $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
804 | - |
|
805 | - // select2 |
|
806 | - wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
807 | - |
|
808 | - // flatpickr |
|
809 | - wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
810 | - |
|
811 | - // Bootstrap file browser |
|
812 | - wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
813 | - wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
814 | - |
|
815 | - $load_inline = false; |
|
816 | - |
|
817 | - if($this->settings[$js_setting]=='core-popper'){ |
|
818 | - // Bootstrap bundle |
|
819 | - $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
820 | - wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
821 | - // if in admin then add to footer for compatibility. |
|
822 | - is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
823 | - $script = $this->inline_script(); |
|
824 | - wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
825 | - }elseif($this->settings[$js_setting]=='popper'){ |
|
826 | - $url = $this->url.'assets/js/popper.min.js'; |
|
827 | - wp_register_script( 'bootstrap-js-popper', $url, array('select2','jquery'), $this->latest ); |
|
828 | - wp_enqueue_script( 'bootstrap-js-popper' ); |
|
829 | - $load_inline = true; |
|
830 | - }else{ |
|
831 | - $load_inline = true; |
|
832 | - } |
|
833 | - |
|
834 | - // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
835 | - if($load_inline){ |
|
836 | - wp_register_script( 'bootstrap-dummy', '',array('select2','jquery') ); |
|
837 | - wp_enqueue_script( 'bootstrap-dummy' ); |
|
838 | - $script = $this->inline_script(); |
|
839 | - wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
840 | - } |
|
841 | - |
|
842 | - } |
|
843 | - |
|
844 | - /** |
|
845 | - * Enqueue flatpickr if called. |
|
846 | - */ |
|
847 | - public function enqueue_flatpickr(){ |
|
848 | - wp_enqueue_style( 'flatpickr' ); |
|
849 | - wp_enqueue_script( 'flatpickr' ); |
|
850 | - } |
|
851 | - |
|
852 | - /** |
|
853 | - * Get the url path to the current folder. |
|
854 | - * |
|
855 | - * @return string |
|
856 | - */ |
|
857 | - public function get_url() { |
|
858 | - |
|
859 | - $url = ''; |
|
860 | - // check if we are inside a plugin |
|
861 | - $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
862 | - |
|
863 | - // add check in-case user has changed wp-content dir name. |
|
864 | - $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
865 | - $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
866 | - $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
867 | - |
|
868 | - if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
869 | - $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
870 | - } |
|
871 | - |
|
872 | - return $url; |
|
873 | - } |
|
874 | - |
|
875 | - /** |
|
876 | - * Register the database settings with WordPress. |
|
877 | - */ |
|
878 | - public function register_settings() { |
|
879 | - register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
880 | - } |
|
881 | - |
|
882 | - /** |
|
883 | - * Add the WordPress settings menu item. |
|
884 | - * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
885 | - */ |
|
886 | - public function menu_item() { |
|
887 | - $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
888 | - call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
889 | - $this, |
|
890 | - 'settings_page' |
|
891 | - ) ); |
|
892 | - } |
|
893 | - |
|
894 | - /** |
|
895 | - * Get a list of themes and their default JS settings. |
|
896 | - * |
|
897 | - * @return array |
|
898 | - */ |
|
899 | - public function theme_js_settings(){ |
|
900 | - return array( |
|
901 | - 'ayetheme' => 'popper', |
|
902 | - 'listimia' => 'required', |
|
903 | - 'listimia_backend' => 'core-popper', |
|
904 | - 'avada' => 'required', |
|
905 | - ); |
|
906 | - } |
|
907 | - |
|
908 | - /** |
|
909 | - * Get the current Font Awesome output settings. |
|
910 | - * |
|
911 | - * @return array The array of settings. |
|
912 | - */ |
|
913 | - public function get_settings() { |
|
914 | - |
|
915 | - $db_settings = get_option( 'ayecode-ui-settings' ); |
|
916 | - $js_default = 'core-popper'; |
|
917 | - $js_default_backend = $js_default; |
|
918 | - |
|
919 | - // maybe set defaults (if no settings set) |
|
920 | - if(empty($db_settings)){ |
|
921 | - $active_theme = strtolower( get_template() ); // active parent theme. |
|
922 | - $theme_js_settings = self::theme_js_settings(); |
|
923 | - if(isset($theme_js_settings[$active_theme])){ |
|
924 | - $js_default = $theme_js_settings[$active_theme]; |
|
925 | - $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
926 | - } |
|
927 | - } |
|
928 | - |
|
929 | - $defaults = array( |
|
930 | - 'css' => 'compatibility', // core, compatibility |
|
931 | - 'js' => $js_default, // js to load, core-popper, popper |
|
932 | - 'html_font_size' => '16', // js to load, core-popper, popper |
|
933 | - 'css_backend' => 'compatibility', // core, compatibility |
|
934 | - 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
935 | - 'disable_admin' => '', // URL snippets to disable loading on admin |
|
936 | - ); |
|
937 | - |
|
938 | - $settings = wp_parse_args( $db_settings, $defaults ); |
|
939 | - |
|
940 | - /** |
|
941 | - * Filter the Bootstrap settings. |
|
942 | - * |
|
943 | - * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
944 | - */ |
|
945 | - return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
946 | - } |
|
947 | - |
|
948 | - |
|
949 | - /** |
|
950 | - * The settings page html output. |
|
951 | - */ |
|
952 | - public function settings_page() { |
|
953 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
954 | - wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
955 | - } |
|
956 | - ?> |
|
792 | + return str_replace( array( |
|
793 | + '<script>', |
|
794 | + '</script>' |
|
795 | + ), '', $output ); |
|
796 | + } |
|
797 | + |
|
798 | + /** |
|
799 | + * Adds the Font Awesome JS. |
|
800 | + */ |
|
801 | + public function enqueue_scripts() { |
|
802 | + |
|
803 | + $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend'; |
|
804 | + |
|
805 | + // select2 |
|
806 | + wp_register_script( 'select2', $this->url.'assets/js/select2.min.js', array('jquery'), $this->select2_version ); |
|
807 | + |
|
808 | + // flatpickr |
|
809 | + wp_register_script( 'flatpickr', $this->url.'assets/js/flatpickr.min.js', array(), $this->latest ); |
|
810 | + |
|
811 | + // Bootstrap file browser |
|
812 | + wp_register_script( 'aui-custom-file-input', $url = $this->url.'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version ); |
|
813 | + wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() ); |
|
814 | + |
|
815 | + $load_inline = false; |
|
816 | + |
|
817 | + if($this->settings[$js_setting]=='core-popper'){ |
|
818 | + // Bootstrap bundle |
|
819 | + $url = $this->url.'assets/js/bootstrap.bundle.min.js'; |
|
820 | + wp_register_script( 'bootstrap-js-bundle', $url, array('select2','jquery'), $this->latest ); |
|
821 | + // if in admin then add to footer for compatibility. |
|
822 | + is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle'); |
|
823 | + $script = $this->inline_script(); |
|
824 | + wp_add_inline_script( 'bootstrap-js-bundle', $script ); |
|
825 | + }elseif($this->settings[$js_setting]=='popper'){ |
|
826 | + $url = $this->url.'assets/js/popper.min.js'; |
|
827 | + wp_register_script( 'bootstrap-js-popper', $url, array('select2','jquery'), $this->latest ); |
|
828 | + wp_enqueue_script( 'bootstrap-js-popper' ); |
|
829 | + $load_inline = true; |
|
830 | + }else{ |
|
831 | + $load_inline = true; |
|
832 | + } |
|
833 | + |
|
834 | + // Load needed inline scripts by faking the loading of a script if the main script is not being loaded |
|
835 | + if($load_inline){ |
|
836 | + wp_register_script( 'bootstrap-dummy', '',array('select2','jquery') ); |
|
837 | + wp_enqueue_script( 'bootstrap-dummy' ); |
|
838 | + $script = $this->inline_script(); |
|
839 | + wp_add_inline_script( 'bootstrap-dummy', $script ); |
|
840 | + } |
|
841 | + |
|
842 | + } |
|
843 | + |
|
844 | + /** |
|
845 | + * Enqueue flatpickr if called. |
|
846 | + */ |
|
847 | + public function enqueue_flatpickr(){ |
|
848 | + wp_enqueue_style( 'flatpickr' ); |
|
849 | + wp_enqueue_script( 'flatpickr' ); |
|
850 | + } |
|
851 | + |
|
852 | + /** |
|
853 | + * Get the url path to the current folder. |
|
854 | + * |
|
855 | + * @return string |
|
856 | + */ |
|
857 | + public function get_url() { |
|
858 | + |
|
859 | + $url = ''; |
|
860 | + // check if we are inside a plugin |
|
861 | + $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) ); |
|
862 | + |
|
863 | + // add check in-case user has changed wp-content dir name. |
|
864 | + $wp_content_folder_name = basename(WP_CONTENT_DIR); |
|
865 | + $dir_parts = explode("/$wp_content_folder_name/",$file_dir); |
|
866 | + $url_parts = explode("/$wp_content_folder_name/",plugins_url()); |
|
867 | + |
|
868 | + if(!empty($url_parts[0]) && !empty($dir_parts[1])){ |
|
869 | + $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] ); |
|
870 | + } |
|
871 | + |
|
872 | + return $url; |
|
873 | + } |
|
874 | + |
|
875 | + /** |
|
876 | + * Register the database settings with WordPress. |
|
877 | + */ |
|
878 | + public function register_settings() { |
|
879 | + register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' ); |
|
880 | + } |
|
881 | + |
|
882 | + /** |
|
883 | + * Add the WordPress settings menu item. |
|
884 | + * @since 1.0.10 Calling function name direct will fail theme check so we don't. |
|
885 | + */ |
|
886 | + public function menu_item() { |
|
887 | + $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme |
|
888 | + call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array( |
|
889 | + $this, |
|
890 | + 'settings_page' |
|
891 | + ) ); |
|
892 | + } |
|
893 | + |
|
894 | + /** |
|
895 | + * Get a list of themes and their default JS settings. |
|
896 | + * |
|
897 | + * @return array |
|
898 | + */ |
|
899 | + public function theme_js_settings(){ |
|
900 | + return array( |
|
901 | + 'ayetheme' => 'popper', |
|
902 | + 'listimia' => 'required', |
|
903 | + 'listimia_backend' => 'core-popper', |
|
904 | + 'avada' => 'required', |
|
905 | + ); |
|
906 | + } |
|
907 | + |
|
908 | + /** |
|
909 | + * Get the current Font Awesome output settings. |
|
910 | + * |
|
911 | + * @return array The array of settings. |
|
912 | + */ |
|
913 | + public function get_settings() { |
|
914 | + |
|
915 | + $db_settings = get_option( 'ayecode-ui-settings' ); |
|
916 | + $js_default = 'core-popper'; |
|
917 | + $js_default_backend = $js_default; |
|
918 | + |
|
919 | + // maybe set defaults (if no settings set) |
|
920 | + if(empty($db_settings)){ |
|
921 | + $active_theme = strtolower( get_template() ); // active parent theme. |
|
922 | + $theme_js_settings = self::theme_js_settings(); |
|
923 | + if(isset($theme_js_settings[$active_theme])){ |
|
924 | + $js_default = $theme_js_settings[$active_theme]; |
|
925 | + $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default; |
|
926 | + } |
|
927 | + } |
|
928 | + |
|
929 | + $defaults = array( |
|
930 | + 'css' => 'compatibility', // core, compatibility |
|
931 | + 'js' => $js_default, // js to load, core-popper, popper |
|
932 | + 'html_font_size' => '16', // js to load, core-popper, popper |
|
933 | + 'css_backend' => 'compatibility', // core, compatibility |
|
934 | + 'js_backend' => $js_default_backend, // js to load, core-popper, popper |
|
935 | + 'disable_admin' => '', // URL snippets to disable loading on admin |
|
936 | + ); |
|
937 | + |
|
938 | + $settings = wp_parse_args( $db_settings, $defaults ); |
|
939 | + |
|
940 | + /** |
|
941 | + * Filter the Bootstrap settings. |
|
942 | + * |
|
943 | + * @todo if we add this filer people might use it and then it defeates the purpose of this class :/ |
|
944 | + */ |
|
945 | + return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults ); |
|
946 | + } |
|
947 | + |
|
948 | + |
|
949 | + /** |
|
950 | + * The settings page html output. |
|
951 | + */ |
|
952 | + public function settings_page() { |
|
953 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
954 | + wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) ); |
|
955 | + } |
|
956 | + ?> |
|
957 | 957 | <div class="wrap"> |
958 | 958 | <h1><?php echo $this->name; ?></h1> |
959 | 959 | <p><?php _e("Here you can adjust settings if you are having compatibility issues.","aui");?></p> |
960 | 960 | <form method="post" action="options.php"> |
961 | 961 | <?php |
962 | - settings_fields( 'ayecode-ui-settings' ); |
|
963 | - do_settings_sections( 'ayecode-ui-settings' ); |
|
964 | - ?> |
|
962 | + settings_fields( 'ayecode-ui-settings' ); |
|
963 | + do_settings_sections( 'ayecode-ui-settings' ); |
|
964 | + ?> |
|
965 | 965 | |
966 | 966 | <h2><?php _e( 'Frontend', 'aui' ); ?></h2> |
967 | 967 | <table class="form-table wpbs-table-settings"> |
@@ -1041,489 +1041,489 @@ discard block |
||
1041 | 1041 | </table> |
1042 | 1042 | |
1043 | 1043 | <?php |
1044 | - submit_button(); |
|
1045 | - ?> |
|
1044 | + submit_button(); |
|
1045 | + ?> |
|
1046 | 1046 | </form> |
1047 | 1047 | |
1048 | 1048 | <div id="wpbs-version"><?php echo $this->version; ?></div> |
1049 | 1049 | </div> |
1050 | 1050 | |
1051 | 1051 | <?php |
1052 | - } |
|
1053 | - |
|
1054 | - public function customizer_settings($wp_customize){ |
|
1055 | - $wp_customize->add_section('aui_settings', array( |
|
1056 | - 'title' => __('AyeCode UI','aui'), |
|
1057 | - 'priority' => 120, |
|
1058 | - )); |
|
1059 | - |
|
1060 | - // ============================= |
|
1061 | - // = Color Picker = |
|
1062 | - // ============================= |
|
1063 | - $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1064 | - 'default' => AUI_PRIMARY_COLOR, |
|
1065 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1066 | - 'capability' => 'edit_theme_options', |
|
1067 | - 'type' => 'option', |
|
1068 | - 'transport' => 'refresh', |
|
1069 | - )); |
|
1070 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1071 | - 'label' => __('Primary Color','aui'), |
|
1072 | - 'section' => 'aui_settings', |
|
1073 | - 'settings' => 'aui_options[color_primary]', |
|
1074 | - ))); |
|
1075 | - |
|
1076 | - $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1077 | - 'default' => '#6c757d', |
|
1078 | - 'sanitize_callback' => 'sanitize_hex_color', |
|
1079 | - 'capability' => 'edit_theme_options', |
|
1080 | - 'type' => 'option', |
|
1081 | - 'transport' => 'refresh', |
|
1082 | - )); |
|
1083 | - $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1084 | - 'label' => __('Secondary Color','aui'), |
|
1085 | - 'section' => 'aui_settings', |
|
1086 | - 'settings' => 'aui_options[color_secondary]', |
|
1087 | - ))); |
|
1088 | - } |
|
1089 | - |
|
1090 | - |
|
1091 | - public static function custom_css($compatibility = true) { |
|
1092 | - $settings = get_option('aui_options'); |
|
1093 | - |
|
1094 | - ob_start(); |
|
1095 | - |
|
1096 | - $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1097 | - $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1098 | - //AUI_PRIMARY_COLOR_ORIGINAL |
|
1099 | - ?> |
|
1052 | + } |
|
1053 | + |
|
1054 | + public function customizer_settings($wp_customize){ |
|
1055 | + $wp_customize->add_section('aui_settings', array( |
|
1056 | + 'title' => __('AyeCode UI','aui'), |
|
1057 | + 'priority' => 120, |
|
1058 | + )); |
|
1059 | + |
|
1060 | + // ============================= |
|
1061 | + // = Color Picker = |
|
1062 | + // ============================= |
|
1063 | + $wp_customize->add_setting('aui_options[color_primary]', array( |
|
1064 | + 'default' => AUI_PRIMARY_COLOR, |
|
1065 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1066 | + 'capability' => 'edit_theme_options', |
|
1067 | + 'type' => 'option', |
|
1068 | + 'transport' => 'refresh', |
|
1069 | + )); |
|
1070 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array( |
|
1071 | + 'label' => __('Primary Color','aui'), |
|
1072 | + 'section' => 'aui_settings', |
|
1073 | + 'settings' => 'aui_options[color_primary]', |
|
1074 | + ))); |
|
1075 | + |
|
1076 | + $wp_customize->add_setting('aui_options[color_secondary]', array( |
|
1077 | + 'default' => '#6c757d', |
|
1078 | + 'sanitize_callback' => 'sanitize_hex_color', |
|
1079 | + 'capability' => 'edit_theme_options', |
|
1080 | + 'type' => 'option', |
|
1081 | + 'transport' => 'refresh', |
|
1082 | + )); |
|
1083 | + $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array( |
|
1084 | + 'label' => __('Secondary Color','aui'), |
|
1085 | + 'section' => 'aui_settings', |
|
1086 | + 'settings' => 'aui_options[color_secondary]', |
|
1087 | + ))); |
|
1088 | + } |
|
1089 | + |
|
1090 | + |
|
1091 | + public static function custom_css($compatibility = true) { |
|
1092 | + $settings = get_option('aui_options'); |
|
1093 | + |
|
1094 | + ob_start(); |
|
1095 | + |
|
1096 | + $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR; |
|
1097 | + $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR; |
|
1098 | + //AUI_PRIMARY_COLOR_ORIGINAL |
|
1099 | + ?> |
|
1100 | 1100 | <style> |
1101 | 1101 | <?php |
1102 | - if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1103 | - echo self::css_primary($primary_color,$compatibility); |
|
1104 | - } |
|
1102 | + if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){ |
|
1103 | + echo self::css_primary($primary_color,$compatibility); |
|
1104 | + } |
|
1105 | 1105 | |
1106 | - if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1107 | - echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1108 | - } |
|
1106 | + if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){ |
|
1107 | + echo self::css_secondary($settings['color_secondary'],$compatibility); |
|
1108 | + } |
|
1109 | 1109 | ?> |
1110 | 1110 | </style> |
1111 | 1111 | <?php |
1112 | 1112 | |
1113 | 1113 | |
1114 | - /* |
|
1114 | + /* |
|
1115 | 1115 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1116 | 1116 | */ |
1117 | - return str_replace( array( |
|
1118 | - '<style>', |
|
1119 | - '</style>' |
|
1120 | - ), '', ob_get_clean()); |
|
1121 | - } |
|
1122 | - |
|
1123 | - public static function css_primary($color_code,$compatibility){; |
|
1124 | - $color_code = sanitize_hex_color($color_code); |
|
1125 | - if(!$color_code){return '';} |
|
1126 | - /** |
|
1127 | - * c = color, b = background color, o = border-color, f = fill |
|
1128 | - */ |
|
1129 | - $selectors = array( |
|
1130 | - 'a' => array('c'), |
|
1131 | - '.btn-primary' => array('b','o'), |
|
1132 | - '.btn-primary.disabled' => array('b','o'), |
|
1133 | - '.btn-primary:disabled' => array('b','o'), |
|
1134 | - '.btn-outline-primary' => array('c','o'), |
|
1135 | - '.btn-outline-primary:hover' => array('b','o'), |
|
1136 | - '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1137 | - '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1138 | - '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1139 | - '.btn-link' => array('c'), |
|
1140 | - '.dropdown-item.active' => array('b'), |
|
1141 | - '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1142 | - '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1117 | + return str_replace( array( |
|
1118 | + '<style>', |
|
1119 | + '</style>' |
|
1120 | + ), '', ob_get_clean()); |
|
1121 | + } |
|
1122 | + |
|
1123 | + public static function css_primary($color_code,$compatibility){; |
|
1124 | + $color_code = sanitize_hex_color($color_code); |
|
1125 | + if(!$color_code){return '';} |
|
1126 | + /** |
|
1127 | + * c = color, b = background color, o = border-color, f = fill |
|
1128 | + */ |
|
1129 | + $selectors = array( |
|
1130 | + 'a' => array('c'), |
|
1131 | + '.btn-primary' => array('b','o'), |
|
1132 | + '.btn-primary.disabled' => array('b','o'), |
|
1133 | + '.btn-primary:disabled' => array('b','o'), |
|
1134 | + '.btn-outline-primary' => array('c','o'), |
|
1135 | + '.btn-outline-primary:hover' => array('b','o'), |
|
1136 | + '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1137 | + '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1138 | + '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'), |
|
1139 | + '.btn-link' => array('c'), |
|
1140 | + '.dropdown-item.active' => array('b'), |
|
1141 | + '.custom-control-input:checked~.custom-control-label::before' => array('b','o'), |
|
1142 | + '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'), |
|
1143 | 1143 | // '.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules... |
1144 | 1144 | // '.custom-range::-moz-range-thumb' => array('b'), |
1145 | 1145 | // '.custom-range::-ms-thumb' => array('b'), |
1146 | - '.nav-pills .nav-link.active' => array('b'), |
|
1147 | - '.nav-pills .show>.nav-link' => array('b'), |
|
1148 | - '.page-link' => array('c'), |
|
1149 | - '.page-item.active .page-link' => array('b','o'), |
|
1150 | - '.badge-primary' => array('b'), |
|
1151 | - '.alert-primary' => array('b','o'), |
|
1152 | - '.progress-bar' => array('b'), |
|
1153 | - '.list-group-item.active' => array('b','o'), |
|
1154 | - '.bg-primary' => array('b','f'), |
|
1155 | - '.btn-link.btn-primary' => array('c'), |
|
1156 | - '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1157 | - ); |
|
1158 | - |
|
1159 | - $important_selectors = array( |
|
1160 | - '.bg-primary' => array('b','f'), |
|
1161 | - '.border-primary' => array('o'), |
|
1162 | - '.text-primary' => array('c'), |
|
1163 | - ); |
|
1164 | - |
|
1165 | - $color = array(); |
|
1166 | - $color_i = array(); |
|
1167 | - $background = array(); |
|
1168 | - $background_i = array(); |
|
1169 | - $border = array(); |
|
1170 | - $border_i = array(); |
|
1171 | - $fill = array(); |
|
1172 | - $fill_i = array(); |
|
1173 | - |
|
1174 | - $output = ''; |
|
1175 | - |
|
1176 | - // build rules into each type |
|
1177 | - foreach($selectors as $selector => $types){ |
|
1178 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1179 | - $types = array_combine($types,$types); |
|
1180 | - if(isset($types['c'])){$color[] = $selector;} |
|
1181 | - if(isset($types['b'])){$background[] = $selector;} |
|
1182 | - if(isset($types['o'])){$border[] = $selector;} |
|
1183 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1184 | - } |
|
1185 | - |
|
1186 | - // build rules into each type |
|
1187 | - foreach($important_selectors as $selector => $types){ |
|
1188 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1189 | - $types = array_combine($types,$types); |
|
1190 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1191 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1192 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1193 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1194 | - } |
|
1195 | - |
|
1196 | - // add any color rules |
|
1197 | - if(!empty($color)){ |
|
1198 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1199 | - } |
|
1200 | - if(!empty($color_i)){ |
|
1201 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1202 | - } |
|
1203 | - |
|
1204 | - // add any background color rules |
|
1205 | - if(!empty($background)){ |
|
1206 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1207 | - } |
|
1208 | - if(!empty($background_i)){ |
|
1209 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1210 | - } |
|
1211 | - |
|
1212 | - // add any border color rules |
|
1213 | - if(!empty($border)){ |
|
1214 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1215 | - } |
|
1216 | - if(!empty($border_i)){ |
|
1217 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1218 | - } |
|
1219 | - |
|
1220 | - // add any fill color rules |
|
1221 | - if(!empty($fill)){ |
|
1222 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1223 | - } |
|
1224 | - if(!empty($fill_i)){ |
|
1225 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1226 | - } |
|
1227 | - |
|
1228 | - |
|
1229 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1230 | - |
|
1231 | - // darken |
|
1232 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1233 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1234 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1235 | - |
|
1236 | - // lighten |
|
1237 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1238 | - |
|
1239 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1240 | - $op_25 = $color_code."40"; // 25% opacity |
|
1241 | - |
|
1242 | - |
|
1243 | - // button states |
|
1244 | - $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1245 | - $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1246 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1247 | - $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1248 | - |
|
1249 | - |
|
1250 | - // dropdown's |
|
1251 | - $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1252 | - |
|
1253 | - |
|
1254 | - // input states |
|
1255 | - $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1256 | - |
|
1257 | - // page link |
|
1258 | - $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1259 | - |
|
1260 | - return $output; |
|
1261 | - } |
|
1262 | - |
|
1263 | - public static function css_secondary($color_code,$compatibility){; |
|
1264 | - $color_code = sanitize_hex_color($color_code); |
|
1265 | - if(!$color_code){return '';} |
|
1266 | - /** |
|
1267 | - * c = color, b = background color, o = border-color, f = fill |
|
1268 | - */ |
|
1269 | - $selectors = array( |
|
1270 | - '.btn-secondary' => array('b','o'), |
|
1271 | - '.btn-secondary.disabled' => array('b','o'), |
|
1272 | - '.btn-secondary:disabled' => array('b','o'), |
|
1273 | - '.btn-outline-secondary' => array('c','o'), |
|
1274 | - '.btn-outline-secondary:hover' => array('b','o'), |
|
1275 | - '.btn-outline-secondary.disabled' => array('c'), |
|
1276 | - '.btn-outline-secondary:disabled' => array('c'), |
|
1277 | - '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1278 | - '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1279 | - '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1280 | - '.badge-secondary' => array('b'), |
|
1281 | - '.alert-secondary' => array('b','o'), |
|
1282 | - '.btn-link.btn-secondary' => array('c'), |
|
1283 | - ); |
|
1284 | - |
|
1285 | - $important_selectors = array( |
|
1286 | - '.bg-secondary' => array('b','f'), |
|
1287 | - '.border-secondary' => array('o'), |
|
1288 | - '.text-secondary' => array('c'), |
|
1289 | - ); |
|
1290 | - |
|
1291 | - $color = array(); |
|
1292 | - $color_i = array(); |
|
1293 | - $background = array(); |
|
1294 | - $background_i = array(); |
|
1295 | - $border = array(); |
|
1296 | - $border_i = array(); |
|
1297 | - $fill = array(); |
|
1298 | - $fill_i = array(); |
|
1299 | - |
|
1300 | - $output = ''; |
|
1301 | - |
|
1302 | - // build rules into each type |
|
1303 | - foreach($selectors as $selector => $types){ |
|
1304 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1305 | - $types = array_combine($types,$types); |
|
1306 | - if(isset($types['c'])){$color[] = $selector;} |
|
1307 | - if(isset($types['b'])){$background[] = $selector;} |
|
1308 | - if(isset($types['o'])){$border[] = $selector;} |
|
1309 | - if(isset($types['f'])){$fill[] = $selector;} |
|
1310 | - } |
|
1311 | - |
|
1312 | - // build rules into each type |
|
1313 | - foreach($important_selectors as $selector => $types){ |
|
1314 | - $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1315 | - $types = array_combine($types,$types); |
|
1316 | - if(isset($types['c'])){$color_i[] = $selector;} |
|
1317 | - if(isset($types['b'])){$background_i[] = $selector;} |
|
1318 | - if(isset($types['o'])){$border_i[] = $selector;} |
|
1319 | - if(isset($types['f'])){$fill_i[] = $selector;} |
|
1320 | - } |
|
1321 | - |
|
1322 | - // add any color rules |
|
1323 | - if(!empty($color)){ |
|
1324 | - $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1325 | - } |
|
1326 | - if(!empty($color_i)){ |
|
1327 | - $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1328 | - } |
|
1329 | - |
|
1330 | - // add any background color rules |
|
1331 | - if(!empty($background)){ |
|
1332 | - $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1333 | - } |
|
1334 | - if(!empty($background_i)){ |
|
1335 | - $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1336 | - } |
|
1337 | - |
|
1338 | - // add any border color rules |
|
1339 | - if(!empty($border)){ |
|
1340 | - $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1341 | - } |
|
1342 | - if(!empty($border_i)){ |
|
1343 | - $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1344 | - } |
|
1345 | - |
|
1346 | - // add any fill color rules |
|
1347 | - if(!empty($fill)){ |
|
1348 | - $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1349 | - } |
|
1350 | - if(!empty($fill_i)){ |
|
1351 | - $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - $prefix = $compatibility ? ".bsui " : ""; |
|
1356 | - |
|
1357 | - // darken |
|
1358 | - $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1359 | - $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1360 | - $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1361 | - |
|
1362 | - // lighten |
|
1363 | - $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1364 | - |
|
1365 | - // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1366 | - $op_25 = $color_code."40"; // 25% opacity |
|
1367 | - |
|
1368 | - |
|
1369 | - // button states |
|
1370 | - $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1371 | - $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1372 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1373 | - $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1374 | - |
|
1375 | - |
|
1376 | - return $output; |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1381 | - * |
|
1382 | - * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1383 | - * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1384 | - * |
|
1385 | - * @return string |
|
1386 | - */ |
|
1387 | - public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1388 | - $hexCode = ltrim($hexCode, '#'); |
|
1389 | - |
|
1390 | - if (strlen($hexCode) == 3) { |
|
1391 | - $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1392 | - } |
|
1393 | - |
|
1394 | - $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1395 | - |
|
1396 | - foreach ($hexCode as & $color) { |
|
1397 | - $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1398 | - $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1399 | - |
|
1400 | - $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1401 | - } |
|
1402 | - |
|
1403 | - return '#' . implode($hexCode); |
|
1404 | - } |
|
1405 | - |
|
1406 | - /** |
|
1407 | - * Check if we should display examples. |
|
1408 | - */ |
|
1409 | - public function maybe_show_examples(){ |
|
1410 | - if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1411 | - echo "<head>"; |
|
1412 | - wp_head(); |
|
1413 | - echo "</head>"; |
|
1414 | - echo "<body>"; |
|
1415 | - echo $this->get_examples(); |
|
1416 | - echo "</body>"; |
|
1417 | - exit; |
|
1418 | - } |
|
1419 | - } |
|
1420 | - |
|
1421 | - /** |
|
1422 | - * Get developer examples. |
|
1423 | - * |
|
1424 | - * @return string |
|
1425 | - */ |
|
1426 | - public function get_examples(){ |
|
1427 | - $output = ''; |
|
1428 | - |
|
1429 | - |
|
1430 | - // open form |
|
1431 | - $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1432 | - |
|
1433 | - // input example |
|
1434 | - $output .= aui()->input(array( |
|
1435 | - 'type' => 'text', |
|
1436 | - 'id' => 'text-example', |
|
1437 | - 'name' => 'text-example', |
|
1438 | - 'placeholder' => 'text placeholder', |
|
1439 | - 'title' => 'Text input example', |
|
1440 | - 'value' => '', |
|
1441 | - 'required' => false, |
|
1442 | - 'help_text' => 'help text', |
|
1443 | - 'label' => 'Text input example label' |
|
1444 | - )); |
|
1445 | - |
|
1446 | - // input example |
|
1447 | - $output .= aui()->input(array( |
|
1448 | - 'type' => 'url', |
|
1449 | - 'id' => 'text-example2', |
|
1450 | - 'name' => 'text-example', |
|
1451 | - 'placeholder' => 'url placeholder', |
|
1452 | - 'title' => 'Text input example', |
|
1453 | - 'value' => '', |
|
1454 | - 'required' => false, |
|
1455 | - 'help_text' => 'help text', |
|
1456 | - 'label' => 'Text input example label' |
|
1457 | - )); |
|
1458 | - |
|
1459 | - // checkbox example |
|
1460 | - $output .= aui()->input(array( |
|
1461 | - 'type' => 'checkbox', |
|
1462 | - 'id' => 'checkbox-example', |
|
1463 | - 'name' => 'checkbox-example', |
|
1464 | - 'placeholder' => 'checkbox-example', |
|
1465 | - 'title' => 'Checkbox example', |
|
1466 | - 'value' => '1', |
|
1467 | - 'checked' => true, |
|
1468 | - 'required' => false, |
|
1469 | - 'help_text' => 'help text', |
|
1470 | - 'label' => 'Checkbox checked' |
|
1471 | - )); |
|
1472 | - |
|
1473 | - // checkbox example |
|
1474 | - $output .= aui()->input(array( |
|
1475 | - 'type' => 'checkbox', |
|
1476 | - 'id' => 'checkbox-example2', |
|
1477 | - 'name' => 'checkbox-example2', |
|
1478 | - 'placeholder' => 'checkbox-example', |
|
1479 | - 'title' => 'Checkbox example', |
|
1480 | - 'value' => '1', |
|
1481 | - 'checked' => false, |
|
1482 | - 'required' => false, |
|
1483 | - 'help_text' => 'help text', |
|
1484 | - 'label' => 'Checkbox un-checked' |
|
1485 | - )); |
|
1486 | - |
|
1487 | - // switch example |
|
1488 | - $output .= aui()->input(array( |
|
1489 | - 'type' => 'checkbox', |
|
1490 | - 'id' => 'switch-example', |
|
1491 | - 'name' => 'switch-example', |
|
1492 | - 'placeholder' => 'checkbox-example', |
|
1493 | - 'title' => 'Switch example', |
|
1494 | - 'value' => '1', |
|
1495 | - 'checked' => true, |
|
1496 | - 'switch' => true, |
|
1497 | - 'required' => false, |
|
1498 | - 'help_text' => 'help text', |
|
1499 | - 'label' => 'Switch on' |
|
1500 | - )); |
|
1501 | - |
|
1502 | - // switch example |
|
1503 | - $output .= aui()->input(array( |
|
1504 | - 'type' => 'checkbox', |
|
1505 | - 'id' => 'switch-example2', |
|
1506 | - 'name' => 'switch-example2', |
|
1507 | - 'placeholder' => 'checkbox-example', |
|
1508 | - 'title' => 'Switch example', |
|
1509 | - 'value' => '1', |
|
1510 | - 'checked' => false, |
|
1511 | - 'switch' => true, |
|
1512 | - 'required' => false, |
|
1513 | - 'help_text' => 'help text', |
|
1514 | - 'label' => 'Switch off' |
|
1515 | - )); |
|
1516 | - |
|
1517 | - // close form |
|
1518 | - $output .= "</form>"; |
|
1519 | - |
|
1520 | - return $output; |
|
1521 | - } |
|
1522 | - |
|
1523 | - } |
|
1524 | - |
|
1525 | - /** |
|
1526 | - * Run the class if found. |
|
1527 | - */ |
|
1528 | - AyeCode_UI_Settings::instance(); |
|
1146 | + '.nav-pills .nav-link.active' => array('b'), |
|
1147 | + '.nav-pills .show>.nav-link' => array('b'), |
|
1148 | + '.page-link' => array('c'), |
|
1149 | + '.page-item.active .page-link' => array('b','o'), |
|
1150 | + '.badge-primary' => array('b'), |
|
1151 | + '.alert-primary' => array('b','o'), |
|
1152 | + '.progress-bar' => array('b'), |
|
1153 | + '.list-group-item.active' => array('b','o'), |
|
1154 | + '.bg-primary' => array('b','f'), |
|
1155 | + '.btn-link.btn-primary' => array('c'), |
|
1156 | + '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'), |
|
1157 | + ); |
|
1158 | + |
|
1159 | + $important_selectors = array( |
|
1160 | + '.bg-primary' => array('b','f'), |
|
1161 | + '.border-primary' => array('o'), |
|
1162 | + '.text-primary' => array('c'), |
|
1163 | + ); |
|
1164 | + |
|
1165 | + $color = array(); |
|
1166 | + $color_i = array(); |
|
1167 | + $background = array(); |
|
1168 | + $background_i = array(); |
|
1169 | + $border = array(); |
|
1170 | + $border_i = array(); |
|
1171 | + $fill = array(); |
|
1172 | + $fill_i = array(); |
|
1173 | + |
|
1174 | + $output = ''; |
|
1175 | + |
|
1176 | + // build rules into each type |
|
1177 | + foreach($selectors as $selector => $types){ |
|
1178 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1179 | + $types = array_combine($types,$types); |
|
1180 | + if(isset($types['c'])){$color[] = $selector;} |
|
1181 | + if(isset($types['b'])){$background[] = $selector;} |
|
1182 | + if(isset($types['o'])){$border[] = $selector;} |
|
1183 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1184 | + } |
|
1185 | + |
|
1186 | + // build rules into each type |
|
1187 | + foreach($important_selectors as $selector => $types){ |
|
1188 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1189 | + $types = array_combine($types,$types); |
|
1190 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1191 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1192 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1193 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1194 | + } |
|
1195 | + |
|
1196 | + // add any color rules |
|
1197 | + if(!empty($color)){ |
|
1198 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1199 | + } |
|
1200 | + if(!empty($color_i)){ |
|
1201 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1202 | + } |
|
1203 | + |
|
1204 | + // add any background color rules |
|
1205 | + if(!empty($background)){ |
|
1206 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1207 | + } |
|
1208 | + if(!empty($background_i)){ |
|
1209 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1210 | + } |
|
1211 | + |
|
1212 | + // add any border color rules |
|
1213 | + if(!empty($border)){ |
|
1214 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1215 | + } |
|
1216 | + if(!empty($border_i)){ |
|
1217 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1218 | + } |
|
1219 | + |
|
1220 | + // add any fill color rules |
|
1221 | + if(!empty($fill)){ |
|
1222 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1223 | + } |
|
1224 | + if(!empty($fill_i)){ |
|
1225 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1226 | + } |
|
1227 | + |
|
1228 | + |
|
1229 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1230 | + |
|
1231 | + // darken |
|
1232 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1233 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1234 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1235 | + |
|
1236 | + // lighten |
|
1237 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1238 | + |
|
1239 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1240 | + $op_25 = $color_code."40"; // 25% opacity |
|
1241 | + |
|
1242 | + |
|
1243 | + // button states |
|
1244 | + $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1245 | + $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1246 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1247 | + $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1248 | + |
|
1249 | + |
|
1250 | + // dropdown's |
|
1251 | + $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} "; |
|
1252 | + |
|
1253 | + |
|
1254 | + // input states |
|
1255 | + $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1256 | + |
|
1257 | + // page link |
|
1258 | + $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1259 | + |
|
1260 | + return $output; |
|
1261 | + } |
|
1262 | + |
|
1263 | + public static function css_secondary($color_code,$compatibility){; |
|
1264 | + $color_code = sanitize_hex_color($color_code); |
|
1265 | + if(!$color_code){return '';} |
|
1266 | + /** |
|
1267 | + * c = color, b = background color, o = border-color, f = fill |
|
1268 | + */ |
|
1269 | + $selectors = array( |
|
1270 | + '.btn-secondary' => array('b','o'), |
|
1271 | + '.btn-secondary.disabled' => array('b','o'), |
|
1272 | + '.btn-secondary:disabled' => array('b','o'), |
|
1273 | + '.btn-outline-secondary' => array('c','o'), |
|
1274 | + '.btn-outline-secondary:hover' => array('b','o'), |
|
1275 | + '.btn-outline-secondary.disabled' => array('c'), |
|
1276 | + '.btn-outline-secondary:disabled' => array('c'), |
|
1277 | + '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'), |
|
1278 | + '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'), |
|
1279 | + '.btn-outline-secondary.dropdown-toggle' => array('b','o'), |
|
1280 | + '.badge-secondary' => array('b'), |
|
1281 | + '.alert-secondary' => array('b','o'), |
|
1282 | + '.btn-link.btn-secondary' => array('c'), |
|
1283 | + ); |
|
1284 | + |
|
1285 | + $important_selectors = array( |
|
1286 | + '.bg-secondary' => array('b','f'), |
|
1287 | + '.border-secondary' => array('o'), |
|
1288 | + '.text-secondary' => array('c'), |
|
1289 | + ); |
|
1290 | + |
|
1291 | + $color = array(); |
|
1292 | + $color_i = array(); |
|
1293 | + $background = array(); |
|
1294 | + $background_i = array(); |
|
1295 | + $border = array(); |
|
1296 | + $border_i = array(); |
|
1297 | + $fill = array(); |
|
1298 | + $fill_i = array(); |
|
1299 | + |
|
1300 | + $output = ''; |
|
1301 | + |
|
1302 | + // build rules into each type |
|
1303 | + foreach($selectors as $selector => $types){ |
|
1304 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1305 | + $types = array_combine($types,$types); |
|
1306 | + if(isset($types['c'])){$color[] = $selector;} |
|
1307 | + if(isset($types['b'])){$background[] = $selector;} |
|
1308 | + if(isset($types['o'])){$border[] = $selector;} |
|
1309 | + if(isset($types['f'])){$fill[] = $selector;} |
|
1310 | + } |
|
1311 | + |
|
1312 | + // build rules into each type |
|
1313 | + foreach($important_selectors as $selector => $types){ |
|
1314 | + $selector = $compatibility ? ".bsui ".$selector : $selector; |
|
1315 | + $types = array_combine($types,$types); |
|
1316 | + if(isset($types['c'])){$color_i[] = $selector;} |
|
1317 | + if(isset($types['b'])){$background_i[] = $selector;} |
|
1318 | + if(isset($types['o'])){$border_i[] = $selector;} |
|
1319 | + if(isset($types['f'])){$fill_i[] = $selector;} |
|
1320 | + } |
|
1321 | + |
|
1322 | + // add any color rules |
|
1323 | + if(!empty($color)){ |
|
1324 | + $output .= implode(",",$color) . "{color: $color_code;} "; |
|
1325 | + } |
|
1326 | + if(!empty($color_i)){ |
|
1327 | + $output .= implode(",",$color_i) . "{color: $color_code !important;} "; |
|
1328 | + } |
|
1329 | + |
|
1330 | + // add any background color rules |
|
1331 | + if(!empty($background)){ |
|
1332 | + $output .= implode(",",$background) . "{background-color: $color_code;} "; |
|
1333 | + } |
|
1334 | + if(!empty($background_i)){ |
|
1335 | + $output .= implode(",",$background_i) . "{background-color: $color_code !important;} "; |
|
1336 | + } |
|
1337 | + |
|
1338 | + // add any border color rules |
|
1339 | + if(!empty($border)){ |
|
1340 | + $output .= implode(",",$border) . "{border-color: $color_code;} "; |
|
1341 | + } |
|
1342 | + if(!empty($border_i)){ |
|
1343 | + $output .= implode(",",$border_i) . "{border-color: $color_code !important;} "; |
|
1344 | + } |
|
1345 | + |
|
1346 | + // add any fill color rules |
|
1347 | + if(!empty($fill)){ |
|
1348 | + $output .= implode(",",$fill) . "{fill: $color_code;} "; |
|
1349 | + } |
|
1350 | + if(!empty($fill_i)){ |
|
1351 | + $output .= implode(",",$fill_i) . "{fill: $color_code !important;} "; |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + $prefix = $compatibility ? ".bsui " : ""; |
|
1356 | + |
|
1357 | + // darken |
|
1358 | + $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075"); |
|
1359 | + $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10"); |
|
1360 | + $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125"); |
|
1361 | + |
|
1362 | + // lighten |
|
1363 | + $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25"); |
|
1364 | + |
|
1365 | + // opacity see https://css-tricks.com/8-digit-hex-codes/ |
|
1366 | + $op_25 = $color_code."40"; // 25% opacity |
|
1367 | + |
|
1368 | + |
|
1369 | + // button states |
|
1370 | + $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075."; border-color: ".$darker_10.";} "; |
|
1371 | + $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1372 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10."; border-color: ".$darker_125.";} "; |
|
1373 | + $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} "; |
|
1374 | + |
|
1375 | + |
|
1376 | + return $output; |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * Increases or decreases the brightness of a color by a percentage of the current brightness. |
|
1381 | + * |
|
1382 | + * @param string $hexCode Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF` |
|
1383 | + * @param float $adjustPercent A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker. |
|
1384 | + * |
|
1385 | + * @return string |
|
1386 | + */ |
|
1387 | + public static function css_hex_lighten_darken($hexCode, $adjustPercent) { |
|
1388 | + $hexCode = ltrim($hexCode, '#'); |
|
1389 | + |
|
1390 | + if (strlen($hexCode) == 3) { |
|
1391 | + $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2]; |
|
1392 | + } |
|
1393 | + |
|
1394 | + $hexCode = array_map('hexdec', str_split($hexCode, 2)); |
|
1395 | + |
|
1396 | + foreach ($hexCode as & $color) { |
|
1397 | + $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color; |
|
1398 | + $adjustAmount = ceil($adjustableLimit * $adjustPercent); |
|
1399 | + |
|
1400 | + $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT); |
|
1401 | + } |
|
1402 | + |
|
1403 | + return '#' . implode($hexCode); |
|
1404 | + } |
|
1405 | + |
|
1406 | + /** |
|
1407 | + * Check if we should display examples. |
|
1408 | + */ |
|
1409 | + public function maybe_show_examples(){ |
|
1410 | + if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){ |
|
1411 | + echo "<head>"; |
|
1412 | + wp_head(); |
|
1413 | + echo "</head>"; |
|
1414 | + echo "<body>"; |
|
1415 | + echo $this->get_examples(); |
|
1416 | + echo "</body>"; |
|
1417 | + exit; |
|
1418 | + } |
|
1419 | + } |
|
1420 | + |
|
1421 | + /** |
|
1422 | + * Get developer examples. |
|
1423 | + * |
|
1424 | + * @return string |
|
1425 | + */ |
|
1426 | + public function get_examples(){ |
|
1427 | + $output = ''; |
|
1428 | + |
|
1429 | + |
|
1430 | + // open form |
|
1431 | + $output .= "<form class='p-5 m-5 border rounded'>"; |
|
1432 | + |
|
1433 | + // input example |
|
1434 | + $output .= aui()->input(array( |
|
1435 | + 'type' => 'text', |
|
1436 | + 'id' => 'text-example', |
|
1437 | + 'name' => 'text-example', |
|
1438 | + 'placeholder' => 'text placeholder', |
|
1439 | + 'title' => 'Text input example', |
|
1440 | + 'value' => '', |
|
1441 | + 'required' => false, |
|
1442 | + 'help_text' => 'help text', |
|
1443 | + 'label' => 'Text input example label' |
|
1444 | + )); |
|
1445 | + |
|
1446 | + // input example |
|
1447 | + $output .= aui()->input(array( |
|
1448 | + 'type' => 'url', |
|
1449 | + 'id' => 'text-example2', |
|
1450 | + 'name' => 'text-example', |
|
1451 | + 'placeholder' => 'url placeholder', |
|
1452 | + 'title' => 'Text input example', |
|
1453 | + 'value' => '', |
|
1454 | + 'required' => false, |
|
1455 | + 'help_text' => 'help text', |
|
1456 | + 'label' => 'Text input example label' |
|
1457 | + )); |
|
1458 | + |
|
1459 | + // checkbox example |
|
1460 | + $output .= aui()->input(array( |
|
1461 | + 'type' => 'checkbox', |
|
1462 | + 'id' => 'checkbox-example', |
|
1463 | + 'name' => 'checkbox-example', |
|
1464 | + 'placeholder' => 'checkbox-example', |
|
1465 | + 'title' => 'Checkbox example', |
|
1466 | + 'value' => '1', |
|
1467 | + 'checked' => true, |
|
1468 | + 'required' => false, |
|
1469 | + 'help_text' => 'help text', |
|
1470 | + 'label' => 'Checkbox checked' |
|
1471 | + )); |
|
1472 | + |
|
1473 | + // checkbox example |
|
1474 | + $output .= aui()->input(array( |
|
1475 | + 'type' => 'checkbox', |
|
1476 | + 'id' => 'checkbox-example2', |
|
1477 | + 'name' => 'checkbox-example2', |
|
1478 | + 'placeholder' => 'checkbox-example', |
|
1479 | + 'title' => 'Checkbox example', |
|
1480 | + 'value' => '1', |
|
1481 | + 'checked' => false, |
|
1482 | + 'required' => false, |
|
1483 | + 'help_text' => 'help text', |
|
1484 | + 'label' => 'Checkbox un-checked' |
|
1485 | + )); |
|
1486 | + |
|
1487 | + // switch example |
|
1488 | + $output .= aui()->input(array( |
|
1489 | + 'type' => 'checkbox', |
|
1490 | + 'id' => 'switch-example', |
|
1491 | + 'name' => 'switch-example', |
|
1492 | + 'placeholder' => 'checkbox-example', |
|
1493 | + 'title' => 'Switch example', |
|
1494 | + 'value' => '1', |
|
1495 | + 'checked' => true, |
|
1496 | + 'switch' => true, |
|
1497 | + 'required' => false, |
|
1498 | + 'help_text' => 'help text', |
|
1499 | + 'label' => 'Switch on' |
|
1500 | + )); |
|
1501 | + |
|
1502 | + // switch example |
|
1503 | + $output .= aui()->input(array( |
|
1504 | + 'type' => 'checkbox', |
|
1505 | + 'id' => 'switch-example2', |
|
1506 | + 'name' => 'switch-example2', |
|
1507 | + 'placeholder' => 'checkbox-example', |
|
1508 | + 'title' => 'Switch example', |
|
1509 | + 'value' => '1', |
|
1510 | + 'checked' => false, |
|
1511 | + 'switch' => true, |
|
1512 | + 'required' => false, |
|
1513 | + 'help_text' => 'help text', |
|
1514 | + 'label' => 'Switch off' |
|
1515 | + )); |
|
1516 | + |
|
1517 | + // close form |
|
1518 | + $output .= "</form>"; |
|
1519 | + |
|
1520 | + return $output; |
|
1521 | + } |
|
1522 | + |
|
1523 | + } |
|
1524 | + |
|
1525 | + /** |
|
1526 | + * Run the class if found. |
|
1527 | + */ |
|
1528 | + AyeCode_UI_Settings::instance(); |
|
1529 | 1529 | } |
1530 | 1530 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined( 'ABSPATH' ) ) { |
4 | - exit; // Exit if accessed directly |
|
4 | + exit; // Exit if accessed directly |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -11,231 +11,231 @@ discard block |
||
11 | 11 | */ |
12 | 12 | class AUI { |
13 | 13 | |
14 | - /** |
|
15 | - * Holds the class instance. |
|
16 | - * |
|
17 | - * @since 1.0.0 |
|
18 | - * @var null |
|
19 | - */ |
|
20 | - private static $instance = null; |
|
21 | - |
|
22 | - /** |
|
23 | - * Holds the current AUI version number. |
|
24 | - * |
|
25 | - * @var string $ver The current version number. |
|
26 | - */ |
|
27 | - public static $ver = '0.1.33'; |
|
28 | - |
|
29 | - public static $options = null; |
|
30 | - |
|
31 | - /** |
|
32 | - * There can be only one. |
|
33 | - * |
|
34 | - * @since 1.0.0 |
|
35 | - * @return AUI|null |
|
36 | - */ |
|
37 | - public static function instance() { |
|
38 | - if ( self::$instance == null ) { |
|
39 | - self::$instance = new AUI(); |
|
40 | - } |
|
41 | - |
|
42 | - return self::$instance; |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * AUI constructor. |
|
47 | - * |
|
48 | - * @since 1.0.0 |
|
49 | - */ |
|
50 | - private function __construct() { |
|
51 | - if ( function_exists( "__autoload" ) ) { |
|
52 | - spl_autoload_register( "__autoload" ); |
|
53 | - } |
|
54 | - spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | - |
|
56 | - // load options |
|
57 | - self::$options = get_option('aui_options'); |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * Autoload any components on the fly. |
|
62 | - * |
|
63 | - * @since 1.0.0 |
|
64 | - * |
|
65 | - * @param $classname |
|
66 | - */ |
|
67 | - private function autoload( $classname ) { |
|
68 | - $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | - $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | - if ( $file_path && is_readable( $file_path ) ) { |
|
71 | - include_once( $file_path ); |
|
72 | - } |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Get the AUI options. |
|
77 | - * |
|
78 | - * @param $option |
|
79 | - * |
|
80 | - * @return string|void |
|
81 | - */ |
|
82 | - public function get_option( $option ){ |
|
83 | - $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | - |
|
85 | - if ( ! $result && $option) { |
|
86 | - if( $option == 'color_primary' ){ |
|
87 | - $result = AUI_PRIMARY_COLOR; |
|
88 | - }elseif( $option == 'color_secondary' ){ |
|
89 | - $result = AUI_SECONDARY_COLOR; |
|
90 | - } |
|
91 | - } |
|
92 | - return $result; |
|
93 | - } |
|
94 | - |
|
95 | - public function render( $items = array() ) { |
|
96 | - $output = ''; |
|
97 | - |
|
98 | - if ( ! empty( $items ) ) { |
|
99 | - foreach ( $items as $args ) { |
|
100 | - $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | - if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | - $output .= $this->$render( $args ); |
|
103 | - } |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - return $output; |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Render and return a bootstrap alert component. |
|
112 | - * |
|
113 | - * @since 1.0.0 |
|
114 | - * |
|
115 | - * @param array $args |
|
116 | - * |
|
117 | - * @return string The rendered component. |
|
118 | - */ |
|
119 | - public function alert( $args = array() ) { |
|
120 | - return AUI_Component_Alert::get( $args ); |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Render and return a bootstrap input component. |
|
125 | - * |
|
126 | - * @since 1.0.0 |
|
127 | - * |
|
128 | - * @param array $args |
|
129 | - * |
|
130 | - * @return string The rendered component. |
|
131 | - */ |
|
132 | - public function input( $args = array() ) { |
|
133 | - return AUI_Component_Input::input( $args ); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Render and return a bootstrap textarea component. |
|
138 | - * |
|
139 | - * @since 1.0.0 |
|
140 | - * |
|
141 | - * @param array $args |
|
142 | - * |
|
143 | - * @return string The rendered component. |
|
144 | - */ |
|
145 | - public function textarea( $args = array() ) { |
|
146 | - return AUI_Component_Input::textarea( $args ); |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Render and return a bootstrap button component. |
|
151 | - * |
|
152 | - * @since 1.0.0 |
|
153 | - * |
|
154 | - * @param array $args |
|
155 | - * |
|
156 | - * @return string The rendered component. |
|
157 | - */ |
|
158 | - public function button( $args = array() ) { |
|
159 | - return AUI_Component_Button::get( $args ); |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Render and return a bootstrap button component. |
|
164 | - * |
|
165 | - * @since 1.0.0 |
|
166 | - * |
|
167 | - * @param array $args |
|
168 | - * |
|
169 | - * @return string The rendered component. |
|
170 | - */ |
|
171 | - public function badge( $args = array() ) { |
|
172 | - $defaults = array( |
|
173 | - 'class' => 'badge badge-primary align-middle', |
|
174 | - ); |
|
175 | - |
|
176 | - // maybe set type |
|
177 | - if ( empty( $args['href'] ) ) { |
|
178 | - $defaults['type'] = 'badge'; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Parse incoming $args into an array and merge it with $defaults |
|
183 | - */ |
|
184 | - $args = wp_parse_args( $args, $defaults ); |
|
185 | - |
|
186 | - return AUI_Component_Button::get( $args ); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Render and return a bootstrap dropdown component. |
|
191 | - * |
|
192 | - * @since 1.0.0 |
|
193 | - * |
|
194 | - * @param array $args |
|
195 | - * |
|
196 | - * @return string The rendered component. |
|
197 | - */ |
|
198 | - public function dropdown( $args = array() ) { |
|
199 | - return AUI_Component_Dropdown::get( $args ); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Render and return a bootstrap select component. |
|
204 | - * |
|
205 | - * @since 1.0.0 |
|
206 | - * |
|
207 | - * @param array $args |
|
208 | - * |
|
209 | - * @return string The rendered component. |
|
210 | - */ |
|
211 | - public function select( $args = array() ) { |
|
212 | - return AUI_Component_Input::select( $args ); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Render and return a bootstrap radio component. |
|
217 | - * |
|
218 | - * @since 1.0.0 |
|
219 | - * |
|
220 | - * @param array $args |
|
221 | - * |
|
222 | - * @return string The rendered component. |
|
223 | - */ |
|
224 | - public function radio( $args = array() ) { |
|
225 | - return AUI_Component_Input::radio( $args ); |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Render and return a bootstrap pagination component. |
|
230 | - * |
|
231 | - * @since 1.0.0 |
|
232 | - * |
|
233 | - * @param array $args |
|
234 | - * |
|
235 | - * @return string The rendered component. |
|
236 | - */ |
|
237 | - public function pagination( $args = array() ) { |
|
238 | - return AUI_Component_Pagination::get( $args ); |
|
239 | - } |
|
14 | + /** |
|
15 | + * Holds the class instance. |
|
16 | + * |
|
17 | + * @since 1.0.0 |
|
18 | + * @var null |
|
19 | + */ |
|
20 | + private static $instance = null; |
|
21 | + |
|
22 | + /** |
|
23 | + * Holds the current AUI version number. |
|
24 | + * |
|
25 | + * @var string $ver The current version number. |
|
26 | + */ |
|
27 | + public static $ver = '0.1.33'; |
|
28 | + |
|
29 | + public static $options = null; |
|
30 | + |
|
31 | + /** |
|
32 | + * There can be only one. |
|
33 | + * |
|
34 | + * @since 1.0.0 |
|
35 | + * @return AUI|null |
|
36 | + */ |
|
37 | + public static function instance() { |
|
38 | + if ( self::$instance == null ) { |
|
39 | + self::$instance = new AUI(); |
|
40 | + } |
|
41 | + |
|
42 | + return self::$instance; |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * AUI constructor. |
|
47 | + * |
|
48 | + * @since 1.0.0 |
|
49 | + */ |
|
50 | + private function __construct() { |
|
51 | + if ( function_exists( "__autoload" ) ) { |
|
52 | + spl_autoload_register( "__autoload" ); |
|
53 | + } |
|
54 | + spl_autoload_register( array( $this, 'autoload' ) ); |
|
55 | + |
|
56 | + // load options |
|
57 | + self::$options = get_option('aui_options'); |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * Autoload any components on the fly. |
|
62 | + * |
|
63 | + * @since 1.0.0 |
|
64 | + * |
|
65 | + * @param $classname |
|
66 | + */ |
|
67 | + private function autoload( $classname ) { |
|
68 | + $class = str_replace( '_', '-', strtolower( $classname ) ); |
|
69 | + $file_path = trailingslashit( dirname( __FILE__ ) ) . "components/class-" . $class . '.php'; |
|
70 | + if ( $file_path && is_readable( $file_path ) ) { |
|
71 | + include_once( $file_path ); |
|
72 | + } |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Get the AUI options. |
|
77 | + * |
|
78 | + * @param $option |
|
79 | + * |
|
80 | + * @return string|void |
|
81 | + */ |
|
82 | + public function get_option( $option ){ |
|
83 | + $result = isset(self::$options[$option]) ? esc_attr(self::$options[$option]) : ''; |
|
84 | + |
|
85 | + if ( ! $result && $option) { |
|
86 | + if( $option == 'color_primary' ){ |
|
87 | + $result = AUI_PRIMARY_COLOR; |
|
88 | + }elseif( $option == 'color_secondary' ){ |
|
89 | + $result = AUI_SECONDARY_COLOR; |
|
90 | + } |
|
91 | + } |
|
92 | + return $result; |
|
93 | + } |
|
94 | + |
|
95 | + public function render( $items = array() ) { |
|
96 | + $output = ''; |
|
97 | + |
|
98 | + if ( ! empty( $items ) ) { |
|
99 | + foreach ( $items as $args ) { |
|
100 | + $render = isset( $args['render'] ) ? $args['render'] : ''; |
|
101 | + if ( $render && method_exists( __CLASS__, $render ) ) { |
|
102 | + $output .= $this->$render( $args ); |
|
103 | + } |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + return $output; |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Render and return a bootstrap alert component. |
|
112 | + * |
|
113 | + * @since 1.0.0 |
|
114 | + * |
|
115 | + * @param array $args |
|
116 | + * |
|
117 | + * @return string The rendered component. |
|
118 | + */ |
|
119 | + public function alert( $args = array() ) { |
|
120 | + return AUI_Component_Alert::get( $args ); |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Render and return a bootstrap input component. |
|
125 | + * |
|
126 | + * @since 1.0.0 |
|
127 | + * |
|
128 | + * @param array $args |
|
129 | + * |
|
130 | + * @return string The rendered component. |
|
131 | + */ |
|
132 | + public function input( $args = array() ) { |
|
133 | + return AUI_Component_Input::input( $args ); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Render and return a bootstrap textarea component. |
|
138 | + * |
|
139 | + * @since 1.0.0 |
|
140 | + * |
|
141 | + * @param array $args |
|
142 | + * |
|
143 | + * @return string The rendered component. |
|
144 | + */ |
|
145 | + public function textarea( $args = array() ) { |
|
146 | + return AUI_Component_Input::textarea( $args ); |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Render and return a bootstrap button component. |
|
151 | + * |
|
152 | + * @since 1.0.0 |
|
153 | + * |
|
154 | + * @param array $args |
|
155 | + * |
|
156 | + * @return string The rendered component. |
|
157 | + */ |
|
158 | + public function button( $args = array() ) { |
|
159 | + return AUI_Component_Button::get( $args ); |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Render and return a bootstrap button component. |
|
164 | + * |
|
165 | + * @since 1.0.0 |
|
166 | + * |
|
167 | + * @param array $args |
|
168 | + * |
|
169 | + * @return string The rendered component. |
|
170 | + */ |
|
171 | + public function badge( $args = array() ) { |
|
172 | + $defaults = array( |
|
173 | + 'class' => 'badge badge-primary align-middle', |
|
174 | + ); |
|
175 | + |
|
176 | + // maybe set type |
|
177 | + if ( empty( $args['href'] ) ) { |
|
178 | + $defaults['type'] = 'badge'; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Parse incoming $args into an array and merge it with $defaults |
|
183 | + */ |
|
184 | + $args = wp_parse_args( $args, $defaults ); |
|
185 | + |
|
186 | + return AUI_Component_Button::get( $args ); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Render and return a bootstrap dropdown component. |
|
191 | + * |
|
192 | + * @since 1.0.0 |
|
193 | + * |
|
194 | + * @param array $args |
|
195 | + * |
|
196 | + * @return string The rendered component. |
|
197 | + */ |
|
198 | + public function dropdown( $args = array() ) { |
|
199 | + return AUI_Component_Dropdown::get( $args ); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Render and return a bootstrap select component. |
|
204 | + * |
|
205 | + * @since 1.0.0 |
|
206 | + * |
|
207 | + * @param array $args |
|
208 | + * |
|
209 | + * @return string The rendered component. |
|
210 | + */ |
|
211 | + public function select( $args = array() ) { |
|
212 | + return AUI_Component_Input::select( $args ); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Render and return a bootstrap radio component. |
|
217 | + * |
|
218 | + * @since 1.0.0 |
|
219 | + * |
|
220 | + * @param array $args |
|
221 | + * |
|
222 | + * @return string The rendered component. |
|
223 | + */ |
|
224 | + public function radio( $args = array() ) { |
|
225 | + return AUI_Component_Input::radio( $args ); |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Render and return a bootstrap pagination component. |
|
230 | + * |
|
231 | + * @since 1.0.0 |
|
232 | + * |
|
233 | + * @param array $args |
|
234 | + * |
|
235 | + * @return string The rendered component. |
|
236 | + */ |
|
237 | + public function pagination( $args = array() ) { |
|
238 | + return AUI_Component_Pagination::get( $args ); |
|
239 | + } |
|
240 | 240 | |
241 | 241 | } |
242 | 242 | \ No newline at end of file |
@@ -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.33"; |
|
19 | - if(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.33"; |
|
19 | + if(version_compare($this_version , $ayecode_ui_version, '>')){ |
|
20 | + $ayecode_ui_version = $this_version ; |
|
21 | + $ayecode_ui_file_key = wp_hash( __FILE__ ); |
|
22 | + } |
|
23 | 23 | },0); |
24 | 24 | |
25 | 25 | /** |
26 | 26 | * Load this version of WP Bootstrap Settings only if the file hash is the current one. |
27 | 27 | */ |
28 | 28 | add_action('after_setup_theme', function () { |
29 | - global $ayecode_ui_file_key; |
|
30 | - if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | - include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | - include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | - } |
|
29 | + global $ayecode_ui_file_key; |
|
30 | + if($ayecode_ui_file_key && $ayecode_ui_file_key == wp_hash( __FILE__ )){ |
|
31 | + include_once( dirname( __FILE__ ) . '/includes/class-aui.php' ); |
|
32 | + include_once( dirname( __FILE__ ) . '/includes/ayecode-ui-settings.php' ); |
|
33 | + } |
|
34 | 34 | },1); |
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Add the function that calls the class. |
38 | 38 | */ |
39 | 39 | if(!function_exists('aui')){ |
40 | - function aui(){ |
|
41 | - if(!class_exists("AUI",false)){ |
|
42 | - return false; |
|
43 | - } |
|
44 | - return AUI::instance(); |
|
45 | - } |
|
40 | + function aui(){ |
|
41 | + if(!class_exists("AUI",false)){ |
|
42 | + return false; |
|
43 | + } |
|
44 | + return AUI::instance(); |
|
45 | + } |
|
46 | 46 | } |
47 | 47 | \ No newline at end of file |