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