PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.3.1
GiveWP – Donation Plugin and Fundraising Platform v2.3.1
4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / class-give-html-elements.php
give / includes Last commit date
admin 7 years ago api 7 years ago deprecated 7 years ago donors 7 years ago emails 7 years ago forms 7 years ago gateways 7 years ago libraries 7 years ago payments 7 years ago actions.php 7 years ago ajax-functions.php 7 years ago class-give-async-process.php 7 years ago class-give-background-updater.php 7 years ago class-give-cache.php 7 years ago class-give-cli-commands.php 7 years ago class-give-comment.php 7 years ago class-give-cron.php 7 years ago class-give-db-comments-meta.php 7 years ago class-give-db-comments.php 7 years ago class-give-db-donor-meta.php 7 years ago class-give-db-donors.php 7 years ago class-give-db-form-meta.php 7 years ago class-give-db-logs-meta.php 7 years ago class-give-db-logs.php 7 years ago class-give-db-meta.php 7 years ago class-give-db-payment-meta.php 7 years ago class-give-db-sequential-ordering.php 7 years ago class-give-db-sessions.php 7 years ago class-give-db.php 7 years ago class-give-donate-form.php 7 years ago class-give-donor-wall-widget.php 7 years ago class-give-donor.php 7 years ago class-give-email-access.php 7 years ago class-give-html-elements.php 7 years ago class-give-license-handler.php 7 years ago class-give-logging.php 7 years ago class-give-readme-parser.php 7 years ago class-give-roles.php 7 years ago class-give-scripts.php 7 years ago class-give-session.php 7 years ago class-give-stats.php 8 years ago class-give-template-loader.php 8 years ago class-give-tooltips.php 7 years ago class-give-translation.php 8 years ago class-notices.php 7 years ago country-functions.php 7 years ago currency-functions.php 7 years ago error-tracking.php 7 years ago filters.php 7 years ago formatting.php 7 years ago import-functions.php 7 years ago install.php 7 years ago login-register.php 7 years ago misc-functions.php 7 years ago plugin-compatibility.php 7 years ago post-types.php 7 years ago price-functions.php 7 years ago process-donation.php 7 years ago shortcodes.php 7 years ago template-functions.php 7 years ago user-functions.php 7 years ago
class-give-html-elements.php
755 lines
1 <?php
2 /**
3 * HTML elements
4 *
5 * @package Give
6 * @subpackage Classes/Give_HTML_Elements
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Give_HTML_Elements Class
19 *
20 * A helper class for outputting common HTML elements, such as product drop downs.
21 *
22 * @since 1.0
23 */
24 class Give_HTML_Elements {
25
26 /**
27 * Donations Dropdown
28 *
29 * Renders an HTML Dropdown of all the donations.
30 *
31 * @since 1.0
32 * @access public
33 *
34 * @param array $args Arguments for the dropdown.
35 *
36 * @return string Donations dropdown.
37 */
38 public function donations_dropdown( $args = array() ) {
39
40 $defaults = array(
41 'name' => 'donations',
42 'id' => 'donations',
43 'class' => '',
44 'multiple' => false,
45 'selected' => 0,
46 'chosen' => false,
47 'number' => 30,
48 'placeholder' => __( 'Select a donation', 'give' ),
49 );
50
51 $args = wp_parse_args( $args, $defaults );
52
53 $payments = new Give_Payments_Query( array(
54 'number' => $args['number'],
55 ) );
56
57 $payments = $payments->get_payments();
58
59 $options = array();
60
61 // Provide nice human readable options.
62 if ( $payments ) {
63 $options[0] = $args['placeholder'];
64 foreach ( $payments as $payment ) {
65
66 $options[ absint( $payment->ID ) ] = esc_html( '#' . $payment->ID . ' - ' . $payment->email . ' - ' . $payment->form_title );
67
68 }
69 } else {
70 $options[0] = __( 'No donations found.', 'give' );
71 }
72
73 $output = $this->select( array(
74 'name' => $args['name'],
75 'selected' => $args['selected'],
76 'id' => $args['id'],
77 'class' => $args['class'],
78 'options' => $options,
79 'chosen' => $args['chosen'],
80 'multiple' => $args['multiple'],
81 'placeholder' => $args['placeholder'],
82 'select_atts' => $args['select_atts'],
83 'show_option_all' => false,
84 'show_option_none' => false,
85 ) );
86
87 return $output;
88 }
89
90 /**
91 * Give Forms Dropdown
92 *
93 * Renders an HTML Dropdown of all the Give Forms.
94 *
95 * @since 1.0
96 * @access public
97 *
98 * @param array $args Arguments for the dropdown.
99 *
100 * @return string Give forms dropdown.
101 */
102 public function forms_dropdown( $args = array() ) {
103
104 $defaults = array(
105 'name' => 'forms',
106 'id' => 'forms',
107 'class' => '',
108 'multiple' => false,
109 'selected' => 0,
110 'chosen' => false,
111 'number' => 30,
112 'placeholder' => esc_attr__( 'All Forms', 'give' ),
113 'data' => array(
114 'search-type' => 'form',
115 ),
116 'query_args' => array()
117 );
118
119 $args = wp_parse_args( $args, $defaults );
120
121 $form_args = wp_parse_args(
122 $args['query_args'],
123 array(
124 'post_type' => 'give_forms',
125 'orderby' => 'title',
126 'order' => 'ASC',
127 'posts_per_page' => $args['number'],
128 )
129 );
130
131 /**
132 * Filter the forms dropdown.
133 *
134 * @since 2.3.0
135 *
136 * @param array $form_args Arguments for forms_dropdown query.
137 *
138 * @return array Arguments for forms_dropdown query.
139 */
140 $form_args = apply_filters( 'give_forms_dropdown_args', $form_args );
141
142 $cache_key = Give_Cache::get_key( 'give_forms', $form_args, false );
143
144 // Get forms from cache.
145 $forms = Give_Cache::get_db_query( $cache_key );
146
147 if ( is_null( $forms ) ) {
148 $forms = new WP_Query( $form_args );
149 $forms = $forms->posts;
150 Give_Cache::set_db_query( $cache_key, $forms );
151 }
152
153 $options = array();
154
155 // Ensure the selected.
156 if ( false !== $args['selected'] && $args['selected'] !== 0 ) {
157 $options[ $args['selected'] ] = get_the_title( $args['selected'] );
158 }
159
160 $options[0] = esc_html__( 'No forms found.', 'give' );
161 if ( ! empty( $forms ) ) {
162 $options[0] = $args['placeholder'];
163 foreach ( $forms as $form ) {
164 $form_title = empty( $form->post_title )
165 ? sprintf( __( 'Untitled (#%s)', 'give' ), $form->ID )
166 : $form->post_title;
167
168 $options[ absint( $form->ID ) ] = esc_html( $form_title );
169 }
170 }
171
172 $output = $this->select( array(
173 'name' => $args['name'],
174 'selected' => $args['selected'],
175 'id' => $args['id'],
176 'class' => $args['class'],
177 'options' => $options,
178 'chosen' => $args['chosen'],
179 'multiple' => $args['multiple'],
180 'placeholder' => $args['placeholder'],
181 'show_option_all' => false,
182 'show_option_none' => false,
183 'data' => $args['data'],
184 ) );
185
186 return $output;
187 }
188
189 /**
190 * Donors Dropdown
191 *
192 * Renders an HTML Dropdown of all donors.
193 *
194 * @since 1.0
195 * @access public
196 *
197 * @param array $args Arguments for the dropdown.
198 *
199 * @return string Donors dropdown.
200 */
201 public function donor_dropdown( $args = array() ) {
202
203 $defaults = array(
204 'name' => 'donors',
205 'id' => 'donors',
206 'class' => '',
207 'multiple' => false,
208 'selected' => 0,
209 'chosen' => true,
210 'placeholder' => esc_attr__( 'Select a Donor', 'give' ),
211 'number' => 30,
212 'data' => array(
213 'search-type' => 'donor',
214 ),
215 );
216
217 $args = wp_parse_args( $args, $defaults );
218
219 $donors = Give()->donors->get_donors( array(
220 'number' => $args['number'],
221 ) );
222
223 $options = array();
224
225 if ( $donors ) {
226 $options[0] = esc_html__( 'No donor attached', 'give' );
227 foreach ( $donors as $donor ) {
228 $donor = give_get_name_with_title_prefixes( $donor );
229 $options[ absint( $donor->id ) ] = esc_html( $donor->name . ' (' . $donor->email . ')' );
230 }
231 } else {
232 $options[0] = esc_html__( 'No donors found.', 'give' );
233 }
234
235 if ( ! empty( $args['selected'] ) ) {
236
237 // If a selected customer has been specified, we need to ensure it's in the initial list of customers displayed.
238 if ( ! array_key_exists( $args['selected'], $options ) ) {
239
240 $donor = new Give_Donor( $args['selected'] );
241
242 if ( $donor ) {
243 $donor = give_get_name_with_title_prefixes( $donor );
244 $options[ absint( $args['selected'] ) ] = esc_html( $donor->name . ' (' . $donor->email . ')' );
245
246 }
247 }
248 }
249
250 $output = $this->select( array(
251 'name' => $args['name'],
252 'selected' => $args['selected'],
253 'id' => $args['id'],
254 'class' => $args['class'] . ' give-customer-select',
255 'options' => $options,
256 'multiple' => $args['multiple'],
257 'chosen' => $args['chosen'],
258 'show_option_all' => false,
259 'show_option_none' => false,
260 'data' => $args['data'],
261 ) );
262
263 return $output;
264 }
265
266 /**
267 * Categories Dropdown
268 *
269 * Renders an HTML Dropdown of all the Categories.
270 *
271 * @since 1.0
272 * @access public
273 *
274 * @param string $name Name attribute of the dropdown. Default is 'give_forms_categories'.
275 * @param int $selected Category to select automatically. Default is 0.
276 * @param array $args Select box options.
277 *
278 * @return string Categories dropdown.
279 */
280 public function category_dropdown( $name = 'give_forms_categories', $selected = 0, $args = array() ) {
281 $categories = get_terms( 'give_forms_category', apply_filters( 'give_forms_category_dropdown', array() ) );
282
283 $options = array();
284
285 foreach ( $categories as $category ) {
286 $options[ absint( $category->term_id ) ] = esc_html( $category->name );
287 }
288
289 $output = $this->select( wp_parse_args( $args, array(
290 'name' => $name,
291 'selected' => $selected,
292 'options' => $options,
293 'show_option_all' => esc_html__( 'All Categories', 'give' ),
294 'show_option_none' => false,
295 ) ) );
296
297 return $output;
298 }
299
300 /**
301 * Tags Dropdown
302 *
303 * Renders an HTML Dropdown of all the Tags.
304 *
305 * @since 1.8
306 * @access public
307 *
308 * @param string $name Name attribute of the dropdown. Default is 'give_forms_tags'.
309 * @param int $selected Tag to select automatically. Default is 0.
310 * @param array $args Select box options.
311 *
312 * @return string Tags dropdown.
313 */
314 public function tags_dropdown( $name = 'give_forms_tags', $selected = 0, $args = array() ) {
315 $tags = get_terms( 'give_forms_tag', apply_filters( 'give_forms_tag_dropdown', array() ) );
316
317 $options = array();
318
319 foreach ( $tags as $tag ) {
320 $options[ absint( $tag->term_id ) ] = esc_html( $tag->name );
321 }
322
323 $output = $this->select( wp_parse_args( $args, array(
324 'name' => $name,
325 'selected' => $selected,
326 'options' => $options,
327 'show_option_all' => esc_html__( 'All Tags', 'give' ),
328 'show_option_none' => false,
329 ) ) );
330
331 return $output;
332 }
333
334 /**
335 * Years Dropdown
336 *
337 * Renders an HTML Dropdown of years.
338 *
339 * @since 1.0
340 * @access public
341 *
342 * @param string $name Name attribute of the dropdown. Default is 'year'.
343 * @param int $selected Year to select automatically. Default is 0.
344 * @param int $years_before Number of years before the current year the dropdown should start with. Default is 5.
345 * @param int $years_after Number of years after the current year the dropdown should finish at. Default is 0.
346 *
347 * @return string Years dropdown.
348 */
349 public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
350 $current = date( 'Y' );
351 $start_year = $current - absint( $years_before );
352 $end_year = $current + absint( $years_after );
353 $selected = empty( $selected ) ? date( 'Y' ) : $selected;
354 $options = array();
355
356 while ( $start_year <= $end_year ) {
357 $options[ absint( $start_year ) ] = $start_year;
358 $start_year ++;
359 }
360
361 $output = $this->select( array(
362 'name' => $name,
363 'selected' => $selected,
364 'options' => $options,
365 'show_option_all' => false,
366 'show_option_none' => false,
367 ) );
368
369 return $output;
370 }
371
372 /**
373 * Months Dropdown
374 *
375 * Renders an HTML Dropdown of months.
376 *
377 * @since 1.0
378 * @access public
379 *
380 * @param string $name Name attribute of the dropdown. Default is 'month'.
381 * @param int $selected Month to select automatically. Default is 0.
382 *
383 * @return string Months dropdown.
384 */
385 public function month_dropdown( $name = 'month', $selected = 0 ) {
386 $month = 1;
387 $options = array();
388 $selected = empty( $selected ) ? date( 'n' ) : $selected;
389
390 while ( $month <= 12 ) {
391 $options[ absint( $month ) ] = give_month_num_to_name( $month );
392 $month ++;
393 }
394
395 $output = $this->select( array(
396 'name' => $name,
397 'selected' => $selected,
398 'options' => $options,
399 'show_option_all' => false,
400 'show_option_none' => false,
401 ) );
402
403 return $output;
404 }
405
406 /**
407 * Dropdown
408 *
409 * Renders an HTML Dropdown.
410 *
411 * @since 1.0
412 * @access public
413 *
414 * @param array $args Arguments for the dropdown.
415 *
416 * @return string The dropdown.
417 */
418 public function select( $args = array() ) {
419 $defaults = array(
420 'options' => array(),
421 'name' => null,
422 'class' => '',
423 'id' => '',
424 'selected' => 0,
425 'chosen' => false,
426 'placeholder' => null,
427 'multiple' => false,
428 'select_atts' => false,
429 'show_option_all' => __( 'All', 'give' ),
430 'show_option_none' => __( 'None', 'give' ),
431 'data' => array(),
432 'readonly' => false,
433 'disabled' => false,
434 );
435
436 $args = wp_parse_args( $args, $defaults );
437
438 $data_elements = '';
439 foreach ( $args['data'] as $key => $value ) {
440 $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
441 }
442
443 $multiple = '';
444 if ( $args['multiple'] ) {
445 $multiple = 'MULTIPLE';
446 }
447
448 if ( $args['chosen'] ) {
449 $args['class'] .= ' give-select-chosen';
450 }
451
452 $placeholder = '';
453 if ( $args['placeholder'] ) {
454 $placeholder = $args['placeholder'];
455 }
456
457 $output = sprintf(
458 '<select name="%1$s" id="%2$s" autocomplete="address-level4" class="give-select %3$s" %4$s %5$s placeholder="%6$s" data-placeholder="%6$s" %7$s>',
459 esc_attr( $args['name'] ),
460 esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ),
461 esc_attr( $args['class'] ),
462 $multiple,
463 $args['select_atts'],
464 $placeholder,
465 $data_elements
466 );
467
468 if ( $args['show_option_all'] ) {
469 if ( $args['multiple'] ) {
470 $selected = selected( true, in_array( 0, $args['selected'] ), false );
471 } else {
472 $selected = selected( $args['selected'], 0, false );
473 }
474 $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
475 }
476
477 if ( ! empty( $args['options'] ) ) {
478
479 if ( $args['show_option_none'] ) {
480 if ( $args['multiple'] ) {
481 $selected = selected( true, in_array( - 1, $args['selected'] ), false );
482 } else {
483 $selected = selected( $args['selected'], - 1, false );
484 }
485 $output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
486 }
487
488 foreach ( $args['options'] as $key => $option ) {
489
490 if ( $args['multiple'] && is_array( $args['selected'] ) ) {
491 $selected = selected( true, in_array( $key, $args['selected'] ), false );
492 } else {
493 $selected = selected( $args['selected'], $key, false );
494 }
495
496 $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
497 }
498 }
499
500 $output .= '</select>';
501
502 return $output;
503 }
504
505 /**
506 * Checkbox
507 *
508 * Renders an HTML Checkbox.
509 *
510 * @since 1.0
511 * @access public
512 *
513 * @param array $args Arguments for the Checkbox.
514 *
515 * @return string The checkbox.
516 */
517 public function checkbox( $args = array() ) {
518 $defaults = array(
519 'name' => null,
520 'current' => null,
521 'class' => 'give-checkbox',
522 'options' => array(
523 'disabled' => false,
524 'readonly' => false,
525 ),
526 );
527
528 $args = wp_parse_args( $args, $defaults );
529
530 $options = '';
531 if ( ! empty( $args['options']['disabled'] ) ) {
532 $options .= ' disabled="disabled"';
533 } elseif ( ! empty( $args['options']['readonly'] ) ) {
534 $options .= ' readonly';
535 }
536
537 $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
538
539 return $output;
540 }
541
542 /**
543 * Text Field
544 *
545 * Renders an HTML Text field.
546 *
547 * @since 1.0
548 * @access public
549 *
550 * @param array $args Arguments for the text field.
551 *
552 * @return string The text field.
553 */
554 public function text( $args = array() ) {
555 // Backwards compatibility.
556 if ( func_num_args() > 1 ) {
557 $args = func_get_args();
558
559 $name = $args[0];
560 $value = isset( $args[1] ) ? $args[1] : '';
561 $label = isset( $args[2] ) ? $args[2] : '';
562 $desc = isset( $args[3] ) ? $args[3] : '';
563 }
564
565 $defaults = array(
566 'name' => isset( $name ) ? $name : 'text',
567 'value' => isset( $value ) ? $value : null,
568 'label' => isset( $label ) ? $label : null,
569 'desc' => isset( $desc ) ? $desc : null,
570 'placeholder' => '',
571 'class' => 'regular-text',
572 'disabled' => false,
573 'autocomplete' => '',
574 'data' => false,
575 );
576
577 $args = wp_parse_args( $args, $defaults );
578
579 $disabled = '';
580 if ( $args['disabled'] ) {
581 $disabled = ' disabled="disabled"';
582 }
583
584 $data = '';
585 if ( ! empty( $args['data'] ) ) {
586 foreach ( $args['data'] as $key => $value ) {
587 $data .= 'data-' . $key . '="' . $value . '" ';
588 }
589 }
590
591 $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
592
593 $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
594
595 if ( ! empty( $args['desc'] ) ) {
596 $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
597 }
598
599 $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" autocomplete="' . esc_attr( $args['autocomplete'] ) . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $args['class'] . '" ' . $data . '' . $disabled . '/>';
600
601 $output .= '</span>';
602
603 return $output;
604 }
605
606 /**
607 * Date Picker
608 *
609 * Renders a date picker field.
610 *
611 * @since 1.5
612 * @access public
613 *
614 * @param array $args Arguments for the date picker.
615 *
616 * @return string The date picker.
617 */
618 public function date_field( $args = array() ) {
619
620 if ( empty( $args['class'] ) ) {
621 $args['class'] = 'give_datepicker';
622 } elseif ( ! strpos( $args['class'], 'give_datepicker' ) ) {
623 $args['class'] .= ' give_datepicker';
624 }
625
626 return $this->text( $args );
627 }
628
629 /**
630 * Textarea
631 *
632 * Renders an HTML textarea.
633 *
634 * @since 1.0
635 * @access public
636 *
637 * @param array $args Arguments for the textarea.
638 *
639 * @return string The textarea.
640 */
641 public function textarea( $args = array() ) {
642 $defaults = array(
643 'name' => 'textarea',
644 'value' => null,
645 'label' => null,
646 'desc' => null,
647 'class' => 'large-text',
648 'disabled' => false,
649 );
650
651 $args = wp_parse_args( $args, $defaults );
652
653 $disabled = '';
654 if ( $args['disabled'] ) {
655 $disabled = ' disabled="disabled"';
656 }
657
658 $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
659
660 $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
661
662 $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
663
664 if ( ! empty( $args['desc'] ) ) {
665 $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
666 }
667
668 $output .= '</span>';
669
670 return $output;
671 }
672
673 /**
674 * User Search Field
675 *
676 * Renders an ajax user search field.
677 *
678 * @since 1.0
679 * @access public
680 *
681 * @param array $args Arguments for the search field.
682 *
683 * @return string The text field with ajax search.
684 */
685 public function ajax_user_search( $args = array() ) {
686
687 $defaults = array(
688 'name' => 'users',
689 'id' => 'users',
690 'class' => 'give-ajax-user-search',
691 'multiple' => false,
692 'selected' => 0,
693 'chosen' => true,
694 'number' => 30,
695 'select_atts' => '',
696 'placeholder' => __( 'Select a user', 'give' ),
697 'data' => array(
698 'search-type' => 'user',
699 ),
700 );
701
702 $args = wp_parse_args( $args, $defaults );
703
704 // Set initial args.
705 $get_users_args = array(
706 'number' => $args['number'],
707 );
708
709 // Ensure selected user is not included in initial query.
710 // This is because sites with many users, it's not a guarantee the selected user will be returned.
711 if ( ! empty( $args['selected'] ) ) {
712 $get_users_args['exclude'] = $args['selected'];
713 }
714
715 // Initial users array.
716 $users = apply_filters( 'give_ajax_user_search_initial_results', get_users( $get_users_args ), $args );
717
718 // Now add the selected user to the $users array if the arg is present.
719 if ( ! empty( $args['selected'] ) ) {
720 $selected_user = apply_filters( 'give_ajax_user_search_selected_results', get_users( "include={$args['selected']}" ), $args );;
721 $users = array_merge( $users, $selected_user );
722 }
723
724 $options = array();
725
726 if ( $users ) {
727 $options[0] = $args['placeholder'];
728 foreach ( $users as $user ) {
729 $options[ absint( $user->ID ) ] = esc_html( $user->user_login . ' (' . $user->user_email . ')' );
730 }
731 } else {
732 $options[0] = __( 'No users found.', 'give' );
733 }
734
735 $output = $this->select( array(
736 'name' => $args['name'],
737 'selected' => $args['selected'],
738 'id' => $args['id'],
739 'class' => $args['class'],
740 'options' => $options,
741 'chosen' => $args['chosen'],
742 'multiple' => $args['multiple'],
743 'placeholder' => $args['placeholder'],
744 'select_atts' => $args['select_atts'],
745 'show_option_all' => false,
746 'show_option_none' => false,
747 'data' => $args['data'],
748 ) );
749
750 return $output;
751
752 }
753
754 }
755