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