Test Failed
Pull Request — master (#3256)
by Devin
07:52 queued 10s
created

give-metabox-functions.php ➔ give_donation_form_goal()   B

Complexity

Conditions 7
Paths 48

Size

Total Lines 58
Code Lines 36

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 36
nc 48
nop 1
dl 0
loc 58
rs 7.6045
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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        = '';
0 ignored issues
show
Unused Code introduced by
$func_name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
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 View Code Duplication
	if ( ! empty( $field['row_classes'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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_amount( give_maybe_sanitize_amount( $field['value'] ), array( 'sanitize' => 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>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
272
	<?php echo $field['before_field']; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field'
Loading history...
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 ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
277
			id="<?php echo esc_attr( $field['id'] ); ?>"
278
			value="<?php echo esc_attr( $field['value'] ); ?>"
279
		<?php echo give_get_custom_attributes( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
280
	/>
281
	<?php echo $field['after_field']; ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field'
Loading history...
282
	<?php
283
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
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'       => 1.00,
336
			'maximum'       => 999999.99,
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>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
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 ] = give_maybe_sanitize_amount( $amount_value );
385
					break;
386
				case 'decimal' :
387
					$field_options['attributes']['class']    .= ' give_input_decimal give-text_small';
388
					$field_options['value'][ $amount_range ] = $amount_value;
389
					break;
390
			}
391
392
			echo '<span class=give-minmax-wrap>';
393
			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 ) );
394
395
			echo isset( $before_html ) ? $before_html : '';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
396
			?>
397
			<input
398
					name="<?php echo give_get_field_name( $field_options ); ?>[<?php echo esc_attr( $amount_range ); ?>]"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
399
					type="text"
400
					id="<?php echo $field_options['id']; ?>_give_donation_limit_<?php echo $amount_range; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field_options'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$amount_range'
Loading history...
401
					data-range_type="<?php echo esc_attr( $amount_range ); ?>"
402
					value="<?php echo give_format_decimal( esc_attr( $field_options['value'][ $amount_range ] ) ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_format_decimal'
Loading history...
403
					placeholder="<?php echo give_format_decimal( $field_options['options'][ $amount_range ] ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_format_decimal'
Loading history...
404
				<?php echo give_get_custom_attributes( $field_options ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
405
			/>
406
			<?php
407
			echo isset( $after_html ) ? $after_html : '';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
408
			echo '</span>';
409
		}
410
		?>
411
	</span>
412
		<?php echo give_get_field_description( $field_options ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
413
	</p>
414
	<?php
415
}
416
417
/**
418
 * Output a hidden input box.
419
 *
420
 * @since  1.8
421
 *
422
 * @param  array $field      {
423
 *                           Optional. Array of hidden text input field arguments.
424
 *
425
 * @type string  $id         Field ID. Default ''.
426
 * @type string  $value      Value of input field. Default ''.
427
 * @type string  $name       Name of input field. Default ''.
428
 * @type string  $type       Type of input field. Default 'text'.
429
 * @type array   $attributes List of attributes of input field. Default array().
430
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
431
 *                                               => '****' )
432
 * }
433
 * @return void
434
 */
435
function give_hidden_input( $field ) {
436
	global $thepostid, $post;
437
438
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
439
	$field['value'] = give_get_field_value( $field, $thepostid );
440
441
	// Custom attribute handling
442
	$custom_attributes = array();
443
444 View Code Duplication
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
445
446
		foreach ( $field['attributes'] as $attribute => $value ) {
447
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
448
		}
449
	}
450
	?>
451
452
	<input
453
			type="hidden"
454
			name="<?php echo give_get_field_name( $field ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
455
			id="<?php echo esc_attr( $field['id'] ); ?>"
456
			value="<?php echo esc_attr( $field['value'] ); ?>"
457
		<?php echo give_get_custom_attributes( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
458
	/>
459
	<?php
460
}
461
462
/**
463
 * Output a textarea input box.
464
 *
465
 * @since  1.8
466
 * @since  1.8
467
 *
468
 * @param  array $field         {
469
 *                              Optional. Array of textarea input field arguments.
470
 *
471
 * @type string  $id            Field ID. Default ''.
472
 * @type string  $style         CSS style for input field. Default ''.
473
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
474
 * @type string  $value         Value of input field. Default ''.
475
 * @type string  $name          Name of input field. Default ''.
476
 * @type string  $description   Description of input field. Default ''.
477
 * @type array   $attributes    List of attributes of input field. Default array().
478
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
479
 *                                               => '****' )
480
 * }
481
 * @return void
482
 */
483
function give_textarea_input( $field ) {
484
	global $thepostid, $post;
485
486
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
487
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
488
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
489
	$field['value']         = give_get_field_value( $field, $thepostid );
490
491
	?>
492
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
493
	<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
494
	<textarea
495
			style="<?php echo esc_attr( $field['style'] ); ?>"
496
			name="<?php echo give_get_field_name( $field ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
497
			id="<?php echo esc_attr( $field['id'] ); ?>"
498
			rows="10"
499
			cols="20"
500
		<?php echo give_get_custom_attributes( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
501
	><?php echo esc_textarea( $field['value'] ); ?></textarea>
502
	<?php
503
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
504
	echo '</p>';
505
}
506
507
/**
508
 * Output a wysiwyg.
509
 *
510
 * @since  1.8
511
 *
512
 * @param  array $field         {
513
 *                              Optional. Array of WordPress editor field arguments.
514
 *
515
 * @type string  $id            Field ID. Default ''.
516
 * @type string  $style         CSS style for input field. Default ''.
517
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
518
 * @type string  $value         Value of input field. Default ''.
519
 * @type string  $name          Name of input field. Default ''.
520
 * @type string  $description   Description of input field. Default ''.
521
 * @type array   $attributes    List of attributes of input field. Default array().
522
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
523
 *                                               => '****' )
524
 * }
525
 * @return void
526
 */
527
function give_wysiwyg( $field ) {
528
	global $thepostid, $post;
529
530
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
531
	$field['value']         = give_get_field_value( $field, $thepostid );
532
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
533
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
534
535
	$field['unique_field_id'] = give_get_field_name( $field );
536
	$editor_attributes        = array(
537
		'textarea_name' => isset( $field['repeatable_field_id'] ) ? $field['repeatable_field_id'] : $field['id'],
538
		'textarea_rows' => '10',
539
		'editor_css'    => esc_attr( $field['style'] ),
540
		'editor_class'  => $field['attributes']['class'],
541
	);
542
	$data_wp_editor           = ' data-wp-editor="' . base64_encode( json_encode( array(
543
			$field['value'],
544
			$field['unique_field_id'],
545
			$editor_attributes,
546
		) ) ) . '"';
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 4 spaces, but found 8.
Loading history...
547
	$data_wp_editor           = isset( $field['repeatable_field_id'] ) ? $data_wp_editor : '';
548
549
	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>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$data_wp_editor'
Loading history...
550
551
	wp_editor(
552
		$field['value'],
553
		$field['unique_field_id'],
554
		$editor_attributes
555
	);
556
557
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
558
	echo '</div>';
559
}
560
561
/**
562
 * Output a checkbox input box.
563
 *
564
 * @since  1.8
565
 *
566
 * @param  array $field         {
567
 *                              Optional. Array of checkbox field arguments.
568
 *
569
 * @type string  $id            Field ID. Default ''.
570
 * @type string  $style         CSS style for input field. Default ''.
571
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
572
 * @type string  $value         Value of input field. Default ''.
573
 * @type string  $cbvalue       Checkbox value. Default 'on'.
574
 * @type string  $name          Name of input field. Default ''.
575
 * @type string  $description   Description of input field. Default ''.
576
 * @type array   $attributes    List of attributes of input field. Default array().
577
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
578
 *                                               => '****' )
579
 * }
580
 * @return void
581
 */
582
function give_checkbox( $field ) {
583
	global $thepostid, $post;
584
585
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
586
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
587
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
588
	$field['value']         = give_get_field_value( $field, $thepostid );
589
	$field['cbvalue']       = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on';
590
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
591
	?>
592
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
593
	<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
594
	<input
595
			type="checkbox"
596
			style="<?php echo esc_attr( $field['style'] ); ?>"
597
			name="<?php echo give_get_field_name( $field ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
598
			id="<?php echo esc_attr( $field['id'] ); ?>"
599
			value="<?php echo esc_attr( $field['cbvalue'] ); ?>"
600
		<?php echo checked( $field['value'], $field['cbvalue'], false ); ?>
601
		<?php echo give_get_custom_attributes( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
602
	/>
603
	<?php
604
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
605
	echo '</p>';
606
}
607
608
/**
609
 * Output a select input box.
610
 *
611
 * @since  1.8
612
 *
613
 * @param  array $field         {
614
 *                              Optional. Array of select field arguments.
615
 *
616
 * @type string  $id            Field ID. Default ''.
617
 * @type string  $style         CSS style for input field. Default ''.
618
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
619
 * @type string  $value         Value of input field. Default ''.
620
 * @type string  $name          Name of input field. Default ''.
621
 * @type string  $description   Description of input field. Default ''.
622
 * @type array   $attributes    List of attributes of input field. Default array().
623
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
624
 *                                               => '****' )
625
 * @type array   $options       List of options. Default array().
626
 *                                               for example: 'options' => array( '' => 'None', 'yes' => 'Yes' )
627
 * }
628
 * @return void
629
 */
630
function give_select( $field ) {
631
	global $thepostid, $post;
632
633
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
634
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
635
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
636
	$field['value']         = give_get_field_value( $field, $thepostid );
637
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
638
	?>
639
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
640
	<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
641
	<select
642
	id="<?php echo esc_attr( $field['id'] ); ?>"
643
	name="<?php echo give_get_field_name( $field ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
644
	style="<?php echo esc_attr( $field['style'] ) ?>"
645
	<?php echo give_get_custom_attributes( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
646
	>
647
	<?php
648
	foreach ( $field['options'] as $key => $value ) {
649
		echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
650
	}
651
	echo '</select>';
652
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
653
	echo '</p>';
654
}
655
656
/**
657
 * Output a radio input box.
658
 *
659
 * @since  1.8
660
 *
661
 * @param  array $field         {
662
 *                              Optional. Array of radio field arguments.
663
 *
664
 * @type string  $id            Field ID. Default ''.
665
 * @type string  $style         CSS style for input field. Default ''.
666
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
667
 * @type string  $value         Value of input field. Default ''.
668
 * @type string  $name          Name of input field. Default ''.
669
 * @type string  $description   Description of input field. Default ''.
670
 * @type array   $attributes    List of attributes of input field. Default array().
671
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
672
 *                                               => '****' )
673
 * @type array   $options       List of options. Default array().
674
 *                                               for example: 'options' => array( 'enable' => 'Enable', 'disable' =>
675
 *                                               'Disable' )
676
 * }
677
 * @return void
678
 */
679
function give_radio( $field ) {
680
	global $thepostid, $post;
681
682
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
683
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
684
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
685
	$field['value']         = give_get_field_value( $field, $thepostid );
686
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
687
688
	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">';
689
690
	foreach ( $field['options'] as $key => $value ) {
691
692
		echo '<li><label><input
693
				name="' . give_get_field_name( $field ) . '"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
694
				value="' . esc_attr( $key ) . '"
695
				type="radio"
696
				style="' . esc_attr( $field['style'] ) . '"
697
				' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' '
698
		     . give_get_custom_attributes( $field ) . '
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
699
				/> ' . esc_html( $value ) . '</label>
700
		</li>';
701
	}
702
	echo '</ul>';
703
704
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
705
	echo '</fieldset>';
706
}
707
708
/**
709
 * Output a colorpicker.
710
 *
711
 * @since  1.8
712
 *
713
 * @param  array $field         {
714
 *                              Optional. Array of colorpicker field arguments.
715
 *
716
 * @type string  $id            Field ID. Default ''.
717
 * @type string  $style         CSS style for input field. Default ''.
718
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
719
 * @type string  $value         Value of input field. Default ''.
720
 * @type string  $name          Name of input field. Default ''.
721
 * @type string  $description   Description of input field. Default ''.
722
 * @type array   $attributes    List of attributes of input field. Default array().
723
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
724
 *                                               => '****' )
725
 * }
726
 * @return void
727
 */
728
function give_colorpicker( $field ) {
729
	global $thepostid, $post;
730
731
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
732
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
733
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
734
	$field['value']         = give_get_field_value( $field, $thepostid );
735
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
736
	$field['type']          = 'text';
737
	?>
738
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
739
	<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
740
	<input
741
			type="<?php echo esc_attr( $field['type'] ); ?>"
742
			style="<?php echo esc_attr( $field['style'] ); ?>"
743
			name="<?php echo give_get_field_name( $field ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
744
			id="' . esc_attr( $field['id'] ) . '" value="<?php echo esc_attr( $field['value'] ); ?>"
745
		<?php echo give_get_custom_attributes( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
746
	/>
747
	<?php
748
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
749
	echo '</p>';
750
}
751
752
/**
753
 * Output a file upload field.
754
 *
755
 * @since  1.8.9
756
 *
757
 * @param array $field
758
 */
759
function give_file( $field ) {
760
	give_media( $field );
761
}
762
763
764
/**
765
 * Output a media upload field.
766
 *
767
 * @since  1.8
768
 *
769
 * @param array $field
770
 */
771
function give_media( $field ) {
772
	global $thepostid, $post;
773
774
	$thepostid    = empty( $thepostid ) ? $post->ID : $thepostid;
775
	$button_label = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $field['type'] ? __( 'File', 'give' ) : __( 'Image', 'give' ) ) );
776
777
	$field['style']               = isset( $field['style'] ) ? $field['style'] : '';
778
	$field['wrapper_class']       = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
779
	$field['value']               = give_get_field_value( $field, $thepostid );
780
	$field['name']                = isset( $field['name'] ) ? $field['name'] : $field['id'];
781
	$field['attributes']['class'] = "{$field['attributes']['class']} give-text-medium";
782
783
	// Allow developer to save attachment ID or attachment url as metadata.
784
	$field['fvalue'] = isset( $field['fvalue'] ) ? $field['fvalue'] : 'url';
785
786
	$allow_media_preview_tags = array( 'jpg', 'jpeg', 'png', 'gif', 'ico' );
787
	$preview_image_src        = $field['value'] ? ( 'id' === $field['fvalue'] ? wp_get_attachment_url( $field['value'] ) : $field['value'] ) : '#';
788
	$preview_image_extension  = $preview_image_src ? pathinfo( $preview_image_src, PATHINFO_EXTENSION ) : '';
789
	$is_show_preview          = in_array( $preview_image_extension, $allow_media_preview_tags );
790
	?>
791
	<fieldset class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
792
		<label for="<?php echo give_get_field_name( $field ) ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
793
		<input
794
				name="<?php echo give_get_field_name( $field ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
795
				id="<?php echo esc_attr( $field['id'] ); ?>"
796
				type="text"
797
				value="<?php echo $field['value']; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field'
Loading history...
798
				style="<?php echo esc_attr( $field['style'] ); ?>"
799
			<?php echo give_get_custom_attributes( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_custom_attributes'
Loading history...
800
		/>&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']; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$button_label'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$field'
Loading history...
801
		<?php echo give_get_field_description( $field ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
802
		<div class="give-image-thumb<?php echo ! $field['value'] || ! $is_show_preview ? ' give-hidden' : ''; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '!'
Loading history...
803
			<span class="give-delete-image-thumb dashicons dashicons-no-alt"></span>
804
			<img src="<?php echo $preview_image_src; ?>" alt="">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$preview_image_src'
Loading history...
805
		</div>
806
	</fieldset>
807
	<?php
808
}
809
810
/**
811
 * Output a select field with payment options list.
812
 *
813
 * @since  1.8
814
 *
815
 * @param  array $field
816
 *
817
 * @return void
818
 */
819
function give_default_gateway( $field ) {
820
	global $thepostid, $post;
821
822
	// get all active payment gateways.
823
	$gateways         = give_get_enabled_payment_gateways( $thepostid );
824
	$field['options'] = array();
825
826
	// Set field option value.
827
	if ( ! empty( $gateways ) ) {
828
		foreach ( $gateways as $key => $option ) {
829
			$field['options'][ $key ] = $option['admin_label'];
830
		}
831
	}
832
833
	// Add a field to the Give Form admin single post view of this field
834
	if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
835
		$field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] );
836
	}
837
838
	// Render select field.
839
	give_select( $field );
840
}
841
842
/**
843
 * Output the documentation link.
844
 *
845
 * @since  1.8
846
 *
847
 * @param  array $field      {
848
 *                           Optional. Array of customizable link attributes.
849
 *
850
 * @type string  $name       Name of input field. Default ''.
851
 * @type string  $type       Type of input field. Default 'text'.
852
 * @type string  $url        Value to be passed as a link. Default 'https://givewp.com/documentation'.
853
 * @type string  $title      Value to be passed as text of link. Default 'Documentation'.
854
 * @type array   $attributes List of attributes of input field. Default array().
855
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
856
 *                                               => '****' )
857
 * }
858
 * @return void
859
 */
860
861
function give_docs_link( $field ) {
862
	$field['url']   = isset( $field['url'] ) ? $field['url'] : 'https://givewp.com/documentation';
863
	$field['title'] = isset( $field['title'] ) ? $field['title'] : 'Documentation';
864
865
	echo '<p class="give-docs-link"><a href="' . esc_url( $field['url'] )
866
	     . '" target="_blank">'
867
	     . sprintf( esc_html__( 'Need Help? See docs on "%s"', 'give' ), $field['title'] )
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
868
	     . '<span class="dashicons dashicons-editor-help"></span></a></p>';
869
}
870
871
872
/**
873
 * Output preview buttons.
874
 *
875
 * @since 2.0
876
 *
877
 * @param $field
878
 */
879
function give_email_preview_buttons( $field ) {
880
	/* @var WP_Post $post */
881
	global $post;
882
883
	$field_id = str_replace( array( '_give_', '_preview_buttons' ), '', $field['id'] );
884
885
	ob_start();
886
887
	echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_name'
Loading history...
888
889
	echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
890
		'<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>',
891
		wp_nonce_url(
892
			add_query_arg(
893
				array(
894
					'give_action' => 'preview_email',
895
					'email_type'  => $field_id,
896
					'form_id'     => $post->ID,
897
				),
898
				home_url()
899
			), 'give-preview-email'
900
		),
901
		$field['name']
902
	);
903
904
	echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
905
		' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>',
906
		wp_nonce_url(
907
			add_query_arg(
908
				array(
909
					'give_action'  => 'send_preview_email',
910
					'email_type'   => $field_id,
911
					'give-message' => 'sent-test-email',
912
					'form_id'      => $post->ID,
913
				)
914
			), 'give-send-preview-email' ),
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 8 spaces, but found 12.
Loading history...
915
		esc_attr__( 'Send Test Email.', 'give' ),
916
		esc_html__( 'Send Test Email', 'give' )
917
	);
918
919
	if ( ! empty( $field['description'] ) ) {
920
		echo '<span class="give-field-description">' . wp_kses_post( $field['desc'] ) . '</span>';
921
	}
922
923
	echo '</p>';
924
925
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
926
}
927
928
/**
929
 * Get setting field value.
930
 *
931
 * Note: Use only for single post, page or custom post type.
932
 *
933
 * @since  1.8
934
 * @since  2.1 Added support for donation_limit.
935
 *
936
 * @param  array $field
937
 * @param  int   $postid
938
 *
939
 * @return mixed
940
 */
941
function give_get_field_value( $field, $postid ) {
942
	if ( isset( $field['attributes']['value'] ) ) {
943
		return $field['attributes']['value'];
944
	}
945
946
	// If field is range slider.
947
	if ( 'donation_limit' === $field['type'] ) {
948
949
		// Get minimum value.
950
		$minimum = give_get_meta( $postid, $field['id'] . '_minimum', true );
951
952
		// Give < 2.1
953
		if ( '_give_custom_amount_range' === $field['id'] && empty( $minimum ) ) {
954
			$minimum = give_get_meta( $postid, '_give_custom_amount_minimum', true );
955
		}
956
957
		$field_value = array(
958
			'minimum' => $minimum,
959
			'maximum' => give_get_meta( $postid, $field['id'] . '_maximum', true ),
960
		);
961
	} else {
962
		// Get value from db.
963
		$field_value = give_get_meta( $postid, $field['id'], true );
964
	}
965
966
	/**
967
	 * Filter the field value before apply default value.
968
	 *
969
	 * @since 1.8
970
	 *
971
	 * @param mixed $field_value Field value.
972
	 */
973
	$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
974
975
	// Set default value if no any data saved to db.
976
	if ( ! $field_value && isset( $field['default'] ) ) {
977
		$field_value = $field['default'];
978
	}
979
980
	return $field_value;
981
}
982
983
984
/**
985
 * Get field description html.
986
 *
987
 * @since 1.8
988
 *
989
 * @param $field
990
 *
991
 * @return string
992
 */
993
function give_get_field_description( $field ) {
994
	$field_desc_html = '';
995
	$description     = '';
996
997
	// Check for both `description` and `desc`.
998
	if ( isset( $field['description'] ) ) {
999
		$description = $field['description'];
1000
	} elseif ( isset( $field['desc'] ) ) {
1001
		$description = $field['desc'];
1002
	}
1003
1004
	// Set if there is a description.
1005
	if ( ! empty( $description ) ) {
1006
		$field_desc_html = '<span class="give-field-description">' . wp_kses_post( $description ) . '</span>';
1007
	}
1008
1009
	return $field_desc_html;
1010
}
1011
1012
1013
/**
1014
 * Get repeater field value.
1015
 *
1016
 * Note: Use only for single post, page or custom post type.
1017
 *
1018
 * @since  1.8
1019
 *
1020
 * @param array $field
1021
 * @param array $field_group
1022
 * @param array $fields
1023
 *
1024
 * @return string
1025
 */
1026
function give_get_repeater_field_value( $field, $field_group, $fields ) {
1027
	$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
1028
1029
	/**
1030
	 * Filter the specific repeater field value
1031
	 *
1032
	 * @since 1.8
1033
	 *
1034
	 * @param string $field_id
1035
	 */
1036
	$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
1037
1038
	/**
1039
	 * Filter the repeater field value
1040
	 *
1041
	 * @since 1.8
1042
	 *
1043
	 * @param string $field_id
1044
	 */
1045
	$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
1046
1047
	return $field_value;
1048
}
1049
1050
/**
1051
 * Get repeater field id.
1052
 *
1053
 * Note: Use only for single post, page or custom post type.
1054
 *
1055
 * @since  1.8
1056
 *
1057
 * @param array    $field
1058
 * @param array    $fields
1059
 * @param int|bool $default
1060
 *
1061
 * @return string
1062
 */
1063
function give_get_repeater_field_id( $field, $fields, $default = false ) {
1064
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1065
1066
	// Get field id.
1067
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
1068
1069
	/**
1070
	 * Filter the specific repeater field id
1071
	 *
1072
	 * @since 1.8
1073
	 *
1074
	 * @param string $field_id
1075
	 */
1076
	$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
1077
1078
	/**
1079
	 * Filter the repeater field id
1080
	 *
1081
	 * @since 1.8
1082
	 *
1083
	 * @param string $field_id
1084
	 */
1085
	$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
1086
1087
	return $field_id;
1088
}
1089
1090
1091
/**
1092
 * Get field name.
1093
 *
1094
 * @since  1.8
1095
 *
1096
 * @param  array $field
1097
 *
1098
 * @return string
1099
 */
1100
function give_get_field_name( $field ) {
1101
	$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
1102
1103
	/**
1104
	 * Filter the field name.
1105
	 *
1106
	 * @since 1.8
1107
	 *
1108
	 * @param string $field_name
1109
	 */
1110
	$field_name = apply_filters( 'give_get_field_name', $field_name, $field );
1111
1112
	return $field_name;
1113
}
1114
1115
/**
1116
 * Output repeater field or multi donation type form on donation from edit screen.
1117
 * Note: internal use only.
1118
 *
1119
 * @TODO   : Add support for wysiwyg type field.
1120
 *
1121
 * @since  1.8
1122
 *
1123
 * @param  array $fields
1124
 *
1125
 * @return void
1126
 */
1127
function _give_metabox_form_data_repeater_fields( $fields ) {
1128
	global $thepostid, $post;
1129
1130
	// Bailout.
1131
	if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) {
1132
		return;
1133
	}
1134
1135
	$group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0;
1136
	$close_tabs      = isset( $fields['options']['close_tabs'] ) ? (int) $fields['options']['close_tabs'] : 0;
1137
	$wrapper_class   = isset( $fields['wrapper_class'] ) ? $fields['wrapper_class'] : '';
1138
	?>
1139
	<div class="give-repeatable-field-section <?php echo esc_attr( $wrapper_class ); ?>" id="<?php echo "{$fields['id']}_field"; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '"{$fields['id']}_field"'
Loading history...
1140
	     data-group-numbering="<?php echo $group_numbering; ?>" data-close-tabs="<?php echo $close_tabs; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$group_numbering'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$close_tabs'
Loading history...
1141
		<?php if ( ! empty( $fields['name'] ) ) : ?>
1142
			<p class="give-repeater-field-name"><?php echo $fields['name']; ?></p>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$fields'
Loading history...
1143
		<?php endif; ?>
1144
1145
		<?php if ( ! empty( $fields['description'] ) ) : ?>
1146
			<p class="give-repeater-field-description"><?php echo $fields['description']; ?></p>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$fields'
Loading history...
1147
		<?php endif; ?>
1148
1149
		<table class="give-repeatable-fields-section-wrapper" cellspacing="0">
1150
			<?php
1151
			$repeater_field_values = give_get_meta( $thepostid, $fields['id'], true );
1152
			$header_title          = isset( $fields['options']['header_title'] )
1153
				? $fields['options']['header_title']
1154
				: esc_attr__( 'Group', 'give' );
1155
1156
			$add_default_donation_field = false;
1157
1158
			// Check if level is not created or we have to add default level.
1159
			if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) {
1160
				$repeater_field_values = array_values( $repeater_field_values );
1161
			} else {
1162
				$fields_count               = 1;
1163
				$add_default_donation_field = true;
1164
			}
1165
			?>
1166
			<tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '" data-rf-row-count=\"{$fields_count}\""'
Loading history...
1167
			<!--Repeater field group template-->
1168
			<tr class="give-template give-row">
1169
				<td class="give-repeater-field-wrap give-column" colspan="2">
1170
					<div class="give-row-head give-move">
1171
						<button type="button" class="handlediv button-link"><span class="toggle-indicator"></span>
1172
						</button>
1173
						<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span>
1174
						<h2>
1175
							<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$header_title'
Loading history...
1176
						</h2>
1177
					</div>
1178
					<div class="give-row-body">
1179
						<?php foreach ( $fields['fields'] as $field ) : ?>
1180
							<?php
1181
							if ( ! give_is_field_callback_exist( $field ) ) {
1182
								continue;
1183
							}
1184
							?>
1185
							<?php
1186
							$field['repeat']              = true;
1187
							$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields );
1188
							$field['id']                  = str_replace(
1189
								array( '[', ']' ),
1190
								array( '_', '', ),
1191
								$field['repeatable_field_id']
1192
							);
1193
							?>
1194
							<?php give_render_field( $field ); ?>
1195
						<?php endforeach; ?>
1196
					</div>
1197
				</td>
1198
			</tr>
1199
1200
			<?php if ( ! empty( $repeater_field_values ) ) : ?>
1201
				<!--Stored repeater field group-->
1202
				<?php foreach ( $repeater_field_values as $index => $field_group ) : ?>
1203
					<tr class="give-row">
1204
						<td class="give-repeater-field-wrap give-column" colspan="2">
1205
							<div class="give-row-head give-move">
1206
								<button type="button" class="handlediv button-link">
1207
									<span class="toggle-indicator"></span></button>
1208
								<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
1209
								</span>
1210
								<h2>
1211
									<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$header_title'
Loading history...
1212
								</h2>
1213
							</div>
1214
							<div class="give-row-body">
1215
								<?php foreach ( $fields['fields'] as $field ) : ?>
1216
									<?php if ( ! give_is_field_callback_exist( $field ) ) {
1217
										continue;
1218
									} ?>
1219
									<?php
1220
									$field['repeat']              = true;
1221
									$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index );
1222
									$field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields );
1223
									$field['id']                  = str_replace(
1224
										array( '[', ']' ),
1225
										array( '_', '', ),
1226
										$field['repeatable_field_id']
1227
									);
1228
									?>
1229
									<?php give_render_field( $field ); ?>
1230
								<?php endforeach; ?>
1231
							</div>
1232
						</td>
1233
					</tr>
1234
				<?php endforeach;; ?>
1235
1236
			<?php elseif ( $add_default_donation_field ) : ?>
1237
				<!--Default repeater field group-->
1238
				<tr class="give-row">
1239
					<td class="give-repeater-field-wrap give-column" colspan="2">
1240
						<div class="give-row-head give-move">
1241
							<button type="button" class="handlediv button-link">
1242
								<span class="toggle-indicator"></span></button>
1243
							<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
1244
							</span>
1245
							<h2>
1246
								<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$header_title'
Loading history...
1247
							</h2>
1248
						</div>
1249
						<div class="give-row-body">
1250
							<?php
1251
							foreach ( $fields['fields'] as $field ) :
1252
								if ( ! give_is_field_callback_exist( $field ) ) {
1253
									continue;
1254
								}
1255
1256
								$field['repeat']              = true;
1257
								$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 );
1258
								$field['attributes']['value'] = apply_filters(
1259
									"give_default_field_group_field_{$field['id']}_value",
1260
									( ! empty( $field['default'] ) ? $field['default'] : '' ),
1261
									$field,
1262
									$fields
1263
								);
1264
								$field['id']                  = str_replace(
1265
									array( '[', ']' ),
1266
									array( '_', '', ),
1267
									$field['repeatable_field_id']
1268
								);
1269
								give_render_field( $field );
1270
1271
							endforeach;
1272
							?>
1273
						</div>
1274
					</td>
1275
				</tr>
1276
			<?php endif; ?>
1277
			</tbody>
1278
			<tfoot>
1279
			<tr>
1280
				<?php
1281
				$add_row_btn_title = isset( $fields['options']['add_button'] )
1282
					? $add_row_btn_title = $fields['options']['add_button']
1283
					: esc_html__( 'Add Row', 'give' );
1284
				?>
1285
				<td colspan="2" class="give-add-repeater-field-section-row-wrap">
1286
					<span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$add_row_btn_title'
Loading history...
1287
				</td>
1288
			</tr>
1289
			</tfoot>
1290
		</table>
1291
	</div>
1292
	<?php
1293
}
1294
1295
1296
/**
1297
 * Get current setting tab.
1298
 *
1299
 * @since  1.8
1300
 * @return string
1301
 */
1302 View Code Duplication
function give_get_current_setting_tab() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1303
	// Get current setting page.
1304
	$current_setting_page = give_get_current_setting_page();
1305
1306
	/**
1307
	 * Filter the default tab for current setting page.
1308
	 *
1309
	 * @since 1.8
1310
	 *
1311
	 * @param string
1312
	 */
1313
	$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' );
1314
1315
	// Get current tab.
1316
	$current_tab = empty( $_GET['tab'] ) ? $default_current_tab : urldecode( $_GET['tab'] );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
1317
1318
	// Output.
1319
	return $current_tab;
1320
}
1321
1322
1323
/**
1324
 * Get current setting section.
1325
 *
1326
 * @since  1.8
1327
 * @return string
1328
 */
1329 View Code Duplication
function give_get_current_setting_section() {
0 ignored issues
show
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1330
	// Get current tab.
1331
	$current_tab = give_get_current_setting_tab();
1332
1333
	/**
1334
	 * Filter the default section for current setting page tab.
1335
	 *
1336
	 * @since 1.8
1337
	 *
1338
	 * @param string
1339
	 */
1340
	$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' );
1341
1342
	// Get current section.
1343
	$current_section = empty( $_REQUEST['section'] ) ? $default_current_section : urldecode( $_REQUEST['section'] );
0 ignored issues
show
introduced by
Detected access of super global var $_REQUEST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_REQUEST
Loading history...
1344
1345
	// Output.
1346
	return $current_section;
1347
}
1348
1349
/**
1350
 * Get current setting page.
1351
 *
1352
 * @since  1.8
1353
 * @return string
1354
 */
1355
function give_get_current_setting_page() {
1356
	// Get current page.
1357
	$setting_page = ! empty( $_GET['page'] ) ? urldecode( $_GET['page'] ) : '';
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
1358
1359
	// Output.
1360
	return $setting_page;
1361
}
1362
1363
/**
1364
 * Set value for Form content --> Display content field setting.
1365
 *
1366
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_display_content is not set
1367
 * yet.
1368
 *
1369
 * @since  1.8
1370
 *
1371
 * @param  mixed $field_value Field Value.
1372
 * @param  array $field       Field args.
1373
 * @param  int   $postid      Form/Post ID.
1374
 *
1375
 * @return string
1376
 */
1377
function _give_display_content_field_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1378
	$show_content = give_get_meta( $postid, '_give_content_option', true );
1379
1380
	if (
1381
		! give_get_meta( $postid, '_give_display_content', true )
1382
		&& $show_content
1383
		&& ( 'none' !== $show_content )
1384
	) {
1385
		$field_value = 'enabled';
1386
	}
1387
1388
	return $field_value;
1389
}
1390
1391
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 );
1392
1393
1394
/**
1395
 * Set value for Form content --> Content placement field setting.
1396
 *
1397
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_content_placement is not
1398
 * set yet.
1399
 *
1400
 * @since  1.8
1401
 *
1402
 * @param  mixed $field_value Field Value.
1403
 * @param  array $field       Field args.
1404
 * @param  int   $postid      Form/Post ID.
1405
 *
1406
 * @return string
1407
 */
1408
function _give_content_placement_field_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1409
	$show_content = give_get_meta( $postid, '_give_content_option', true );
1410
1411
	if (
1412
		! give_get_meta( $postid, '_give_content_placement', true )
1413
		&& ( 'none' !== $show_content )
1414
	) {
1415
		$field_value = $show_content;
1416
	}
1417
1418
	return $field_value;
1419
}
1420
1421
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 );
1422
1423
1424
/**
1425
 * Set value for Terms and Conditions --> Terms and Conditions field setting.
1426
 *
1427
 * Backward compatibility:  set value by _give_terms_option form meta field value if it's value is none.
1428
 *
1429
 * @since  1.8
1430
 *
1431
 * @param  mixed $field_value Field Value.
1432
 * @param  array $field       Field args.
1433
 * @param  int   $postid      Form/Post ID.
1434
 *
1435
 * @return string
1436
 */
1437 View Code Duplication
function _give_terms_option_field_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1438
	$term_option = give_get_meta( $postid, '_give_terms_option', true );
1439
1440
	if ( in_array( $term_option, array( 'none', 'yes' ) ) ) {
1441
		$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' );
1442
	}
1443
1444
	return $field_value;
1445
}
1446
1447
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 );
1448
1449
1450
/**
1451
 * Set value for Form Display --> Offline Donation --> Billing Fields.
1452
 *
1453
 * Backward compatibility:  set value by _give_offline_donation_enable_billing_fields_single form meta field value if
1454
 * it's value is on.
1455
 *
1456
 * @since  1.8
1457
 *
1458
 * @param  mixed $field_value Field Value.
1459
 * @param  array $field       Field args.
1460
 * @param  int   $postid      Form/Post ID.
1461
 *
1462
 * @return string
1463
 */
1464
function _give_offline_donation_enable_billing_fields_single_field_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1465
	$offline_donation = give_get_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true );
1466
1467
	if ( 'on' === $offline_donation ) {
1468
		$field_value = 'enabled';
1469
	}
1470
1471
	return $field_value;
1472
}
1473
1474
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 );
1475
1476
1477
/**
1478
 * Set value for Donation Options --> Custom Amount.
1479
 *
1480
 * Backward compatibility:  set value by _give_custom_amount form meta field value if it's value is yes or no.
1481
 *
1482
 * @since  1.8
1483
 *
1484
 * @param  mixed $field_value Field Value.
1485
 * @param  array $field       Field args.
1486
 * @param  int   $postid      Form/Post ID.
1487
 *
1488
 * @return string
1489
 */
1490 View Code Duplication
function _give_custom_amount_field_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1491
	$custom_amount = give_get_meta( $postid, '_give_custom_amount', true );
1492
1493
	if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) {
1494
		$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' );
1495
	}
1496
1497
	return $field_value;
1498
}
1499
1500
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 );
1501
1502
1503
/**
1504
 * Set value for Donation Goal --> Donation Goal.
1505
 *
1506
 * Backward compatibility:  set value by _give_goal_option form meta field value if it's value is yes or no.
1507
 *
1508
 * @since  1.8
1509
 *
1510
 * @param  mixed $field_value Field Value.
1511
 * @param  array $field       Field args.
1512
 * @param  int   $postid      Form/Post ID.
1513
 *
1514
 * @return string
1515
 */
1516 View Code Duplication
function _give_goal_option_field_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1517
	$goal_option = give_get_meta( $postid, '_give_goal_option', true );
1518
1519
	if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) {
1520
		$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' );
1521
	}
1522
1523
	return $field_value;
1524
}
1525
1526
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 );
1527
1528
/**
1529
 * Set value for Donation Goal --> close Form.
1530
 *
1531
 * Backward compatibility:  set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes
1532
 * or no.
1533
 *
1534
 * @since  1.8
1535
 *
1536
 * @param  mixed $field_value Field Value.
1537
 * @param  array $field       Field args.
1538
 * @param  int   $postid      Form/Post ID.
1539
 *
1540
 * @return string
1541
 */
1542 View Code Duplication
function _give_close_form_when_goal_achieved_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1543
	$close_form = give_get_meta( $postid, '_give_close_form_when_goal_achieved', true );
1544
1545
	if ( in_array( $close_form, array( 'yes', 'no' ) ) ) {
1546
		$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' );
1547
	}
1548
1549
	return $field_value;
1550
}
1551
1552
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 );
1553
1554
1555
/**
1556
 * Set value for Form display --> Guest Donation.
1557
 *
1558
 * Backward compatibility:  set value by _give_logged_in_only form meta field value if it's value is yes or no.
1559
 *
1560
 * @since  1.8
1561
 *
1562
 * @param  mixed $field_value Field Value.
1563
 * @param  array $field       Field args.
1564
 * @param  int   $postid      Form/Post ID.
1565
 *
1566
 * @return string
1567
 */
1568 View Code Duplication
function _give_logged_in_only_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1569
	$guest_donation = give_get_meta( $postid, '_give_logged_in_only', true );
1570
1571
	if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) {
1572
		$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' );
1573
	}
1574
1575
	return $field_value;
1576
}
1577
1578
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 );
1579
1580
/**
1581
 * Set value for Offline Donations --> Offline Donations.
1582
 *
1583
 * Backward compatibility:  set value by _give_customize_offline_donations form meta field value if it's value is yes
1584
 * or no.
1585
 *
1586
 * @since  1.8
1587
 *
1588
 * @param  mixed $field_value Field Value.
1589
 * @param  array $field       Field args.
1590
 * @param  int   $postid      Form/Post ID.
1591
 *
1592
 * @return string
1593
 */
1594 View Code Duplication
function _give_customize_offline_donations_value( $field_value, $field, $postid ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This function seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1595
	$customize_offline_text = give_get_meta( $postid, '_give_customize_offline_donations', true );
1596
1597
	if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) {
1598
		$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' );
1599
	}
1600
1601
	return $field_value;
1602
}
1603
1604
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 );
1605
1606
1607
/**
1608
 * Set repeater field id for multi donation form.
1609
 *
1610
 * @since 1.8
1611
 *
1612
 * @param int   $field_id
1613
 * @param array $field
1614
 * @param array $fields
1615
 * @param bool  $default
1616
 *
1617
 * @return mixed
1618
 */
1619
function _give_set_multi_level_repeater_field_id( $field_id, $field, $fields, $default ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field_id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1620
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1621
	$field_id        = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1622
1623
	return $field_id;
1624
}
1625
1626
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1627
1628
/**
1629
 * Set repeater field value for multi donation form.
1630
 *
1631
 * @since 1.8
1632
 *
1633
 * @param string $field_value
1634
 * @param array  $field
1635
 * @param array  $field_group
1636
 * @param array  $fields
1637
 *
1638
 * @return mixed
1639
 */
1640
function _give_set_multi_level_repeater_field_value( $field_value, $field, $field_group, $fields ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field_value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $fields is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1641
	$field_value = $field_group[ $field['id'] ]['level_id'];
1642
1643
	return $field_value;
1644
}
1645
1646
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1647
1648
/**
1649
 * Set default value for _give_id field.
1650
 *
1651
 * @since 1.8
1652
 *
1653
 * @param $field
1654
 *
1655
 * @return string
1656
 */
1657
function _give_set_field_give_id_default_value( $field ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1658
	return 0;
1659
}
1660
1661
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1662
1663
/**
1664
 * Set default value for _give_default field.
1665
 *
1666
 * @since 1.8
1667
 *
1668
 * @param $field
1669
 *
1670
 * @return string
1671
 */
1672
function _give_set_field_give_default_default_value( $field ) {
0 ignored issues
show
Unused Code introduced by
The parameter $field is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1673
	return 'default';
1674
}
1675
1676
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1677
1678
/**
1679
 * Set repeater field editor id for field type wysiwyg.
1680
 *
1681
 * @since 1.8
1682
 *
1683
 * @param $field_name
1684
 * @param $field
1685
 *
1686
 * @return string
1687
 */
1688
function give_repeater_field_set_editor_id( $field_name, $field ) {
1689
	if ( isset( $field['repeatable_field_id'] ) && 'wysiwyg' == $field['type'] ) {
1690
		$field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1691
	}
1692
1693
	return $field_name;
1694
}
1695
1696
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );
1697
1698
/**
1699
 * Output Donation form radio input box.
1700
 *
1701
 * @since  2.1.3
1702
 *
1703
 * @param  array $field {
1704
 *                              Optional. Array of radio field arguments.
1705
 *
1706
 * @type string $id Field ID. Default ''.
1707
 * @type string $style CSS style for input field. Default ''.
1708
 * @type string $wrapper_class CSS class to use for wrapper of input field. Default ''.
1709
 * @type string $value Value of input field. Default ''.
1710
 * @type string $name Name of input field. Default ''.
1711
 * @type string $description Description of input field. Default ''.
1712
 * @type array $attributes List of attributes of input field. Default array().
1713
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
1714
 *                                               => '****' )
1715
 * @type array $options List of options. Default array().
1716
 *                                               for example: 'options' => array( 'enable' => 'Enable', 'disable' =>
1717
 *                                               'Disable' )
1718
 * }
1719
 * @return void
1720
 */
1721
function give_donation_form_goal( $field ) {
1722
	global $thepostid, $post;
1723
1724
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
1725
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
1726
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
1727
	$field['value']         = give_get_field_value( $field, $thepostid );
1728
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
1729
0 ignored issues
show
Coding Style introduced by
Functions must not contain multiple empty lines in a row; found 2 empty lines
Loading history...
1730
1731
	printf(
1732
		'<fieldset class="give-field-wrap %s_field %s">',
1733
		esc_attr( $field['id'] ),
1734
		esc_attr( $field['wrapper_class'] )
1735
	);
1736
1737
	printf(
1738
		'<span class="give-field-label">%s</span>',
1739
		esc_html( $field['name'] )
1740
	);
1741
1742
	printf(
1743
		'<legend class="screen-reader-text">%s</legend>',
1744
		esc_html( $field['name'] )
1745
	);
1746
	?>
1747
1748
    <ul class="give-radios">
1749
		<?php
1750
		foreach ( $field['options'] as $key => $value ) {
1751
			$attributes = empty( $field['attributes'] ) ? '' : give_get_attribute_str( $field['attributes'] );
1752
			printf(
1753
				'<li><label><input name="%s" value="%s" type="radio" style="%s" %s %s /> %s </label></li>',
1754
				give_get_field_name( $field ),
1755
				esc_attr( $key ),
1756
				esc_attr( $field['style'] ),
1757
				checked( esc_attr( $field['value'] ), esc_attr( $key ), false ),
1758
				$attributes,
1759
				esc_html( $value )
1760
			);
1761
		}
1762
		?>
1763
    </ul>
1764
1765
	<?php
1766
	/**
1767
	 * Action to add HTML after donation form radio button is display and before description.
1768
	 *
1769
	 * @since 2.1.3
1770
	 *
1771
	 * @param array $field Array of radio field arguments.
1772
	 */
1773
	do_action( 'give_donation_form_goal_before_description', $field );
1774
1775
	echo give_get_field_description( $field );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_field_description'
Loading history...
1776
1777
	echo '</fieldset>';
1778
}