PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.13.3
GiveWP – Donation Plugin and Fundraising Platform v2.13.3
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 / admin / give-metabox-functions.php
give / includes / admin Last commit date
add-ons 5 years ago donors 5 years ago emails 6 years ago forms 4 years ago payments 4 years ago reports 5 years ago settings 4 years ago shortcodes 5 years ago tools 5 years ago upgrades 5 years ago views 6 years ago abstract-admin-settings-page.php 6 years ago admin-actions.php 5 years ago admin-filters.php 6 years ago admin-footer.php 5 years ago admin-pages.php 5 years ago class-addon-activation-banner.php 6 years ago class-admin-settings.php 5 years ago class-api-keys-table.php 6 years ago class-blank-slate.php 6 years ago class-give-admin.php 5 years ago class-give-html-elements.php 6 years ago class-i18n-module.php 6 years ago dashboard-widgets.php 6 years ago give-metabox-functions.php 5 years ago import-functions.php 5 years ago misc-functions.php 5 years ago plugins.php 5 years ago setting-page-functions.php 6 years ago
give-metabox-functions.php
1752 lines
1 <?php
2 /**
3 * Give Meta Box Functions
4 *
5 * @package Give
6 * @subpackage Functions
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8
10 */
11 if ( ! defined( 'ABSPATH' ) ) {
12 exit; // Exit if accessed directly
13 }
14
15
16 /**
17 * Check if field callback exist or not.
18 *
19 * @since 1.8
20 *
21 * @param $field
22 *
23 * @return bool|string
24 */
25 function give_is_field_callback_exist( $field ) {
26 return ( give_get_field_callback( $field ) ? true : false );
27 }
28
29 /**
30 * Get field callback.
31 *
32 * @since 1.8
33 *
34 * @param $field
35 *
36 * @return bool|string
37 */
38 function give_get_field_callback( $field ) {
39 $func_name_prefix = 'give';
40 $func_name = '';
41
42 // Set callback function on basis of cmb2 field name.
43 switch ( $field['type'] ) {
44 case 'radio_inline':
45 $func_name = "{$func_name_prefix}_radio";
46 break;
47
48 case 'text':
49 case 'text-medium':
50 case 'text_medium':
51 case 'text-small':
52 case 'text_small':
53 case 'number':
54 case 'email':
55 $func_name = "{$func_name_prefix}_text_input";
56 break;
57
58 case 'textarea':
59 $func_name = "{$func_name_prefix}_textarea_input";
60 break;
61
62 case 'colorpicker':
63 $func_name = "{$func_name_prefix}_{$field['type']}";
64 break;
65
66 case 'hidden':
67 case 'levels_id':
68 $func_name = "{$func_name_prefix}_hidden_input";
69 break;
70
71 case 'group':
72 $func_name = "_{$func_name_prefix}_metabox_form_data_repeater_fields";
73 break;
74
75 case 'give_default_radio_inline':
76 $func_name = "{$func_name_prefix}_radio";
77 break;
78
79 case 'donation_limit':
80 $func_name = "{$func_name_prefix}_donation_limit";
81 break;
82
83 case 'chosen':
84 $func_name = "{$func_name_prefix}_chosen_input";
85 break;
86
87 case 'label':
88 $func_name = "{$func_name_prefix}_label_field";
89 break;
90
91 default:
92 if (
93 array_key_exists( 'callback', $field )
94 && ! empty( $field['callback'] )
95 ) {
96 $func_name = $field['callback'];
97 } else {
98 $func_name = "{$func_name_prefix}_{$field['type']}";
99 }
100 }
101
102 /**
103 * Filter the metabox setting render function
104 *
105 * @since 1.8
106 */
107 $func_name = apply_filters( 'give_get_field_callback', $func_name, $field );
108
109 // Exit if not any function exist.
110 // Check if render callback exist or not.
111 if ( empty( $func_name ) ) {
112 return false;
113 } elseif ( is_string( $func_name ) && ! function_exists( "$func_name" ) ) {
114 return false;
115 } elseif ( is_array( $func_name ) && ! method_exists( $func_name[0], "$func_name[1]" ) ) {
116 return false;
117 }
118
119 return $func_name;
120 }
121
122 /**
123 * This function adds backward compatibility to render cmb2 type field type.
124 *
125 * @since 1.8
126 *
127 * @param array $field Field argument array.
128 *
129 * @return bool
130 */
131 function give_render_field( $field ) {
132
133 // Check if render callback exist or not.
134 if ( ! ( $func_name = give_get_field_callback( $field ) ) ) {
135 return false;
136 }
137
138 // CMB2 compatibility: Push all classes to attributes's class key
139 if ( empty( $field['class'] ) ) {
140 $field['class'] = '';
141 }
142
143 if ( empty( $field['attributes']['class'] ) ) {
144 $field['attributes']['class'] = '';
145 }
146
147 $field['attributes']['class'] = trim( "give-field {$field['attributes']['class']} give-{$field['type']} {$field['class']}" );
148 unset( $field['class'] );
149
150 // CMB2 compatibility: Set wrapper class if any.
151 if ( ! empty( $field['row_classes'] ) ) {
152 $field['wrapper_class'] = $field['row_classes'];
153 unset( $field['row_classes'] );
154 }
155
156 // Set field params on basis of cmb2 field name.
157 switch ( $field['type'] ) {
158 case 'radio_inline':
159 if ( empty( $field['wrapper_class'] ) ) {
160 $field['wrapper_class'] = '';
161 }
162 $field['wrapper_class'] .= ' give-inline-radio-fields';
163
164 break;
165
166 case 'text':
167 case 'text-medium':
168 case 'text_medium':
169 case 'text-small':
170 case 'text_small':
171 // CMB2 compatibility: Set field type to text.
172 $field['type'] = isset( $field['attributes']['type'] ) ? $field['attributes']['type'] : 'text';
173
174 // CMB2 compatibility: Set data type to price.
175 if (
176 empty( $field['data_type'] )
177 && ! empty( $field['attributes']['class'] )
178 && (
179 false !== strpos( $field['attributes']['class'], 'money' )
180 || false !== strpos( $field['attributes']['class'], 'amount' )
181 )
182 ) {
183 $field['data_type'] = 'decimal';
184 }
185 break;
186
187 case 'levels_id':
188 $field['type'] = 'hidden';
189 break;
190
191 case 'colorpicker':
192 $field['type'] = 'text';
193 $field['class'] = 'give-colorpicker';
194 break;
195
196 case 'give_default_radio_inline':
197 $field['type'] = 'radio';
198 $field['options'] = [
199 'default' => __( 'Default', 'give' ),
200 ];
201 break;
202
203 case 'donation_limit':
204 $field['type'] = 'donation_limit';
205 break;
206 } // End switch().
207
208 // CMB2 compatibility: Add support to define field description by desc & description param.
209 // We encourage you to use description param.
210 $field['description'] = ( ! empty( $field['description'] )
211 ? $field['description']
212 : ( ! empty( $field['desc'] ) ? $field['desc'] : '' ) );
213
214 // Call render function.
215 if ( is_array( $func_name ) ) {
216 $func_name[0]->{$func_name[1]}( $field );
217 } else {
218 $func_name( $field );
219 }
220
221 return true;
222 }
223
224 /**
225 * Output a text input box.
226 *
227 * @since 1.8
228 *
229 * @param array $field {
230 * Optional. Array of text input field arguments.
231 *
232 * @type string $id Field ID. Default ''.
233 * @type string $style CSS style for input field. Default ''.
234 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
235 * @type string $value Value of input field. Default ''.
236 * @type string $name Name of input field. Default ''.
237 * @type string $type Type of input field. Default 'text'.
238 * @type string $before_field Text/HTML to add before input field. Default ''.
239 * @type string $after_field Text/HTML to add after input field. Default ''.
240 * @type string $data_type Define data type for value of input to filter it properly. Default ''.
241 * @type string $description Description of input field. Default ''.
242 * @type array $attributes List of attributes of input field. Default array().
243 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
244 * => '****' )
245 * }
246 * @return void
247 */
248 function give_text_input( $field ) {
249 global $thepostid, $post;
250
251 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
252 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
253 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
254 $field['value'] = give_get_field_value( $field, $thepostid );
255 $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text';
256 $field['before_field'] = '';
257 $field['after_field'] = '';
258 $data_type = empty( $field['data_type'] ) ? '' : $field['data_type'];
259
260 switch ( $data_type ) {
261 case 'price':
262 $field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( give_maybe_sanitize_amount( $field['value'] ), false, false ) : $field['value'] );
263
264 $field['before_field'] = ! empty( $field['before_field'] ) ? $field['before_field'] : ( give_get_option( 'currency_position', 'before' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '' );
265 $field['after_field'] = ! empty( $field['after_field'] ) ? $field['after_field'] : ( give_get_option( 'currency_position', 'before' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '' );
266 break;
267
268 case 'decimal':
269 $field['attributes']['class'] .= ' give_input_decimal';
270 $field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( give_maybe_sanitize_amount( $field['value'] ), false, false ) : $field['value'] );
271 break;
272
273 default:
274 break;
275 }
276
277 ?>
278 <p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
279 <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
280 <?php echo $field['before_field']; ?>
281 <input
282 type="<?php echo esc_attr( $field['type'] ); ?>"
283 style="<?php echo esc_attr( $field['style'] ); ?>"
284 name="<?php echo give_get_field_name( $field ); ?>"
285 id="<?php echo esc_attr( $field['id'] ); ?>"
286 value="<?php echo esc_attr( $field['value'] ); ?>"
287 <?php echo give_get_attribute_str( $field ); ?>
288 />
289 <?php echo $field['after_field']; ?>
290 <?php
291 echo give_get_field_description( $field );
292 echo '</p>';
293 }
294
295 /**
296 * Output a chosen input box.
297 * Note: only for internal use.
298 *
299 * @param array $field {
300 * Optional. Array of text input field arguments.
301 *
302 * @type string $id Field ID. Default ''.
303 * @type string $style CSS style for input field. Default ''.
304 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
305 * @type string $value Value of input field. Default ''.
306 * @type string $name Name of input field. Default ''.
307 * @type string $type Type of input field. Default 'text'.
308 * @type string $before_field Text/HTML to add before input field. Default ''.
309 * @type string $after_field Text/HTML to add after input field. Default ''.
310 * @type string $data_type Define data type for value of input to filter it properly. Default ''.
311 * @type string $description Description of input field. Default ''.
312 * @type array $attributes List of attributes of input field. Default array().
313 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
314 * => '****' )
315 * }
316 *
317 * @since 2.1
318 *
319 * @return void
320 */
321 function give_chosen_input( $field ) {
322 global $thepostid, $post;
323
324 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
325 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
326 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
327 $field['before_field'] = '';
328 $field['after_field'] = '';
329 $placeholder = isset( $field['placeholder'] ) ? 'data-placeholder="' . $field['placeholder'] . '"' : '';
330 $data_type = ! empty( $field['data_type'] ) ? $field['data_type'] : '';
331 $type = '';
332 $field['value'] = array_filter( (array) give_get_field_value( $field, $thepostid ) );
333 $choices = $field['options'];
334 $fieldName = esc_attr( give_get_field_name( $field ) );
335 $allow_new_values = ! empty( $field['allow-custom-values'] ) && (bool) $field['allow-custom-values'] ? 'data-allows-new-values="true"' : '';
336
337 // Set attributes based on multiselect datatype.
338 if ( 'multiselect' === $data_type ) {
339 $type = 'multiple';
340 $field['value'] = empty( $field['value'] ) ? [] : $field['value'];
341 $fieldName .= '[]';
342 }
343
344 if ( $allow_new_values && $field['value'] ) {
345 $choices = array_merge( array_combine( $field['value'], $field['value'] ), $choices );
346 }
347 ?>
348 <p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
349 <label for="<?php echo esc_attr( give_get_field_name( $field ) ); ?>">
350 <?php echo wp_kses_post( $field['name'] ); ?>
351 </label>
352 <?php echo esc_attr( $field['before_field'] ); ?>
353 <select
354 class="give-select-chosen give-chosen-settings"
355 style="<?php echo esc_attr( $field['style'] ); ?>"
356 name="<?php echo $fieldName; ?>"
357 id="<?php echo esc_attr( $field['id'] ); ?>"
358 <?php echo "{$type} {$allow_new_values} {$placeholder}"; ?>
359 >
360 <?php
361 foreach ( $choices as $key => $name ) {
362 echo sprintf(
363 '<option %1$s value="%2$s">%3$s</option>',
364 in_array( $key, $field['value'] ) ? 'selected="selected"' : '',
365 esc_attr( $key ),
366 $name
367 );
368 }
369 ?>
370 </select>
371 <?php echo esc_attr( $field['after_field'] ); ?>
372 <?php echo give_get_field_description( $field ); ?>
373 </p>
374 <?php
375 }
376
377 /**
378 * Output a label field
379 * Note: only for internal use.
380 *
381 * @param array $field {
382 * Optional. Array of text input field arguments.
383 *
384 * @type string $id Field ID. Default ''.
385 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
386 * @type string $value Value of input field. Default ''.
387 * @type string $title Text to display. HTML supported Default ''.
388 * @type string $before_field Text/HTML to add before input field. Default ''.
389 * @type string $after_field Text/HTML to add after input field. Default ''.
390 * }
391 *
392 * @since 2.7.0
393 *
394 * @return void
395 */
396 function give_label_field( $field ) {
397 global $thepostid, $post;
398
399 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
400 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
401 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
402 $field['before_field'] = '';
403 $field['after_field'] = '';
404 ?>
405 <p class=" <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
406 <?php echo esc_attr( $field['before_field'] ); ?>
407 <?php echo $field['title']; ?>
408 <?php echo esc_attr( $field['after_field'] ); ?>
409 <?php echo give_get_field_description( $field ); ?>
410 </p>
411 <?php
412 }
413
414 /**
415 * Give range slider field.
416 * Note: only for internal logic
417 *
418 * @since 2.1
419 *
420 * @param array $field {
421 * Optional. Array of text input field arguments.
422 *
423 * @type string $id Field ID. Default ''.
424 * @type string $style CSS style for input field. Default ''.
425 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
426 * @type string $value Value of input field. Default ''.
427 * @type string $name Name of input field. Default ''.
428 * @type string $type Type of input field. Default 'text'.
429 * @type string $before_field Text/HTML to add before input field. Default ''.
430 * @type string $after_field Text/HTML to add after input field. Default ''.
431 * @type string $data_type Define data type for value of input to filter it properly. Default ''.
432 * @type string $description Description of input field. Default ''.
433 * @type array $attributes List of attributes of input field. Default array().
434 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
435 * => '****' )
436 * }
437 *
438 * @return void
439 */
440 function give_donation_limit( $field ) {
441 global $thepostid, $post;
442
443 // Get Give donation form ID.
444 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
445
446 // Default arguments.
447 $default_options = [
448 'style' => '',
449 'wrapper_class' => '',
450 'value' => give_get_field_value( $field, $thepostid ),
451 'data_type' => 'decimal',
452 'before_field' => '',
453 'after_field' => '',
454 ];
455
456 // Field options.
457 $field['options'] = ! empty( $field['options'] ) ? $field['options'] : [];
458
459 // Default field option arguments.
460 $field['options'] = wp_parse_args(
461 $field['options'],
462 [
463 'display_label' => '',
464 'minimum' => give_format_decimal( '1.00', false, false ),
465 'maximum' => give_format_decimal( '999999.99', false, false ),
466 ]
467 );
468
469 // Set default field options.
470 $field_options = wp_parse_args( $field, $default_options );
471
472 // Get default minimum value, if empty.
473 $field_options['value']['minimum'] = ! empty( $field_options['value']['minimum'] )
474 ? $field_options['value']['minimum']
475 : $field_options['options']['minimum'];
476
477 // Get default maximum value, if empty.
478 $field_options['value']['maximum'] = ! empty( $field_options['value']['maximum'] )
479 ? $field_options['value']['maximum']
480 : $field_options['options']['maximum'];
481 ?>
482 <p class="give-field-wrap <?php echo esc_attr( $field_options['id'] ); ?>_field <?php echo esc_attr( $field_options['wrapper_class'] ); ?>">
483 <label for="<?php echo give_get_field_name( $field_options ); ?>"><?php echo wp_kses_post( $field_options['name'] ); ?></label>
484 <span class="give_donation_limit_display">
485 <?php
486 foreach ( $field_options['value'] as $amount_range => $amount_value ) {
487
488 switch ( $field_options['data_type'] ) {
489 case 'price':
490 $currency_position = give_get_option( 'currency_position', 'before' );
491 $price_field_labels = 'minimum' === $amount_range ? __( 'Minimum amount', 'give' ) : __( 'Maximum amount', 'give' );
492
493 $tooltip_html = [
494 'before' => Give()->tooltips->render_span(
495 [
496 'label' => $price_field_labels,
497 'tag_content' => sprintf( '<span class="give-money-symbol give-money-symbol-before">%s</span>', give_currency_symbol() ),
498 ]
499 ),
500 'after' => Give()->tooltips->render_span(
501 [
502 'label' => $price_field_labels,
503 'tag_content' => sprintf( '<span class="give-money-symbol give-money-symbol-after">%s</span>', give_currency_symbol() ),
504 ]
505 ),
506 ];
507
508 $before_html = ! empty( $field_options['before_field'] )
509 ? $field_options['before_field']
510 : ( 'before' === $currency_position ? $tooltip_html['before'] : '' );
511
512 $after_html = ! empty( $field_options['after_field'] )
513 ? $field_options['after_field']
514 : ( 'after' === $currency_position ? $tooltip_html['after'] : '' );
515
516 $field_options['attributes']['class'] .= ' give-text_small';
517 $field_options['value'][ $amount_range ] = $amount_value;
518 break;
519
520 case 'decimal':
521 $field_options['attributes']['class'] .= ' give_input_decimal give-text_small';
522 $field_options['value'][ $amount_range ] = $amount_value;
523 break;
524 }
525
526 echo '<span class=give-minmax-wrap>';
527 printf( '<label for="%1$s_give_donation_limit_%2$s">%3$s</label>', esc_attr( $field_options['id'] ), esc_attr( $amount_range ), esc_html( $price_field_labels ) );
528
529 echo isset( $before_html ) ? $before_html : '';
530 ?>
531 <input
532 name="<?php echo give_get_field_name( $field_options ); ?>[<?php echo esc_attr( $amount_range ); ?>]"
533 type="text"
534 id="<?php echo $field_options['id']; ?>_give_donation_limit_<?php echo $amount_range; ?>"
535 data-range_type="<?php echo esc_attr( $amount_range ); ?>"
536 value="<?php echo give_format_decimal( esc_attr( $field_options['value'][ $amount_range ] ) ); ?>"
537 placeholder="<?php echo give_format_decimal( $field_options['options'][ $amount_range ] ); ?>"
538 <?php echo give_get_attribute_str( $field_options ); ?>
539 />
540 <?php
541 echo isset( $after_html ) ? $after_html : '';
542 echo '</span>';
543 }
544 ?>
545 </span>
546 <?php echo give_get_field_description( $field_options ); ?>
547 </p>
548 <?php
549 }
550
551 /**
552 * Output a hidden input box.
553 *
554 * @since 1.8
555 *
556 * @param array $field {
557 * Optional. Array of hidden text input field arguments.
558 *
559 * @type string $id Field ID. Default ''.
560 * @type string $value Value of input field. Default ''.
561 * @type string $name Name of input field. Default ''.
562 * @type string $type Type of input field. Default 'text'.
563 * @type array $attributes List of attributes of input field. Default array().
564 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
565 * => '****' )
566 * }
567 * @return void
568 */
569 function give_hidden_input( $field ) {
570 global $thepostid, $post;
571
572 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
573 $field['value'] = give_get_field_value( $field, $thepostid );
574
575 // Custom attribute handling
576 $custom_attributes = [];
577
578 if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
579
580 foreach ( $field['attributes'] as $attribute => $value ) {
581 $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
582 }
583 }
584 ?>
585
586 <input
587 type="hidden"
588 name="<?php echo give_get_field_name( $field ); ?>"
589 id="<?php echo esc_attr( $field['id'] ); ?>"
590 value="<?php echo esc_attr( $field['value'] ); ?>"
591 <?php echo give_get_attribute_str( $field ); ?>
592 />
593 <?php
594 }
595
596 /**
597 * Output a textarea input box.
598 *
599 * @since 1.8
600 * @since 1.8
601 *
602 * @param array $field {
603 * Optional. Array of textarea input field arguments.
604 *
605 * @type string $id Field ID. Default ''.
606 * @type string $style CSS style for input field. Default ''.
607 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
608 * @type string $value Value of input field. Default ''.
609 * @type string $name Name of input field. Default ''.
610 * @type string $description Description of input field. Default ''.
611 * @type array $attributes List of attributes of input field. Default array().
612 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
613 * => '****' )
614 * }
615 * @return void
616 */
617 function give_textarea_input( $field ) {
618 global $thepostid, $post;
619
620 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
621 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
622 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
623 $field['value'] = give_get_field_value( $field, $thepostid );
624 $default_attributes = [
625 'cols' => 20,
626 'rows' => 10,
627 ];
628 ?>
629 <div class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
630 <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
631 <textarea
632 style="<?php echo esc_attr( $field['style'] ); ?>"
633 name="<?php echo give_get_field_name( $field ); ?>"
634 id="<?php echo esc_attr( $field['id'] ); ?>"
635 <?php echo give_get_attribute_str( $field, $default_attributes ); ?>
636 ><?php echo esc_textarea( $field['value'] ); ?></textarea>
637 <?php
638 echo give_get_field_description( $field );
639 echo '</div>';
640 }
641
642 /**
643 * Output a wysiwyg.
644 *
645 * @since 1.8
646 *
647 * @param array $field {
648 * Optional. Array of WordPress editor field arguments.
649 *
650 * @type string $id Field ID. Default ''.
651 * @type string $style CSS style for input field. Default ''.
652 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
653 * @type string $value Value of input field. Default ''.
654 * @type string $name Name of input field. Default ''.
655 * @type string $description Description of input field. Default ''.
656 * @type array $attributes List of attributes of input field. Default array().
657 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
658 * => '****' )
659 * }
660 * @return void
661 */
662 function give_wysiwyg( $field ) {
663 global $thepostid, $post;
664
665 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
666 $field['value'] = give_get_field_value( $field, $thepostid );
667 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
668 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
669
670 // Since WP 3.9.0 WP does not allow square brackets in field id.
671 // If we pass square brackets in field id then code will work as expected but you will get PHP warnings.
672 // wp-includes/class-wp-editor.php::parse_settings::106
673 $field['unique_field_id'] = str_replace( [ '[', ']' ], [ '_', '' ], give_get_field_name( $field ) );
674
675 $editor_attributes = [
676 'textarea_name' => isset( $field['repeatable_field_id'] ) ? $field['repeatable_field_id'] : $field['id'],
677 'textarea_rows' => '10',
678 'editor_css' => esc_attr( $field['style'] ),
679 'editor_class' => $field['attributes']['class'],
680 ];
681 $data_wp_editor = ' data-wp-editor="' . base64_encode(
682 json_encode(
683 [
684 $field['value'],
685 $field['unique_field_id'],
686 $editor_attributes,
687 ]
688 )
689 ) . '"';
690 $data_wp_editor = isset( $field['repeatable_field_id'] ) ? $data_wp_editor : '';
691
692 echo '<div class="give-field-wrap ' . $field['unique_field_id'] . '_field ' . esc_attr( $field['wrapper_class'] ) . '"' . $data_wp_editor . '><label for="' . $field['unique_field_id'] . '">' . wp_kses_post( $field['name'] ) . '</label>';
693
694 wp_editor(
695 $field['value'],
696 $field['unique_field_id'],
697 $editor_attributes
698 );
699
700 echo give_get_field_description( $field );
701 echo '</div>';
702 }
703
704 /**
705 * Output a checkbox input box.
706 *
707 * @since 1.8
708 *
709 * @param array $field {
710 * Optional. Array of checkbox field arguments.
711 *
712 * @type string $id Field ID. Default ''.
713 * @type string $style CSS style for input field. Default ''.
714 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
715 * @type string $value Value of input field. Default ''.
716 * @type string $cbvalue Checkbox value. Default 'on'.
717 * @type string $name Name of input field. Default ''.
718 * @type string $description Description of input field. Default ''.
719 * @type array $attributes List of attributes of input field. Default array().
720 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
721 * => '****' )
722 * }
723 * @return void
724 */
725 function give_checkbox( $field ) {
726 global $thepostid, $post;
727
728 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
729 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
730 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
731 $field['value'] = give_get_field_value( $field, $thepostid );
732 $field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on';
733 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
734 ?>
735 <p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
736 <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
737 <input
738 type="checkbox"
739 style="<?php echo esc_attr( $field['style'] ); ?>"
740 name="<?php echo give_get_field_name( $field ); ?>"
741 id="<?php echo esc_attr( $field['id'] ); ?>"
742 value="<?php echo esc_attr( $field['cbvalue'] ); ?>"
743 <?php echo checked( $field['value'], $field['cbvalue'], false ); ?>
744 <?php echo give_get_attribute_str( $field ); ?>
745 />
746 <?php
747 echo give_get_field_description( $field );
748 echo '</p>';
749 }
750
751 /**
752 * Output multi checkbox input box.
753 *
754 * @since 2.9.0
755 *
756 * @param array $field {
757 * Optional. Array of checkbox field arguments.
758 *
759 * @type string $id Field ID. Default ''.
760 * @type string $style CSS style for input field. Default ''.
761 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
762 * @type string $value Value of input field. Default ''.
763 * @type string $name Name of input field. Default ''.
764 * @type string $description Description of input field. Default ''.
765 * @type array $attributes List of attributes of input field. Default array().
766 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
767 * => '****' )
768 * @type array $options List of options. Default array().
769 * for example: 'options' => array( 'option1' => 'Option 1', 'option2' =>
770 * 'Option 2' )
771 * }
772 * @return void
773 */
774 function give_multicheck( $field ) {
775 global $thepostid, $post;
776
777 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
778 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
779 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
780 $field['value'] = give_get_field_value( $field, $thepostid );
781 $field['value'] = is_array( $field['value'] ) ? $field['value'] : [];
782 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
783
784 ?>
785 <fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
786 <span class="give-field-label"><?php echo wp_kses_post( $field['name'] ); ?></span>
787 <legend class="screen-reader-text"><?php echo wp_kses_post( $field['name'] ); ?></legend>
788
789 <ul>
790 <?php foreach ( $field['options'] as $key => $value ) : ?>
791 <li>
792 <label>
793 <input
794 type="checkbox"
795 name="<?php echo give_get_field_name( $field ); ?>[]"
796 value="<?php echo esc_attr( $key ); ?>"
797 style="<?php echo esc_attr( $field['style'] ); ?>"
798 <?php echo give_get_attribute_str( $field ); ?>
799 <?php
800 if ( in_array( $key, $field['value'] ) ) {
801 echo 'checked="checked"';}
802 ?>
803 /> <?php echo esc_html( $value ); ?>
804 </label>
805 </li>
806 <?php endforeach; ?>
807 </ul>
808 <?php echo give_get_field_description( $field ); ?>
809 </fieldset>
810 <?php
811 }
812
813 /**
814 * Output a select input box.
815 *
816 * @since 1.8
817 *
818 * @param array $field {
819 * Optional. Array of select field arguments.
820 *
821 * @type string $id Field ID. Default ''.
822 * @type string $style CSS style for input field. Default ''.
823 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
824 * @type string $value Value of input field. Default ''.
825 * @type string $name Name of input field. Default ''.
826 * @type string $description Description of input field. Default ''.
827 * @type array $attributes List of attributes of input field. Default array().
828 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
829 * => '****' )
830 * @type array $options List of options. Default array().
831 * for example: 'options' => array( '' => 'None', 'yes' => 'Yes' )
832 * }
833 * @return void
834 */
835 function give_select( $field ) {
836 global $thepostid, $post;
837
838 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
839 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
840 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
841 $field['value'] = give_get_field_value( $field, $thepostid );
842 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
843 ?>
844 <p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
845 <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
846 <select
847 id="<?php echo esc_attr( $field['id'] ); ?>"
848 name="<?php echo give_get_field_name( $field ); ?>"
849 style="<?php echo esc_attr( $field['style'] ); ?>"
850 <?php echo give_get_attribute_str( $field ); ?>
851 >
852 <?php
853 foreach ( $field['options'] as $key => $value ) {
854 echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
855 }
856 echo '</select>';
857 echo give_get_field_description( $field );
858 echo '</p>';
859 }
860
861 /**
862 * Output a radio input box.
863 *
864 * @since 1.8
865 *
866 * @param array $field {
867 * Optional. Array of radio field arguments.
868 *
869 * @type string $id Field ID. Default ''.
870 * @type string $style CSS style for input field. Default ''.
871 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
872 * @type string $value Value of input field. Default ''.
873 * @type string $name Name of input field. Default ''.
874 * @type string $description Description of input field. Default ''.
875 * @type array $attributes List of attributes of input field. Default array().
876 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
877 * => '****' )
878 * @type array $options List of options. Default array().
879 * for example: 'options' => array( 'enable' => 'Enable', 'disable' =>
880 * 'Disable' )
881 * }
882 * @return void
883 */
884 function give_radio( $field ) {
885 global $thepostid, $post;
886
887 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
888 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
889 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
890 $field['value'] = give_get_field_value( $field, $thepostid );
891 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
892
893 echo '<fieldset class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><span class="give-field-label">' . wp_kses_post( $field['name'] ) . '</span><legend class="screen-reader-text">' . wp_kses_post( $field['name'] ) . '</legend><ul class="give-radios">';
894
895 foreach ( $field['options'] as $key => $value ) {
896
897 echo '<li><label><input
898 name="' . give_get_field_name( $field ) . '"
899 value="' . esc_attr( $key ) . '"
900 type="radio"
901 style="' . esc_attr( $field['style'] ) . '"
902 ' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' '
903 . give_get_attribute_str( $field ) . '
904 /> ' . esc_html( $value ) . '</label>
905 </li>';
906 }
907 echo '</ul>';
908
909 echo give_get_field_description( $field );
910 echo '</fieldset>';
911 }
912
913 /**
914 * Output a multi-line radio input box.
915 *
916 * @since 2.9.0
917 *
918 * @param array $field {
919 * Optional. Array of radio field arguments.
920 *
921 * @type string $id Field ID. Default ''.
922 * @type string $style CSS style for input field. Default ''.
923 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
924 * @type string $value Value of input field. Default ''.
925 * @type string $name Name of input field. Default ''.
926 * @type string $description Description of input field. Default ''.
927 * @type array $attributes List of attributes of input field. Default array().
928 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
929 * => '****' )
930 * @type array $options List of options. Default array().
931 * for example: 'options' => array( 'enable' => [ 'label' => 'Enable', 'description' => 'Description' ] )
932 * }
933 * @return void
934 */
935 function give_multiradio( $field ) {
936 global $thepostid, $post;
937
938 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
939 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
940 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
941 $field['value'] = give_get_field_value( $field, $thepostid );
942 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
943 ?>
944
945 <fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
946 <span class="give-field-label"><?php echo wp_kses_post( $field['name'] ); ?></span>
947 <legend class="screen-reader-text"><?php echo wp_kses_post( $field['name'] ); ?></legend>
948
949
950 <ul class="give-radios">
951 <?php foreach ( $field['options'] as $key => $data ) : ?>
952 <li>
953 <label>
954 <input
955 type="radio"
956 name="<?php echo give_get_field_name( $field ); ?>"
957 value="<?php echo esc_attr( $key ); ?>"
958 style="<?php echo esc_attr( $field['style'] ); ?>"
959 <?php echo checked( esc_attr( $field['value'] ), esc_attr( $key ), false ); ?>
960 <?php echo give_get_attribute_str( $field ); ?>
961 /> <?php echo esc_html( $data['label'] ); ?>
962 </label>
963 <?php if ( isset( $data['description'] ) ) : ?>
964 <span class="give-field-description">
965 <?php echo esc_html( $data['description'] ); ?>
966 </span>
967 <?php endif; ?>
968 </li>
969 <?php endforeach; ?>
970 </ul>
971 <?php echo give_get_field_description( $field ); ?>
972 </fieldset>
973 <?php
974 }
975
976 /**
977 * Output a colorpicker.
978 *
979 * @since 1.8
980 *
981 * @param array $field {
982 * Optional. Array of colorpicker field arguments.
983 *
984 * @type string $id Field ID. Default ''.
985 * @type string $style CSS style for input field. Default ''.
986 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
987 * @type string $value Value of input field. Default ''.
988 * @type string $name Name of input field. Default ''.
989 * @type string $description Description of input field. Default ''.
990 * @type array $attributes List of attributes of input field. Default array().
991 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
992 * => '****' )
993 * }
994 * @return void
995 */
996 function give_colorpicker( $field ) {
997 global $thepostid, $post;
998
999 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
1000 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
1001 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
1002 $field['value'] = give_get_field_value( $field, $thepostid );
1003 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
1004 $field['type'] = 'text';
1005 ?>
1006 <p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
1007 <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
1008 <input
1009 type="<?php echo esc_attr( $field['type'] ); ?>"
1010 style="<?php echo esc_attr( $field['style'] ); ?>"
1011 name="<?php echo give_get_field_name( $field ); ?>"
1012 id="<?php echo esc_attr( $field['id'] ); ?>"
1013 value="<?php echo esc_attr( $field['value'] ); ?>"
1014 <?php echo give_get_attribute_str( $field ); ?>
1015 />
1016 <?php
1017 echo give_get_field_description( $field );
1018 echo '</p>';
1019 }
1020
1021 /**
1022 * Output a file upload field.
1023 *
1024 * @since 1.8.9
1025 *
1026 * @param array $field
1027 */
1028 function give_file( $field ) {
1029 give_media( $field );
1030 }
1031
1032
1033 /**
1034 * Output a media upload field.
1035 *
1036 * @since 1.8
1037 *
1038 * @param array $field
1039 */
1040 function give_media( $field ) {
1041 global $thepostid, $post;
1042
1043 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
1044 $button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $field['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
1045
1046 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
1047 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
1048 $field['value'] = give_get_field_value( $field, $thepostid );
1049 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
1050 $field['attributes']['class'] = "{$field['attributes']['class']} give-text-medium";
1051
1052 // Allow developer to save attachment ID or attachment url as metadata.
1053 $field['fvalue'] = isset( $field['fvalue'] ) ? $field['fvalue'] : 'url';
1054
1055 $allow_media_preview_tags = [ 'jpg', 'jpeg', 'png', 'gif', 'ico' ];
1056 $preview_image_src = $field['value'] ? ( 'id' === $field['fvalue'] ? wp_get_attachment_url( $field['value'] ) : $field['value'] ) : '#';
1057 $preview_image_extension = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
1058 $is_show_preview = in_array( $preview_image_extension, $allow_media_preview_tags );
1059 ?>
1060 <fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
1061 <label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
1062 <input
1063 name="<?php echo give_get_field_name( $field ); ?>"
1064 id="<?php echo esc_attr( $field['id'] ); ?>"
1065 type="text"
1066 value="<?php echo $field['value']; ?>"
1067 style="<?php echo esc_attr( $field['style'] ); ?>"
1068 <?php echo give_get_attribute_str( $field ); ?>
1069 />&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-upload-button button" type="button" value="<?php echo $button_label; ?>" data-fvalue="<?php echo $field['fvalue']; ?>" data-field-type="<?php echo $field['type']; ?>">
1070 <?php echo give_get_field_description( $field ); ?>
1071 <div class="give-image-thumb<?php echo ! $field['value'] || ! $is_show_preview ? ' give-hidden' : ''; ?>">
1072 <span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
1073 <img src="<?php echo $preview_image_src; ?>" alt="">
1074 </div>
1075 </fieldset>
1076 <?php
1077 }
1078
1079 /**
1080 * Output a select field with payment options list.
1081 *
1082 * @since 1.8
1083 *
1084 * @param array $field
1085 *
1086 * @return void
1087 */
1088 function give_default_gateway( $field ) {
1089 global $thepostid, $post;
1090
1091 // get all active payment gateways.
1092 $gateways = give_get_enabled_payment_gateways( $thepostid );
1093 $field['options'] = [];
1094
1095 // Set field option value.
1096 if ( ! empty( $gateways ) ) {
1097 foreach ( $gateways as $key => $option ) {
1098 $field['options'][ $key ] = $option['admin_label'];
1099 }
1100 }
1101
1102 // Add a field to the Give Form admin single post view of this field
1103 if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
1104 $field['options'] = array_merge( [ 'global' => esc_html__( 'Global Default', 'give' ) ], $field['options'] );
1105 }
1106
1107 // Render select field.
1108 give_select( $field );
1109 }
1110
1111 /**
1112 * Output the documentation link.
1113 *
1114 * @since 1.8
1115 *
1116 * @param array $field {
1117 * Optional. Array of customizable link attributes.
1118 *
1119 * @type string $name Name of input field. Default ''.
1120 * @type string $type Type of input field. Default 'text'.
1121 * @type string $url Value to be passed as a link. Default 'https://givewp.com/documentation'.
1122 * @type string $title Value to be passed as text of link. Default 'Documentation'.
1123 * @type array $attributes List of attributes of input field. Default array().
1124 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
1125 * => '****' )
1126 * }
1127 * @return void
1128 */
1129
1130 function give_docs_link( $field ) {
1131 $field['url'] = isset( $field['url'] ) ? $field['url'] : 'https://givewp.com/documentation';
1132 $field['title'] = isset( $field['title'] ) ? $field['title'] : 'Documentation';
1133
1134 echo '<p class="give-docs-link"><a href="' . esc_url( $field['url'] )
1135 . '" target="_blank">'
1136 . sprintf( esc_html__( 'Need Help? See docs on "%s"', 'give' ), $field['title'] )
1137 . '<span class="dashicons dashicons-editor-help"></span></a></p>';
1138 }
1139
1140
1141 /**
1142 * Output preview buttons.
1143 *
1144 * @since 2.0
1145 *
1146 * @param $field
1147 */
1148 function give_email_preview_buttons( $field ) {
1149 /* @var WP_Post $post */
1150 global $post;
1151
1152 $field_id = str_replace( [ '_give_', '_preview_buttons' ], '', $field['id'] );
1153
1154 ob_start();
1155
1156 echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label>';
1157
1158 echo sprintf(
1159 '<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>',
1160 wp_nonce_url(
1161 add_query_arg(
1162 [
1163 'give_action' => 'preview_email',
1164 'email_type' => $field_id,
1165 'form_id' => $post->ID,
1166 ],
1167 home_url()
1168 ),
1169 'give-preview-email'
1170 ),
1171 $field['name']
1172 );
1173
1174 echo sprintf(
1175 ' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>',
1176 wp_nonce_url(
1177 add_query_arg(
1178 [
1179 'give_action' => 'send_preview_email',
1180 'email_type' => $field_id,
1181 'give-messages[]' => 'sent-test-email',
1182 'form_id' => $post->ID,
1183 ]
1184 ),
1185 'give-send-preview-email'
1186 ),
1187 esc_attr__( 'Send Test Email.', 'give' ),
1188 esc_html__( 'Send Test Email', 'give' )
1189 );
1190
1191 if ( ! empty( $field['description'] ) ) {
1192 echo '<span class="give-field-description">' . wp_kses_post( $field['desc'] ) . '</span>';
1193 }
1194
1195 echo '</p>';
1196
1197 echo ob_get_clean();
1198 }
1199
1200 /**
1201 * Get setting field value.
1202 *
1203 * Note: Use only for single post, page or custom post type.
1204 *
1205 * @since 1.8
1206 * @since 2.1 Added support for donation_limit.
1207 *
1208 * @param array $field
1209 * @param int $postid
1210 *
1211 * @return mixed
1212 */
1213 function give_get_field_value( $field, $postid ) {
1214 if ( isset( $field['attributes']['value'] ) ) {
1215 return $field['attributes']['value'];
1216 }
1217
1218 // If field is range slider.
1219 if ( 'donation_limit' === $field['type'] ) {
1220
1221 // Get minimum value.
1222 $minimum = give_get_meta( $postid, $field['id'] . '_minimum', true );
1223
1224 // Give < 2.1
1225 if ( '_give_custom_amount_range' === $field['id'] && empty( $minimum ) ) {
1226 $minimum = give_get_meta( $postid, '_give_custom_amount_minimum', true );
1227 }
1228
1229 $field_value = [
1230 'minimum' => $minimum,
1231 'maximum' => give_get_meta( $postid, $field['id'] . '_maximum', true ),
1232 ];
1233 } else {
1234 // Get value from db.
1235 $field_value = give_get_meta( $postid, $field['id'], true );
1236 }
1237
1238 /**
1239 * Filter the field value before apply default value.
1240 *
1241 * @since 1.8
1242 *
1243 * @param mixed $field_value Field value.
1244 */
1245 $field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
1246
1247 // Set default value if no any data saved to db.
1248 if ( ! $field_value && isset( $field['default'] ) ) {
1249 $field_value = $field['default'];
1250 }
1251
1252 return $field_value;
1253 }
1254
1255
1256 /**
1257 * Get field description html.
1258 *
1259 * @since 1.8
1260 *
1261 * @param $field
1262 *
1263 * @return string
1264 */
1265 function give_get_field_description( $field ) {
1266 $field_desc_html = '';
1267 $description = '';
1268
1269 // Check for both `description` and `desc`.
1270 if ( isset( $field['description'] ) ) {
1271 $description = $field['description'];
1272 } elseif ( isset( $field['desc'] ) ) {
1273 $description = $field['desc'];
1274 }
1275
1276 // Set if there is a description.
1277 if ( ! empty( $description ) ) {
1278 $field_desc_html = '<span class="give-field-description">' . wp_kses_post( $description ) . '</span>';
1279 }
1280
1281 return $field_desc_html;
1282 }
1283
1284
1285 /**
1286 * Get repeater field value.
1287 *
1288 * Note: Use only for single post, page or custom post type.
1289 *
1290 * @since 1.8
1291 *
1292 * @param array $field
1293 * @param array $field_group
1294 * @param array $fields
1295 *
1296 * @return string
1297 */
1298 function give_get_repeater_field_value( $field, $field_group, $fields ) {
1299 $field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
1300
1301 /**
1302 * Filter the specific repeater field value
1303 *
1304 * @since 1.8
1305 *
1306 * @param string $field_id
1307 */
1308 $field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
1309
1310 /**
1311 * Filter the repeater field value
1312 *
1313 * @since 1.8
1314 *
1315 * @param string $field_id
1316 */
1317 $field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
1318
1319 return $field_value;
1320 }
1321
1322 /**
1323 * Get repeater field id.
1324 *
1325 * Note: Use only for single post, page or custom post type.
1326 *
1327 * @since 1.8
1328 *
1329 * @param array $field
1330 * @param array $fields
1331 * @param int|bool $default
1332 *
1333 * @return string
1334 */
1335 function give_get_repeater_field_id( $field, $fields, $default = false ) {
1336 $row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1337
1338 // Get field id.
1339 $field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
1340
1341 /**
1342 * Filter the specific repeater field id
1343 *
1344 * @since 1.8
1345 *
1346 * @param string $field_id
1347 */
1348 $field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
1349
1350 /**
1351 * Filter the repeater field id
1352 *
1353 * @since 1.8
1354 *
1355 * @param string $field_id
1356 */
1357 $field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
1358
1359 return $field_id;
1360 }
1361
1362
1363 /**
1364 * Get field name.
1365 *
1366 * @since 1.8
1367 *
1368 * @param array $field
1369 *
1370 * @return string
1371 */
1372 function give_get_field_name( $field ) {
1373 $field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
1374
1375 /**
1376 * Filter the field name.
1377 *
1378 * @since 1.8
1379 *
1380 * @param string $field_name
1381 */
1382 $field_name = apply_filters( 'give_get_field_name', $field_name, $field );
1383
1384 return $field_name;
1385 }
1386
1387 /**
1388 * Output repeater field or multi donation type form on donation from edit screen.
1389 * Note: internal use only.
1390 *
1391 * @TODO : Add support for wysiwyg type field.
1392 *
1393 * @since 1.8
1394 *
1395 * @param array $fields
1396 *
1397 * @return void
1398 */
1399 function _give_metabox_form_data_repeater_fields( $fields ) {
1400 global $thepostid, $post;
1401
1402 // Bailout.
1403 if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) {
1404 return;
1405 }
1406
1407 $group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0;
1408 $close_tabs = isset( $fields['options']['close_tabs'] ) ? (int) $fields['options']['close_tabs'] : 0;
1409 $wrapper_class = isset( $fields['wrapper_class'] ) ? $fields['wrapper_class'] : '';
1410 ?>
1411 <div class="give-repeatable-field-section <?php echo esc_attr( $wrapper_class ); ?>" id="<?php echo "{$fields['id']}_field"; ?>"
1412 data-group-numbering="<?php echo $group_numbering; ?>" data-close-tabs="<?php echo $close_tabs; ?>">
1413 <?php if ( ! empty( $fields['name'] ) ) : ?>
1414 <p class="give-repeater-field-name"><?php echo $fields['name']; ?></p>
1415 <?php endif; ?>
1416
1417 <?php if ( ! empty( $fields['description'] ) ) : ?>
1418 <p class="give-repeater-field-description"><?php echo $fields['description']; ?></p>
1419 <?php endif; ?>
1420
1421 <table class="give-repeatable-fields-section-wrapper" cellspacing="0">
1422 <?php
1423 // Get value.
1424 $repeater_field_values = ! empty( $fields['attributes']['value'] )
1425 ? $fields['attributes']['value']
1426 : give_get_meta( $thepostid, $fields['id'], true );
1427
1428 // Setup default value.
1429 if ( empty( $repeater_field_values ) && ! empty( $fields['default'] ) ) {
1430 $repeater_field_values = $fields['default'];
1431 }
1432
1433 $header_title = isset( $fields['options']['header_title'] )
1434 ? $fields['options']['header_title']
1435 : esc_attr__( 'Group', 'give' );
1436
1437 $add_default_donation_field = false;
1438
1439 // Check if level is not created or we have to add default level.
1440 if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) {
1441 $repeater_field_values = array_values( $repeater_field_values );
1442 } else {
1443 $fields_count = 1;
1444 $add_default_donation_field = true;
1445 }
1446 ?>
1447 <tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>>
1448 <!--Repeater field group template-->
1449 <tr class="give-template give-row">
1450 <td class="give-repeater-field-wrap give-column" colspan="2">
1451 <div class="give-row-head give-move">
1452 <button type="button" class="give-handlediv button-link"><span class="toggle-indicator"></span>
1453 </button>
1454 <span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span>
1455 <h2>
1456 <span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
1457 </h2>
1458 </div>
1459 <div class="give-row-body">
1460 <?php foreach ( $fields['fields'] as $field ) : ?>
1461 <?php
1462 if ( ! give_is_field_callback_exist( $field ) ) {
1463 continue;
1464 }
1465 ?>
1466 <?php
1467 $field['repeat'] = true;
1468 $field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields );
1469 $field['id'] = str_replace(
1470 [ '[', ']' ],
1471 [ '_', '' ],
1472 $field['repeatable_field_id']
1473 );
1474 ?>
1475 <?php give_render_field( $field ); ?>
1476 <?php endforeach; ?>
1477 </div>
1478 </td>
1479 </tr>
1480
1481 <?php if ( ! empty( $repeater_field_values ) ) : ?>
1482 <!--Stored repeater field group-->
1483 <?php foreach ( $repeater_field_values as $index => $field_group ) : ?>
1484 <tr class="give-row">
1485 <td class="give-repeater-field-wrap give-column" colspan="2">
1486 <div class="give-row-head give-move">
1487 <button type="button" class="give-handlediv button-link">
1488 <span class="toggle-indicator"></span></button>
1489 <span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
1490 </span>
1491 <h2>
1492 <span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
1493 </h2>
1494 </div>
1495 <div class="give-row-body">
1496 <?php foreach ( $fields['fields'] as $field ) : ?>
1497 <?php
1498 if ( ! give_is_field_callback_exist( $field ) ) {
1499 continue;
1500 }
1501 ?>
1502 <?php
1503 $field['repeat'] = true;
1504 $field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index );
1505 $field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields );
1506 $field['id'] = str_replace(
1507 [ '[', ']' ],
1508 [ '_', '' ],
1509 $field['repeatable_field_id']
1510 );
1511 ?>
1512 <?php give_render_field( $field ); ?>
1513 <?php endforeach; ?>
1514 </div>
1515 </td>
1516 </tr>
1517 <?php
1518 endforeach;
1519 ?>
1520
1521 <?php elseif ( $add_default_donation_field ) : ?>
1522 <!--Default repeater field group-->
1523 <tr class="give-row">
1524 <td class="give-repeater-field-wrap give-column" colspan="2">
1525 <div class="give-row-head give-move">
1526 <button type="button" class="give-handlediv button-link">
1527 <span class="toggle-indicator"></span></button>
1528 <span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
1529 </span>
1530 <h2>
1531 <span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
1532 </h2>
1533 </div>
1534 <div class="give-row-body">
1535 <?php
1536 foreach ( $fields['fields'] as $field ) :
1537 if ( ! give_is_field_callback_exist( $field ) ) {
1538 continue;
1539 }
1540
1541 $field['repeat'] = true;
1542 $field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 );
1543 $field['attributes']['value'] = apply_filters(
1544 "give_default_field_group_field_{$field['id']}_value",
1545 ( ! empty( $field['default'] ) ? $field['default'] : '' ),
1546 $field,
1547 $fields
1548 );
1549 $field['id'] = str_replace(
1550 [ '[', ']' ],
1551 [ '_', '' ],
1552 $field['repeatable_field_id']
1553 );
1554 give_render_field( $field );
1555
1556 endforeach;
1557 ?>
1558 </div>
1559 </td>
1560 </tr>
1561 <?php endif; ?>
1562 </tbody>
1563 <tfoot>
1564 <tr>
1565 <?php
1566 $add_row_btn_title = isset( $fields['options']['add_button'] )
1567 ? $add_row_btn_title = $fields['options']['add_button']
1568 : esc_html__( 'Add Row', 'give' );
1569 ?>
1570 <td colspan="2" class="give-add-repeater-field-section-row-wrap">
1571 <span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span>
1572 </td>
1573 </tr>
1574 </tfoot>
1575 </table>
1576 </div>
1577 <?php
1578 }
1579
1580
1581 /**
1582 * Set repeater field id for multi donation form.
1583 *
1584 * @since 1.8
1585 *
1586 * @param int $field_id
1587 * @param array $field
1588 * @param array $fields
1589 * @param bool $default
1590 *
1591 * @return mixed
1592 */
1593 function _give_set_multi_level_repeater_field_id( $field_id, $field, $fields, $default ) {
1594 $row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1595 $field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1596
1597 return $field_id;
1598 }
1599
1600 add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1601
1602 /**
1603 * Set repeater field value for multi donation form.
1604 *
1605 * @since 1.8
1606 *
1607 * @param string $field_value
1608 * @param array $field
1609 * @param array $field_group
1610 * @param array $fields
1611 *
1612 * @return mixed
1613 */
1614 function _give_set_multi_level_repeater_field_value( $field_value, $field, $field_group, $fields ) {
1615 $field_value = $field_group[ $field['id'] ]['level_id'];
1616
1617 return $field_value;
1618 }
1619
1620 add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1621
1622 /**
1623 * Set default value for _give_id field.
1624 *
1625 * @since 1.8
1626 *
1627 * @param $field
1628 *
1629 * @return string
1630 */
1631 function _give_set_field_give_id_default_value( $field ) {
1632 return 0;
1633 }
1634
1635 add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1636
1637 /**
1638 * Set default value for _give_default field.
1639 *
1640 * @since 1.8
1641 *
1642 * @param $field
1643 *
1644 * @return string
1645 */
1646 function _give_set_field_give_default_default_value( $field ) {
1647 return 'default';
1648 }
1649
1650 add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1651
1652 /**
1653 * Set repeater field editor id for field type wysiwyg.
1654 *
1655 * @since 1.8
1656 *
1657 * @param $field_name
1658 * @param $field
1659 *
1660 * @return string
1661 */
1662 function give_repeater_field_set_editor_id( $field_name, $field ) {
1663 if ( isset( $field['repeatable_field_id'] ) && 'wysiwyg' == $field['type'] ) {
1664 $field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1665 }
1666
1667 return $field_name;
1668 }
1669
1670 add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );
1671
1672 /**
1673 * Output Donation form radio input box.
1674 *
1675 * @since 2.1.3
1676 *
1677 * @param array $field {
1678 * Optional. Array of radio field arguments.
1679 *
1680 * @type string $id Field ID. Default ''.
1681 * @type string $style CSS style for input field. Default ''.
1682 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
1683 * @type string $value Value of input field. Default ''.
1684 * @type string $name Name of input field. Default ''.
1685 * @type string $description Description of input field. Default ''.
1686 * @type array $attributes List of attributes of input field. Default array().
1687 * for example: 'attributes' => array( 'placeholder' => '*****', 'class'
1688 * => '****' )
1689 * @type array $options List of options. Default array().
1690 * for example: 'options' => array( 'enable' => 'Enable', 'disable' =>
1691 * 'Disable' )
1692 * }
1693 * @return void
1694 */
1695 function give_donation_form_goal( $field ) {
1696 global $thepostid, $post;
1697
1698 $thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
1699 $field['style'] = isset( $field['style'] ) ? $field['style'] : '';
1700 $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
1701 $field['value'] = give_get_field_value( $field, $thepostid );
1702 $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id'];
1703
1704 printf(
1705 '<fieldset class="give-field-wrap %s_field %s">',
1706 esc_attr( $field['id'] ),
1707 esc_attr( $field['wrapper_class'] )
1708 );
1709
1710 printf(
1711 '<span class="give-field-label">%s</span>',
1712 esc_html( $field['name'] )
1713 );
1714
1715 printf(
1716 '<legend class="screen-reader-text">%s</legend>',
1717 esc_html( $field['name'] )
1718 );
1719 ?>
1720
1721 <ul class="give-radios">
1722 <?php
1723 foreach ( $field['options'] as $key => $value ) {
1724 $attributes = empty( $field['attributes'] ) ? '' : give_get_attribute_str( $field['attributes'] );
1725 printf(
1726 '<li><label><input name="%s" value="%s" type="radio" style="%s" %s %s /> %s </label></li>',
1727 give_get_field_name( $field ),
1728 esc_attr( $key ),
1729 esc_attr( $field['style'] ),
1730 checked( esc_attr( $field['value'] ), esc_attr( $key ), false ),
1731 $attributes,
1732 esc_html( $value )
1733 );
1734 }
1735 ?>
1736 </ul>
1737
1738 <?php
1739 /**
1740 * Action to add HTML after donation form radio button is display and before description.
1741 *
1742 * @since 2.1.3
1743 *
1744 * @param array $field Array of radio field arguments.
1745 */
1746 do_action( 'give_donation_form_goal_before_description', $field );
1747
1748 echo give_get_field_description( $field );
1749
1750 echo '</fieldset>';
1751 }
1752