PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.0.5
GiveWP – Donation Plugin and Fundraising Platform v2.0.5
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 8 years ago api 8 years ago deprecated 8 years ago donors 8 years ago emails 8 years ago forms 8 years ago gateways 8 years ago libraries 8 years ago payments 8 years ago actions.php 8 years ago ajax-functions.php 8 years ago class-give-async-process.php 8 years ago class-give-background-updater.php 8 years ago class-give-cache.php 8 years ago class-give-cli-commands.php 8 years ago class-give-cron.php 8 years ago class-give-db-donor-meta.php 8 years ago class-give-db-donors.php 8 years ago class-give-db-form-meta.php 8 years ago class-give-db-logs-meta.php 8 years ago class-give-db-logs.php 8 years ago class-give-db-meta.php 8 years ago class-give-db-payment-meta.php 8 years ago class-give-db.php 8 years ago class-give-donate-form.php 8 years ago class-give-donor.php 8 years ago class-give-email-access.php 8 years ago class-give-gravatars.php 8 years ago class-give-html-elements.php 8 years ago class-give-license-handler.php 8 years ago class-give-logging.php 8 years ago class-give-roles.php 8 years ago class-give-session.php 8 years ago class-give-stats.php 8 years ago class-give-template-loader.php 9 years ago class-give-tooltips.php 8 years ago class-give-translation.php 8 years ago class-notices.php 8 years ago country-functions.php 8 years ago currency-functions.php 8 years ago error-tracking.php 8 years ago filters.php 8 years ago formatting.php 8 years ago import-functions.php 8 years ago install.php 8 years ago login-register.php 8 years ago misc-functions.php 8 years ago plugin-compatibility.php 8 years ago post-types.php 8 years ago price-functions.php 8 years ago process-donation.php 8 years ago scripts.php 8 years ago shortcodes.php 8 years ago template-functions.php 8 years ago user-functions.php 8 years ago
class-give-html-elements.php
734 lines
1 <?php
2 /**
3 * HTML elements
4 *
5 * @package Give
6 * @subpackage Classes/Give_HTML_Elements
7 * @copyright Copyright (c) 2016, WordImpress
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 );
117
118 $args = wp_parse_args( $args, $defaults );
119
120 $form_args = array(
121 'post_type' => 'give_forms',
122 'orderby' => 'title',
123 'order' => 'ASC',
124 'posts_per_page' => $args['number'],
125 );
126
127 $cache_key = Give_Cache::get_key( 'give_forms', $form_args, false );
128
129 // Get forms from cache.
130 $forms = Give_Cache::get_db_query( $cache_key );
131
132 if ( is_null( $forms ) ) {
133 $forms = get_posts( $form_args );
134 Give_Cache::set_db_query( $cache_key, $forms );
135 }
136
137 $options = array();
138
139 // Ensure the selected.
140 if ( false !== $args['selected'] && $args['selected'] !== 0 ) {
141 $options[ $args['selected'] ] = get_the_title( $args['selected'] );
142 }
143
144 if ( $forms ) {
145 $options[0] = $args['placeholder'];
146 foreach ( $forms as $form ) {
147 $form_title = empty( $form->post_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $form->ID ) : $form->post_title;
148 $options[ absint( $form->ID ) ] = esc_html( $form_title );
149 }
150 } else {
151 $options[0] = esc_html__( 'No forms found.', 'give' );
152 }
153
154 $output = $this->select( array(
155 'name' => $args['name'],
156 'selected' => $args['selected'],
157 'id' => $args['id'],
158 'class' => $args['class'],
159 'options' => $options,
160 'chosen' => $args['chosen'],
161 'multiple' => $args['multiple'],
162 'placeholder' => $args['placeholder'],
163 'show_option_all' => false,
164 'show_option_none' => false,
165 'data' => $args['data'],
166 ) );
167
168 return $output;
169 }
170
171 /**
172 * Donors Dropdown
173 *
174 * Renders an HTML Dropdown of all donors.
175 *
176 * @since 1.0
177 * @access public
178 *
179 * @param array $args Arguments for the dropdown.
180 *
181 * @return string Donors dropdown.
182 */
183 public function donor_dropdown( $args = array() ) {
184
185 $defaults = array(
186 'name' => 'donors',
187 'id' => 'donors',
188 'class' => '',
189 'multiple' => false,
190 'selected' => 0,
191 'chosen' => true,
192 'placeholder' => esc_attr__( 'Select a Donor', 'give' ),
193 'number' => 30,
194 'data' => array(
195 'search-type' => 'donor',
196 ),
197 );
198
199 $args = wp_parse_args( $args, $defaults );
200
201 $donors = Give()->donors->get_donors( array(
202 'number' => $args['number']
203 ) );
204
205 $options = array();
206
207 if ( $donors ) {
208 $options[0] = esc_html__( 'No donor attached', 'give' );
209 foreach ( $donors as $donor ) {
210 $options[ absint( $donor->id ) ] = esc_html( $donor->name . ' (' . $donor->email . ')' );
211 }
212 } else {
213 $options[0] = esc_html__( 'No donors found.', 'give' );
214 }
215
216 if ( ! empty( $args['selected'] ) ) {
217
218 // If a selected customer has been specified, we need to ensure it's in the initial list of customers displayed.
219 if ( ! array_key_exists( $args['selected'], $options ) ) {
220
221 $donor = new Give_Donor( $args['selected'] );
222
223 if ( $donor ) {
224
225 $options[ absint( $args['selected'] ) ] = esc_html( $donor->name . ' (' . $donor->email . ')' );
226
227 }
228 }
229 }
230
231 $output = $this->select( array(
232 'name' => $args['name'],
233 'selected' => $args['selected'],
234 'id' => $args['id'],
235 'class' => $args['class'] . ' give-customer-select',
236 'options' => $options,
237 'multiple' => $args['multiple'],
238 'chosen' => $args['chosen'],
239 'show_option_all' => false,
240 'show_option_none' => false,
241 'data' => $args['data'],
242 ) );
243
244 return $output;
245 }
246
247 /**
248 * Categories Dropdown
249 *
250 * Renders an HTML Dropdown of all the Categories.
251 *
252 * @since 1.0
253 * @access public
254 *
255 * @param string $name Name attribute of the dropdown. Default is 'give_forms_categories'.
256 * @param int $selected Category to select automatically. Default is 0.
257 * @param array $args Select box options.
258 *
259 * @return string Categories dropdown.
260 */
261 public function category_dropdown( $name = 'give_forms_categories', $selected = 0, $args = array() ) {
262 $categories = get_terms( 'give_forms_category', apply_filters( 'give_forms_category_dropdown', array() ) );
263 $options = array();
264
265 foreach ( $categories as $category ) {
266 $options[ absint( $category->term_id ) ] = esc_html( $category->name );
267 }
268
269 $output = $this->select( wp_parse_args( $args, array(
270 'name' => $name,
271 'selected' => $selected,
272 'options' => $options,
273 'show_option_all' => esc_html__( 'All Categories', 'give' ),
274 'show_option_none' => false,
275 ) ) );
276
277 return $output;
278 }
279
280 /**
281 * Tags Dropdown
282 *
283 * Renders an HTML Dropdown of all the Tags.
284 *
285 * @since 1.8
286 * @access public
287 *
288 * @param string $name Name attribute of the dropdown. Default is 'give_forms_tags'.
289 * @param int $selected Tag to select automatically. Default is 0.
290 * @param array $args Select box options.
291 *
292 * @return string Tags dropdown.
293 */
294 public function tags_dropdown( $name = 'give_forms_tags', $selected = 0, $args = array() ) {
295 $tags = get_terms( 'give_forms_tag', apply_filters( 'give_forms_tag_dropdown', array() ) );
296 $options = array();
297
298 foreach ( $tags as $tag ) {
299 $options[ absint( $tag->term_id ) ] = esc_html( $tag->name );
300 }
301
302 $output = $this->select( wp_parse_args( $args, array(
303 'name' => $name,
304 'selected' => $selected,
305 'options' => $options,
306 'show_option_all' => esc_html__( 'All Tags', 'give' ),
307 'show_option_none' => false,
308 ) ) );
309
310 return $output;
311 }
312
313 /**
314 * Years Dropdown
315 *
316 * Renders an HTML Dropdown of years.
317 *
318 * @since 1.0
319 * @access public
320 *
321 * @param string $name Name attribute of the dropdown. Default is 'year'.
322 * @param int $selected Year to select automatically. Default is 0.
323 * @param int $years_before Number of years before the current year the dropdown should start with. Default is 5.
324 * @param int $years_after Number of years after the current year the dropdown should finish at. Default is 0.
325 *
326 * @return string Years dropdown.
327 */
328 public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
329 $current = date( 'Y' );
330 $start_year = $current - absint( $years_before );
331 $end_year = $current + absint( $years_after );
332 $selected = empty( $selected ) ? date( 'Y' ) : $selected;
333 $options = array();
334
335 while ( $start_year <= $end_year ) {
336 $options[ absint( $start_year ) ] = $start_year;
337 $start_year ++;
338 }
339
340 $output = $this->select( array(
341 'name' => $name,
342 'selected' => $selected,
343 'options' => $options,
344 'show_option_all' => false,
345 'show_option_none' => false,
346 ) );
347
348 return $output;
349 }
350
351 /**
352 * Months Dropdown
353 *
354 * Renders an HTML Dropdown of months.
355 *
356 * @since 1.0
357 * @access public
358 *
359 * @param string $name Name attribute of the dropdown. Default is 'month'.
360 * @param int $selected Month to select automatically. Default is 0.
361 *
362 * @return string Months dropdown.
363 */
364 public function month_dropdown( $name = 'month', $selected = 0 ) {
365 $month = 1;
366 $options = array();
367 $selected = empty( $selected ) ? date( 'n' ) : $selected;
368
369 while ( $month <= 12 ) {
370 $options[ absint( $month ) ] = give_month_num_to_name( $month );
371 $month ++;
372 }
373
374 $output = $this->select( array(
375 'name' => $name,
376 'selected' => $selected,
377 'options' => $options,
378 'show_option_all' => false,
379 'show_option_none' => false,
380 ) );
381
382 return $output;
383 }
384
385 /**
386 * Dropdown
387 *
388 * Renders an HTML Dropdown.
389 *
390 * @since 1.0
391 * @access public
392 *
393 * @param array $args Arguments for the dropdown.
394 *
395 * @return string The dropdown.
396 */
397 public function select( $args = array() ) {
398 $defaults = array(
399 'options' => array(),
400 'name' => null,
401 'class' => '',
402 'id' => '',
403 'selected' => 0,
404 'chosen' => false,
405 'placeholder' => null,
406 'multiple' => false,
407 'select_atts' => false,
408 'show_option_all' => __( 'All', 'give' ),
409 'show_option_none' => __( 'None', 'give' ),
410 'data' => array(),
411 'readonly' => false,
412 'disabled' => false,
413 );
414
415 $args = wp_parse_args( $args, $defaults );
416
417 $data_elements = '';
418 foreach ( $args['data'] as $key => $value ) {
419 $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
420 }
421
422 $multiple = '';
423 if ( $args['multiple'] ) {
424 $multiple = 'MULTIPLE';
425 }
426
427 if ( $args['chosen'] ) {
428 $args['class'] .= ' give-select-chosen';
429 }
430
431 $placeholder = '';
432 if ( $args['placeholder'] ) {
433 $placeholder = $args['placeholder'];
434 }
435
436 $output = sprintf(
437 '<select name="%1$s" id="%2$s" class="give-select %3$s" %4$s %5$s placeholder="%6$s" data-placeholder="%6$s" %7$s>',
438 esc_attr( $args['name'] ),
439 esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ),
440 esc_attr( $args['class'] ),
441 $multiple,
442 $args['select_atts'],
443 $placeholder,
444 $data_elements
445 );
446
447 if ( $args['show_option_all'] ) {
448 if ( $args['multiple'] ) {
449 $selected = selected( true, in_array( 0, $args['selected'] ), false );
450 } else {
451 $selected = selected( $args['selected'], 0, false );
452 }
453 $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
454 }
455
456 if ( ! empty( $args['options'] ) ) {
457
458 if ( $args['show_option_none'] ) {
459 if ( $args['multiple'] ) {
460 $selected = selected( true, in_array( - 1, $args['selected'] ), false );
461 } else {
462 $selected = selected( $args['selected'], - 1, false );
463 }
464 $output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
465 }
466
467 foreach ( $args['options'] as $key => $option ) {
468
469 if ( $args['multiple'] && is_array( $args['selected'] ) ) {
470 $selected = selected( true, in_array( $key, $args['selected'] ), false );
471 } else {
472 $selected = selected( $args['selected'], $key, false );
473 }
474
475 $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
476 }
477 }
478
479 $output .= '</select>';
480
481 return $output;
482 }
483
484 /**
485 * Checkbox
486 *
487 * Renders an HTML Checkbox.
488 *
489 * @since 1.0
490 * @access public
491 *
492 * @param array $args Arguments for the Checkbox.
493 *
494 * @return string The checkbox.
495 */
496 public function checkbox( $args = array() ) {
497 $defaults = array(
498 'name' => null,
499 'current' => null,
500 'class' => 'give-checkbox',
501 'options' => array(
502 'disabled' => false,
503 'readonly' => false,
504 ),
505 );
506
507 $args = wp_parse_args( $args, $defaults );
508
509 $options = '';
510 if ( ! empty( $args['options']['disabled'] ) ) {
511 $options .= ' disabled="disabled"';
512 } elseif ( ! empty( $args['options']['readonly'] ) ) {
513 $options .= ' readonly';
514 }
515
516 $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 ) . ' />';
517
518 return $output;
519 }
520
521 /**
522 * Text Field
523 *
524 * Renders an HTML Text field.
525 *
526 * @since 1.0
527 * @access public
528 *
529 * @param array $args Arguments for the text field.
530 *
531 * @return string The text field.
532 */
533 public function text( $args = array() ) {
534 // Backwards compatibility.
535 if ( func_num_args() > 1 ) {
536 $args = func_get_args();
537
538 $name = $args[0];
539 $value = isset( $args[1] ) ? $args[1] : '';
540 $label = isset( $args[2] ) ? $args[2] : '';
541 $desc = isset( $args[3] ) ? $args[3] : '';
542 }
543
544 $defaults = array(
545 'name' => isset( $name ) ? $name : 'text',
546 'value' => isset( $value ) ? $value : null,
547 'label' => isset( $label ) ? $label : null,
548 'desc' => isset( $desc ) ? $desc : null,
549 'placeholder' => '',
550 'class' => 'regular-text',
551 'disabled' => false,
552 'autocomplete' => '',
553 'data' => false,
554 );
555
556 $args = wp_parse_args( $args, $defaults );
557
558 $disabled = '';
559 if ( $args['disabled'] ) {
560 $disabled = ' disabled="disabled"';
561 }
562
563 $data = '';
564 if ( ! empty( $args['data'] ) ) {
565 foreach ( $args['data'] as $key => $value ) {
566 $data .= 'data-' . $key . '="' . $value . '" ';
567 }
568 }
569
570 $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
571
572 $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
573
574 if ( ! empty( $args['desc'] ) ) {
575 $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
576 }
577
578 $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 . '/>';
579
580 $output .= '</span>';
581
582 return $output;
583 }
584
585 /**
586 * Date Picker
587 *
588 * Renders a date picker field.
589 *
590 * @since 1.5
591 * @access public
592 *
593 * @param array $args Arguments for the date picker.
594 *
595 * @return string The date picker.
596 */
597 public function date_field( $args = array() ) {
598
599 if ( empty( $args['class'] ) ) {
600 $args['class'] = 'give_datepicker';
601 } elseif ( ! strpos( $args['class'], 'give_datepicker' ) ) {
602 $args['class'] .= ' give_datepicker';
603 }
604
605 return $this->text( $args );
606 }
607
608 /**
609 * Textarea
610 *
611 * Renders an HTML textarea.
612 *
613 * @since 1.0
614 * @access public
615 *
616 * @param array $args Arguments for the textarea.
617 *
618 * @return string The textarea.
619 */
620 public function textarea( $args = array() ) {
621 $defaults = array(
622 'name' => 'textarea',
623 'value' => null,
624 'label' => null,
625 'desc' => null,
626 'class' => 'large-text',
627 'disabled' => false,
628 );
629
630 $args = wp_parse_args( $args, $defaults );
631
632 $disabled = '';
633 if ( $args['disabled'] ) {
634 $disabled = ' disabled="disabled"';
635 }
636
637 $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
638
639 $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
640
641 $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
642
643 if ( ! empty( $args['desc'] ) ) {
644 $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
645 }
646
647 $output .= '</span>';
648
649 return $output;
650 }
651
652 /**
653 * User Search Field
654 *
655 * Renders an ajax user search field.
656 *
657 * @since 1.0
658 * @access public
659 *
660 * @param array $args Arguments for the search field.
661 *
662 * @return string The text field with ajax search.
663 */
664 public function ajax_user_search( $args = array() ) {
665
666 $defaults = array(
667 'name' => 'users',
668 'id' => 'users',
669 'class' => 'give-ajax-user-search',
670 'multiple' => false,
671 'selected' => 0,
672 'chosen' => true,
673 'number' => 30,
674 'select_atts' => '',
675 'placeholder' => __( 'Select a user', 'give' ),
676 'data' => array(
677 'search-type' => 'user',
678 ),
679 );
680
681 $args = wp_parse_args( $args, $defaults );
682
683 // Set initial args.
684 $get_users_args = array(
685 'number' => $args['number'],
686 );
687
688 // Ensure selected user is not included in initial query.
689 // This is because sites with many users, it's not a guarantee the selected user will be returned.
690 if ( ! empty( $args['selected'] ) ) {
691 $get_users_args['exclude'] = $args['selected'];
692 }
693
694 // Initial users array.
695 $users = apply_filters( 'give_ajax_user_search_initial_results', get_users( $get_users_args ), $args );
696
697 // Now add the selected user to the $users array if the arg is present.
698 if ( ! empty( $args['selected'] ) ) {
699 $selected_user = apply_filters( 'give_ajax_user_search_selected_results', get_users( "include={$args['selected']}" ), $args );;
700 $users = array_merge( $users, $selected_user );
701 }
702
703 $options = array();
704
705 if ( $users ) {
706 $options[0] = $args['placeholder'];
707 foreach ( $users as $user ) {
708 $options[ absint( $user->ID ) ] = esc_html( $user->user_login . ' (' . $user->user_email . ')' );
709 }
710 } else {
711 $options[0] = __( 'No users found.', 'give' );
712 }
713
714 $output = $this->select( array(
715 'name' => $args['name'],
716 'selected' => $args['selected'],
717 'id' => $args['id'],
718 'class' => $args['class'],
719 'options' => $options,
720 'chosen' => $args['chosen'],
721 'multiple' => $args['multiple'],
722 'placeholder' => $args['placeholder'],
723 'select_atts' => $args['select_atts'],
724 'show_option_all' => false,
725 'show_option_none' => false,
726 'data' => $args['data'],
727 ) );
728
729 return $output;
730
731 }
732
733 }
734