PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.0
GiveWP – Donation Plugin and Fundraising Platform v2.1.0
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-sequential-ordering.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-scripts.php 8 years ago class-give-session.php 8 years ago class-give-stats.php 8 years ago class-give-template-loader.php 8 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 shortcodes.php 8 years ago template-functions.php 8 years ago user-functions.php 8 years ago
class-give-html-elements.php
736 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
264 $options = array();
265
266 foreach ( $categories as $category ) {
267 $options[ absint( $category->term_id ) ] = esc_html( $category->name );
268 }
269
270 $output = $this->select( wp_parse_args( $args, array(
271 'name' => $name,
272 'selected' => $selected,
273 'options' => $options,
274 'show_option_all' => esc_html__( 'All Categories', 'give' ),
275 'show_option_none' => false,
276 ) ) );
277
278 return $output;
279 }
280
281 /**
282 * Tags Dropdown
283 *
284 * Renders an HTML Dropdown of all the Tags.
285 *
286 * @since 1.8
287 * @access public
288 *
289 * @param string $name Name attribute of the dropdown. Default is 'give_forms_tags'.
290 * @param int $selected Tag to select automatically. Default is 0.
291 * @param array $args Select box options.
292 *
293 * @return string Tags dropdown.
294 */
295 public function tags_dropdown( $name = 'give_forms_tags', $selected = 0, $args = array() ) {
296 $tags = get_terms( 'give_forms_tag', apply_filters( 'give_forms_tag_dropdown', array() ) );
297
298 $options = array();
299
300 foreach ( $tags as $tag ) {
301 $options[ absint( $tag->term_id ) ] = esc_html( $tag->name );
302 }
303
304 $output = $this->select( wp_parse_args( $args, array(
305 'name' => $name,
306 'selected' => $selected,
307 'options' => $options,
308 'show_option_all' => esc_html__( 'All Tags', 'give' ),
309 'show_option_none' => false,
310 ) ) );
311
312 return $output;
313 }
314
315 /**
316 * Years Dropdown
317 *
318 * Renders an HTML Dropdown of years.
319 *
320 * @since 1.0
321 * @access public
322 *
323 * @param string $name Name attribute of the dropdown. Default is 'year'.
324 * @param int $selected Year to select automatically. Default is 0.
325 * @param int $years_before Number of years before the current year the dropdown should start with. Default is 5.
326 * @param int $years_after Number of years after the current year the dropdown should finish at. Default is 0.
327 *
328 * @return string Years dropdown.
329 */
330 public function year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
331 $current = date( 'Y' );
332 $start_year = $current - absint( $years_before );
333 $end_year = $current + absint( $years_after );
334 $selected = empty( $selected ) ? date( 'Y' ) : $selected;
335 $options = array();
336
337 while ( $start_year <= $end_year ) {
338 $options[ absint( $start_year ) ] = $start_year;
339 $start_year ++;
340 }
341
342 $output = $this->select( array(
343 'name' => $name,
344 'selected' => $selected,
345 'options' => $options,
346 'show_option_all' => false,
347 'show_option_none' => false,
348 ) );
349
350 return $output;
351 }
352
353 /**
354 * Months Dropdown
355 *
356 * Renders an HTML Dropdown of months.
357 *
358 * @since 1.0
359 * @access public
360 *
361 * @param string $name Name attribute of the dropdown. Default is 'month'.
362 * @param int $selected Month to select automatically. Default is 0.
363 *
364 * @return string Months dropdown.
365 */
366 public function month_dropdown( $name = 'month', $selected = 0 ) {
367 $month = 1;
368 $options = array();
369 $selected = empty( $selected ) ? date( 'n' ) : $selected;
370
371 while ( $month <= 12 ) {
372 $options[ absint( $month ) ] = give_month_num_to_name( $month );
373 $month ++;
374 }
375
376 $output = $this->select( array(
377 'name' => $name,
378 'selected' => $selected,
379 'options' => $options,
380 'show_option_all' => false,
381 'show_option_none' => false,
382 ) );
383
384 return $output;
385 }
386
387 /**
388 * Dropdown
389 *
390 * Renders an HTML Dropdown.
391 *
392 * @since 1.0
393 * @access public
394 *
395 * @param array $args Arguments for the dropdown.
396 *
397 * @return string The dropdown.
398 */
399 public function select( $args = array() ) {
400 $defaults = array(
401 'options' => array(),
402 'name' => null,
403 'class' => '',
404 'id' => '',
405 'selected' => 0,
406 'chosen' => false,
407 'placeholder' => null,
408 'multiple' => false,
409 'select_atts' => false,
410 'show_option_all' => __( 'All', 'give' ),
411 'show_option_none' => __( 'None', 'give' ),
412 'data' => array(),
413 'readonly' => false,
414 'disabled' => false,
415 );
416
417 $args = wp_parse_args( $args, $defaults );
418
419 $data_elements = '';
420 foreach ( $args['data'] as $key => $value ) {
421 $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
422 }
423
424 $multiple = '';
425 if ( $args['multiple'] ) {
426 $multiple = 'MULTIPLE';
427 }
428
429 if ( $args['chosen'] ) {
430 $args['class'] .= ' give-select-chosen';
431 }
432
433 $placeholder = '';
434 if ( $args['placeholder'] ) {
435 $placeholder = $args['placeholder'];
436 }
437
438 $output = sprintf(
439 '<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>',
440 esc_attr( $args['name'] ),
441 esc_attr( sanitize_key( str_replace( '-', '_', $args['id'] ) ) ),
442 esc_attr( $args['class'] ),
443 $multiple,
444 $args['select_atts'],
445 $placeholder,
446 $data_elements
447 );
448
449 if ( $args['show_option_all'] ) {
450 if ( $args['multiple'] ) {
451 $selected = selected( true, in_array( 0, $args['selected'] ), false );
452 } else {
453 $selected = selected( $args['selected'], 0, false );
454 }
455 $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
456 }
457
458 if ( ! empty( $args['options'] ) ) {
459
460 if ( $args['show_option_none'] ) {
461 if ( $args['multiple'] ) {
462 $selected = selected( true, in_array( - 1, $args['selected'] ), false );
463 } else {
464 $selected = selected( $args['selected'], - 1, false );
465 }
466 $output .= '<option value="-1"' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
467 }
468
469 foreach ( $args['options'] as $key => $option ) {
470
471 if ( $args['multiple'] && is_array( $args['selected'] ) ) {
472 $selected = selected( true, in_array( $key, $args['selected'] ), false );
473 } else {
474 $selected = selected( $args['selected'], $key, false );
475 }
476
477 $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
478 }
479 }
480
481 $output .= '</select>';
482
483 return $output;
484 }
485
486 /**
487 * Checkbox
488 *
489 * Renders an HTML Checkbox.
490 *
491 * @since 1.0
492 * @access public
493 *
494 * @param array $args Arguments for the Checkbox.
495 *
496 * @return string The checkbox.
497 */
498 public function checkbox( $args = array() ) {
499 $defaults = array(
500 'name' => null,
501 'current' => null,
502 'class' => 'give-checkbox',
503 'options' => array(
504 'disabled' => false,
505 'readonly' => false,
506 ),
507 );
508
509 $args = wp_parse_args( $args, $defaults );
510
511 $options = '';
512 if ( ! empty( $args['options']['disabled'] ) ) {
513 $options .= ' disabled="disabled"';
514 } elseif ( ! empty( $args['options']['readonly'] ) ) {
515 $options .= ' readonly';
516 }
517
518 $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 ) . ' />';
519
520 return $output;
521 }
522
523 /**
524 * Text Field
525 *
526 * Renders an HTML Text field.
527 *
528 * @since 1.0
529 * @access public
530 *
531 * @param array $args Arguments for the text field.
532 *
533 * @return string The text field.
534 */
535 public function text( $args = array() ) {
536 // Backwards compatibility.
537 if ( func_num_args() > 1 ) {
538 $args = func_get_args();
539
540 $name = $args[0];
541 $value = isset( $args[1] ) ? $args[1] : '';
542 $label = isset( $args[2] ) ? $args[2] : '';
543 $desc = isset( $args[3] ) ? $args[3] : '';
544 }
545
546 $defaults = array(
547 'name' => isset( $name ) ? $name : 'text',
548 'value' => isset( $value ) ? $value : null,
549 'label' => isset( $label ) ? $label : null,
550 'desc' => isset( $desc ) ? $desc : null,
551 'placeholder' => '',
552 'class' => 'regular-text',
553 'disabled' => false,
554 'autocomplete' => '',
555 'data' => false,
556 );
557
558 $args = wp_parse_args( $args, $defaults );
559
560 $disabled = '';
561 if ( $args['disabled'] ) {
562 $disabled = ' disabled="disabled"';
563 }
564
565 $data = '';
566 if ( ! empty( $args['data'] ) ) {
567 foreach ( $args['data'] as $key => $value ) {
568 $data .= 'data-' . $key . '="' . $value . '" ';
569 }
570 }
571
572 $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
573
574 $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
575
576 if ( ! empty( $args['desc'] ) ) {
577 $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
578 }
579
580 $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 . '/>';
581
582 $output .= '</span>';
583
584 return $output;
585 }
586
587 /**
588 * Date Picker
589 *
590 * Renders a date picker field.
591 *
592 * @since 1.5
593 * @access public
594 *
595 * @param array $args Arguments for the date picker.
596 *
597 * @return string The date picker.
598 */
599 public function date_field( $args = array() ) {
600
601 if ( empty( $args['class'] ) ) {
602 $args['class'] = 'give_datepicker';
603 } elseif ( ! strpos( $args['class'], 'give_datepicker' ) ) {
604 $args['class'] .= ' give_datepicker';
605 }
606
607 return $this->text( $args );
608 }
609
610 /**
611 * Textarea
612 *
613 * Renders an HTML textarea.
614 *
615 * @since 1.0
616 * @access public
617 *
618 * @param array $args Arguments for the textarea.
619 *
620 * @return string The textarea.
621 */
622 public function textarea( $args = array() ) {
623 $defaults = array(
624 'name' => 'textarea',
625 'value' => null,
626 'label' => null,
627 'desc' => null,
628 'class' => 'large-text',
629 'disabled' => false,
630 );
631
632 $args = wp_parse_args( $args, $defaults );
633
634 $disabled = '';
635 if ( $args['disabled'] ) {
636 $disabled = ' disabled="disabled"';
637 }
638
639 $output = '<span id="give-' . sanitize_key( $args['name'] ) . '-wrap">';
640
641 $output .= '<label class="give-label" for="give-' . sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
642
643 $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $args['class'] . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
644
645 if ( ! empty( $args['desc'] ) ) {
646 $output .= '<span class="give-description">' . esc_html( $args['desc'] ) . '</span>';
647 }
648
649 $output .= '</span>';
650
651 return $output;
652 }
653
654 /**
655 * User Search Field
656 *
657 * Renders an ajax user search field.
658 *
659 * @since 1.0
660 * @access public
661 *
662 * @param array $args Arguments for the search field.
663 *
664 * @return string The text field with ajax search.
665 */
666 public function ajax_user_search( $args = array() ) {
667
668 $defaults = array(
669 'name' => 'users',
670 'id' => 'users',
671 'class' => 'give-ajax-user-search',
672 'multiple' => false,
673 'selected' => 0,
674 'chosen' => true,
675 'number' => 30,
676 'select_atts' => '',
677 'placeholder' => __( 'Select a user', 'give' ),
678 'data' => array(
679 'search-type' => 'user',
680 ),
681 );
682
683 $args = wp_parse_args( $args, $defaults );
684
685 // Set initial args.
686 $get_users_args = array(
687 'number' => $args['number'],
688 );
689
690 // Ensure selected user is not included in initial query.
691 // This is because sites with many users, it's not a guarantee the selected user will be returned.
692 if ( ! empty( $args['selected'] ) ) {
693 $get_users_args['exclude'] = $args['selected'];
694 }
695
696 // Initial users array.
697 $users = apply_filters( 'give_ajax_user_search_initial_results', get_users( $get_users_args ), $args );
698
699 // Now add the selected user to the $users array if the arg is present.
700 if ( ! empty( $args['selected'] ) ) {
701 $selected_user = apply_filters( 'give_ajax_user_search_selected_results', get_users( "include={$args['selected']}" ), $args );;
702 $users = array_merge( $users, $selected_user );
703 }
704
705 $options = array();
706
707 if ( $users ) {
708 $options[0] = $args['placeholder'];
709 foreach ( $users as $user ) {
710 $options[ absint( $user->ID ) ] = esc_html( $user->user_login . ' (' . $user->user_email . ')' );
711 }
712 } else {
713 $options[0] = __( 'No users found.', 'give' );
714 }
715
716 $output = $this->select( array(
717 'name' => $args['name'],
718 'selected' => $args['selected'],
719 'id' => $args['id'],
720 'class' => $args['class'],
721 'options' => $options,
722 'chosen' => $args['chosen'],
723 'multiple' => $args['multiple'],
724 'placeholder' => $args['placeholder'],
725 'select_atts' => $args['select_atts'],
726 'show_option_all' => false,
727 'show_option_none' => false,
728 'data' => $args['data'],
729 ) );
730
731 return $output;
732
733 }
734
735 }
736