Test Failed
Push — issue/1920 ( c3a9e0 )
by Ravinder
441:16 queued 433:44
created

give-metabox-functions.php ➔ give_range_slider()   F

Complexity

Conditions 16
Paths 1120

Size

Total Lines 113

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 16
nc 1120
nop 1
dl 0
loc 113
rs 1.1198
c 0
b 0
f 0

How to fix   Long Method    Complexity   

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 'range_slider':
79
			$func_name = "{$func_name_prefix}_range_slider";
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 'range_slider':
196
			$field['type']  = 'range_slider';
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
 *
290
 * @since 2.1
291
 *
292
 * @param  array $field         {
293
 *                              Optional. Array of text input field arguments.
294
 *
295
 * @type string  $id            Field ID. Default ''.
296
 * @type string  $style         CSS style for input field. Default ''.
297
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
298
 * @type string  $value         Value of input field. Default ''.
299
 * @type string  $name          Name of input field. Default ''.
300
 * @type string  $type          Type of input field. Default 'text'.
301
 * @type string  $before_field  Text/HTML to add before input field. Default ''.
302
 * @type string  $after_field   Text/HTML to add after input field. Default ''.
303
 * @type string  $data_type     Define data type for value of input to filter it properly. Default ''.
304
 * @type string  $description   Description of input field. Default ''.
305
 * @type array   $attributes    List of attributes of input field. Default array().
306
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
307
 *                                               => '****' )
308
 * }
309
 *
310
 * @return void
311
 */
312
function give_range_slider( $field ) {
313
	global $thepostid, $post;
314
315
	// Get Give donation form ID.
316
	$thepostid = empty( $thepostid ) ? $post->ID : $thepostid;
317
318
	// Default arguments.
319
	$default_options = array(
320
		'style'         => '',
321
		'wrapper_class' => '',
322
		'value'         => give_get_field_value( $field, $thepostid ),
323
		'data_type'     => 'decimal',
324
		'before_field'  => '',
325
		'after_field'   => '',
326
	);
327
328
	// Field options.
329
	$field['options'] = ! empty( $field['options'] ) ? $field['options'] : array();
330
331
	// Default field option arguments.
332
	$field['options'] = wp_parse_args( $field['options'], array(
333
			'display_label' => '',
334
			'minimum'       => 1.00,
335
			'maximum'       => 999999.99,
336
		)
337
	);
338
339
	// Set default field options.
340
	$field_options = wp_parse_args( $field, $default_options );
341
342
	// Get default minimum value, if empty.
343
	$field_options['value']['minimum'] = ! empty( $field_options['value']['minimum'] )
344
		? $field_options['value']['minimum']
345
		: $field_options['options']['minimum'];
346
347
	// Get default maximum value, if empty.
348
	$field_options['value']['maximum'] = ! empty( $field_options['value']['maximum'] )
349
		? $field_options['value']['maximum']
350
		: $field_options['options']['maximum'];
351
	?>
352
	<p class="give-field-wrap <?php echo esc_attr( $field_options['id'] ); ?>_field <?php echo esc_attr( $field_options['wrapper_class'] ); ?>">
353
	<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...
354
	<span class="give_range_slider_display">
355
		<?php
356
357
		if ( ! empty( $field_options['options']['display_label'] ) ) {
358
			?>
359
			<span class="give_range_slider_label">
360
				<?php echo esc_html( $field_options['options']['display_label'] ); ?>
361
			</span>
362
			<?php
363
		}
364
365
		foreach ( $field_options['value'] as $amount_range => $amount_value ) {
366
367
			switch ( $field_options['data_type'] ) {
368
				case 'price' :
369
					$currency_position = give_get_option( 'currency_position', 'before' );
370
					$tooltip_label     = 'minimum' === $amount_range ? __( 'Minimum amount', 'give' ) : __( 'Maximum amount', 'give' );
371
372
					$tooltip_html = array(
373
						'before' => Give()->tooltips->render_span( array(
374
							'label'       => $tooltip_label,
375
							'tag_content' => sprintf( '<span class="give-money-symbol give-money-symbol-before">%s</span>', give_currency_symbol() ),
376
						) ),
377
						'after'  => Give()->tooltips->render_span( array(
378
							'label'       => $tooltip_label,
379
							'tag_content' => sprintf( '<span class="give-money-symbol give-money-symbol-after">%s</span>', give_currency_symbol() ),
380
						) ),
381
					);
382
383
					$before_html = ! empty( $field_options['before_field'] )
384
						? $field_options['before_field']
385
						: ( 'before' === $currency_position ? $tooltip_html['before'] : '' );
386
387
					$after_html = ! empty( $field_options['after_field'] )
388
						? $field_options['after_field']
389
						: ( 'after' === $currency_position ? $tooltip_html['after'] : '' );
390
391
					$field_options['attributes']['class']    .= ' give-text_small';
392
					$field_options['value'][ $amount_range ] = give_maybe_sanitize_amount( $amount_value );
393
					break;
394
				case 'decimal' :
395
					$field_options['attributes']['class']    .= ' give_input_decimal give-text_small';
396
					$field_options['value'][ $amount_range ] = $amount_value;
397
					break;
398
			}
399
400
			echo isset( $before_html ) ? $before_html : '';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
401
			?>
402
			<input
403
					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...
404
					type="text"
405
					id="<?php echo $field_options['id']; ?> _give_range_slider_<?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...
406
					data-range_type="<?php echo esc_attr( $amount_range ); ?>"
407
					value="<?php echo esc_attr( $field_options['value'][ $amount_range ] ); ?>"
408
					placeholder="<?php echo $field_options['options'][ $amount_range ]; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$field_options'
Loading history...
409
				<?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...
410
			/>
411
			<?php
412
			echo isset( $after_html ) ? $after_html : '';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
413
		}
414
		?>
415
	</span>
416
		<span
417
				id="<?php echo esc_attr( $field_options['id'] ); ?>"
418
				style="display: block; <?php echo esc_attr( $field_options['style'] ); ?>"
419
				class="<?php echo apply_filters( "give_range_slider_{$field['id']}_classes", "give-range_slider_field" ); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
Coding Style Comprehensibility introduced by
The string literal give-range_slider_field does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

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