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