Completed
Push — es6/issue-1475 ( 93c1ad )
by Ravinder
1139:39 queued 1133: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 = sprintf( __( 'Add or Upload %s', 'give' ), ( 'file' === $field['type'] ? __( 'File', 'give' ) : __( '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
 *
886
 * @param $field
887
 */
888
function give_email_preview_buttons( $field ) {
889
	/* @var WP_Post $post */
890
	global $post;
891
892
	$field_id = str_replace( array( '_give_', '_preview_buttons' ), '', $field['id'] );
893
894
	ob_start();
895
896
	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...
897
898
	echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
899
		'<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>',
900
		wp_nonce_url(
901
			add_query_arg(
902
				array(
903
					'give_action' => 'preview_email',
904
					'email_type'  => $field_id,
905
					'form_id'     => $post->ID,
906
				),
907
				home_url()
908
			), 'give-preview-email'
909
		),
910
		$field['name']
911
	);
912
913
	echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
914
		' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>',
915
		wp_nonce_url(
916
			add_query_arg(
917
				array(
918
					'give_action'  => 'send_preview_email',
919
					'email_type'   => $field_id,
920
					'give-message' => 'sent-test-email',
921
					'form_id'      => $post->ID,
922
				)
923
			), '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...
924
		esc_attr__( 'Send Test Email.', 'give' ),
925
		esc_html__( 'Send Test Email', 'give' )
926
	);
927
928
	if ( ! empty( $field['description'] ) ) {
929
		echo '<span class="give-field-description">' . wp_kses_post( $field['desc'] ) . '</span>';
930
	}
931
932
	echo '</p>';
933
934
	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...
935
}
936
937
/**
938
 * Get setting field value.
939
 *
940
 * Note: Use only for single post, page or custom post type.
941
 *
942
 * @since  1.8
943
 * @since  2.1 Added support for range_slider.
944
 *
945
 * @param  array $field
946
 * @param  int   $postid
947
 *
948
 * @return mixed
949
 */
950
function give_get_field_value( $field, $postid ) {
951
	if ( isset( $field['attributes']['value'] ) ) {
952
		return $field['attributes']['value'];
953
	}
954
955
	// If field is range slider.
956
	if ( 'range_slider' === $field['type'] ) {
957
958
		// Get minimum value.
959
		$minimum = give_get_meta( $postid, $field['id'] . '_minimum', true );
960
961
		// Give < 2.1
962
		if ( '_give_custom_amount_range' === $field['id'] && empty( $minimum ) ) {
963
			$minimum = give_get_meta( $postid, '_give_custom_amount_minimum', true );
964
		}
965
966
		$field_value = array(
967
			'minimum' => $minimum,
968
			'maximum' => give_get_meta( $postid, $field['id'] . '_maximum', true ),
969
		);
970
	} else {
971
		// Get value from db.
972
		$field_value = give_get_meta( $postid, $field['id'], true );
973
	}
974
975
	/**
976
	 * Filter the field value before apply default value.
977
	 *
978
	 * @since 1.8
979
	 *
980
	 * @param mixed $field_value Field value.
981
	 */
982
	$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
983
984
	// Set default value if no any data saved to db.
985
	if ( ! $field_value && isset( $field['default'] ) ) {
986
		$field_value = $field['default'];
987
	}
988
989
	return $field_value;
990
}
991
992
993
/**
994
 * Get field description html.
995
 *
996
 * @since 1.8
997
 *
998
 * @param $field
999
 *
1000
 * @return string
1001
 */
1002
function give_get_field_description( $field ) {
1003
	$field_desc_html = '';
1004
	$description     = '';
1005
1006
	// Check for both `description` and `desc`.
1007
	if ( isset( $field['description'] ) ) {
1008
		$description = $field['description'];
1009
	} elseif ( isset( $field['desc'] ) ) {
1010
		$description = $field['desc'];
1011
	}
1012
1013
	// Set if there is a description.
1014
	if ( ! empty( $description ) ) {
1015
		$field_desc_html = '<span class="give-field-description">' . wp_kses_post( $description ) . '</span>';
1016
	}
1017
1018
	return $field_desc_html;
1019
}
1020
1021
1022
/**
1023
 * Get repeater field value.
1024
 *
1025
 * Note: Use only for single post, page or custom post type.
1026
 *
1027
 * @since  1.8
1028
 *
1029
 * @param array $field
1030
 * @param array $field_group
1031
 * @param array $fields
1032
 *
1033
 * @return string
1034
 */
1035
function give_get_repeater_field_value( $field, $field_group, $fields ) {
1036
	$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
1037
1038
	/**
1039
	 * Filter the specific repeater field value
1040
	 *
1041
	 * @since 1.8
1042
	 *
1043
	 * @param string $field_id
1044
	 */
1045
	$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
1046
1047
	/**
1048
	 * Filter the repeater field value
1049
	 *
1050
	 * @since 1.8
1051
	 *
1052
	 * @param string $field_id
1053
	 */
1054
	$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
1055
1056
	return $field_value;
1057
}
1058
1059
/**
1060
 * Get repeater field id.
1061
 *
1062
 * Note: Use only for single post, page or custom post type.
1063
 *
1064
 * @since  1.8
1065
 *
1066
 * @param array    $field
1067
 * @param array    $fields
1068
 * @param int|bool $default
1069
 *
1070
 * @return string
1071
 */
1072
function give_get_repeater_field_id( $field, $fields, $default = false ) {
1073
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1074
1075
	// Get field id.
1076
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
1077
1078
	/**
1079
	 * Filter the specific repeater field id
1080
	 *
1081
	 * @since 1.8
1082
	 *
1083
	 * @param string $field_id
1084
	 */
1085
	$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
1086
1087
	/**
1088
	 * Filter the repeater field id
1089
	 *
1090
	 * @since 1.8
1091
	 *
1092
	 * @param string $field_id
1093
	 */
1094
	$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
1095
1096
	return $field_id;
1097
}
1098
1099
1100
/**
1101
 * Get field name.
1102
 *
1103
 * @since  1.8
1104
 *
1105
 * @param  array $field
1106
 *
1107
 * @return string
1108
 */
1109
function give_get_field_name( $field ) {
1110
	$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
1111
1112
	/**
1113
	 * Filter the field name.
1114
	 *
1115
	 * @since 1.8
1116
	 *
1117
	 * @param string $field_name
1118
	 */
1119
	$field_name = apply_filters( 'give_get_field_name', $field_name, $field );
1120
1121
	return $field_name;
1122
}
1123
1124
/**
1125
 * Output repeater field or multi donation type form on donation from edit screen.
1126
 * Note: internal use only.
1127
 *
1128
 * @TODO   : Add support for wysiwyg type field.
1129
 *
1130
 * @since  1.8
1131
 *
1132
 * @param  array $fields
1133
 *
1134
 * @return void
1135
 */
1136
function _give_metabox_form_data_repeater_fields( $fields ) {
1137
	global $thepostid, $post;
1138
1139
	// Bailout.
1140
	if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) {
1141
		return;
1142
	}
1143
1144
	$group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0;
1145
	$close_tabs      = isset( $fields['options']['close_tabs'] ) ? (int) $fields['options']['close_tabs'] : 0;
1146
	$wrapper_class   = isset( $fields['wrapper_class'] ) ? $fields['wrapper_class'] : '';
1147
	?>
1148
	<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...
1149
	     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...
1150
		<?php if ( ! empty( $fields['name'] ) ) : ?>
1151
			<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...
1152
		<?php endif; ?>
1153
1154
		<?php if ( ! empty( $fields['description'] ) ) : ?>
1155
			<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...
1156
		<?php endif; ?>
1157
1158
		<table class="give-repeatable-fields-section-wrapper" cellspacing="0">
1159
			<?php
1160
			$repeater_field_values = give_get_meta( $thepostid, $fields['id'], true );
1161
			$header_title          = isset( $fields['options']['header_title'] )
1162
				? $fields['options']['header_title']
1163
				: esc_attr__( 'Group', 'give' );
1164
1165
			$add_default_donation_field = false;
1166
1167
			// Check if level is not created or we have to add default level.
1168
			if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) {
1169
				$repeater_field_values = array_values( $repeater_field_values );
1170
			} else {
1171
				$fields_count               = 1;
1172
				$add_default_donation_field = true;
1173
			}
1174
			?>
1175
			<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...
1176
			<!--Repeater field group template-->
1177
			<tr class="give-template give-row">
1178
				<td class="give-repeater-field-wrap give-column" colspan="2">
1179
					<div class="give-row-head give-move">
1180
						<button type="button" class="handlediv button-link"><span class="toggle-indicator"></span>
1181
						</button>
1182
						<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span>
1183
						<h2>
1184
							<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...
1185
						</h2>
1186
					</div>
1187
					<div class="give-row-body">
1188
						<?php foreach ( $fields['fields'] as $field ) : ?>
1189
							<?php
1190
							if ( ! give_is_field_callback_exist( $field ) ) {
1191
								continue;
1192
							}
1193
							?>
1194
							<?php
1195
							$field['repeat']              = true;
1196
							$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields );
1197
							$field['id']                  = str_replace(
1198
								array( '[', ']' ),
1199
								array( '_', '', ),
1200
								$field['repeatable_field_id']
1201
							);
1202
							?>
1203
							<?php give_render_field( $field ); ?>
1204
						<?php endforeach; ?>
1205
					</div>
1206
				</td>
1207
			</tr>
1208
1209
			<?php if ( ! empty( $repeater_field_values ) ) : ?>
1210
				<!--Stored repeater field group-->
1211
				<?php foreach ( $repeater_field_values as $index => $field_group ) : ?>
1212
					<tr class="give-row">
1213
						<td class="give-repeater-field-wrap give-column" colspan="2">
1214
							<div class="give-row-head give-move">
1215
								<button type="button" class="handlediv button-link">
1216
									<span class="toggle-indicator"></span></button>
1217
								<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
1218
								</span>
1219
								<h2>
1220
									<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...
1221
								</h2>
1222
							</div>
1223
							<div class="give-row-body">
1224
								<?php foreach ( $fields['fields'] as $field ) : ?>
1225
									<?php if ( ! give_is_field_callback_exist( $field ) ) {
1226
										continue;
1227
									} ?>
1228
									<?php
1229
									$field['repeat']              = true;
1230
									$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index );
1231
									$field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields );
1232
									$field['id']                  = str_replace(
1233
										array( '[', ']' ),
1234
										array( '_', '', ),
1235
										$field['repeatable_field_id']
1236
									);
1237
									?>
1238
									<?php give_render_field( $field ); ?>
1239
								<?php endforeach; ?>
1240
							</div>
1241
						</td>
1242
					</tr>
1243
				<?php endforeach;; ?>
1244
1245
			<?php elseif ( $add_default_donation_field ) : ?>
1246
				<!--Default repeater field group-->
1247
				<tr class="give-row">
1248
					<td class="give-repeater-field-wrap give-column" colspan="2">
1249
						<div class="give-row-head give-move">
1250
							<button type="button" class="handlediv button-link">
1251
								<span class="toggle-indicator"></span></button>
1252
							<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
1253
							</span>
1254
							<h2>
1255
								<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...
1256
							</h2>
1257
						</div>
1258
						<div class="give-row-body">
1259
							<?php
1260
							foreach ( $fields['fields'] as $field ) :
1261
								if ( ! give_is_field_callback_exist( $field ) ) {
1262
									continue;
1263
								}
1264
1265
								$field['repeat']              = true;
1266
								$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 );
1267
								$field['attributes']['value'] = apply_filters(
1268
									"give_default_field_group_field_{$field['id']}_value",
1269
									( ! empty( $field['default'] ) ? $field['default'] : '' ),
1270
									$field,
1271
									$fields
1272
								);
1273
								$field['id']                  = str_replace(
1274
									array( '[', ']' ),
1275
									array( '_', '', ),
1276
									$field['repeatable_field_id']
1277
								);
1278
								give_render_field( $field );
1279
1280
							endforeach;
1281
							?>
1282
						</div>
1283
					</td>
1284
				</tr>
1285
			<?php endif; ?>
1286
			</tbody>
1287
			<tfoot>
1288
			<tr>
1289
				<?php
1290
				$add_row_btn_title = isset( $fields['options']['add_button'] )
1291
					? $add_row_btn_title = $fields['options']['add_button']
1292
					: esc_html__( 'Add Row', 'give' );
1293
				?>
1294
				<td colspan="2" class="give-add-repeater-field-section-row-wrap">
1295
					<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...
1296
				</td>
1297
			</tr>
1298
			</tfoot>
1299
		</table>
1300
	</div>
1301
	<?php
1302
}
1303
1304
1305
/**
1306
 * Get current setting tab.
1307
 *
1308
 * @since  1.8
1309
 * @return string
1310
 */
1311 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...
1312
	// Get current setting page.
1313
	$current_setting_page = give_get_current_setting_page();
1314
1315
	/**
1316
	 * Filter the default tab for current setting page.
1317
	 *
1318
	 * @since 1.8
1319
	 *
1320
	 * @param string
1321
	 */
1322
	$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' );
1323
1324
	// Get current tab.
1325
	$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...
1326
1327
	// Output.
1328
	return $current_tab;
1329
}
1330
1331
1332
/**
1333
 * Get current setting section.
1334
 *
1335
 * @since  1.8
1336
 * @return string
1337
 */
1338 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...
1339
	// Get current tab.
1340
	$current_tab = give_get_current_setting_tab();
1341
1342
	/**
1343
	 * Filter the default section for current setting page tab.
1344
	 *
1345
	 * @since 1.8
1346
	 *
1347
	 * @param string
1348
	 */
1349
	$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' );
1350
1351
	// Get current section.
1352
	$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...
1353
1354
	// Output.
1355
	return $current_section;
1356
}
1357
1358
/**
1359
 * Get current setting page.
1360
 *
1361
 * @since  1.8
1362
 * @return string
1363
 */
1364
function give_get_current_setting_page() {
1365
	// Get current page.
1366
	$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...
1367
1368
	// Output.
1369
	return $setting_page;
1370
}
1371
1372
/**
1373
 * Set value for Form content --> Display content field setting.
1374
 *
1375
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_display_content is not set
1376
 * yet.
1377
 *
1378
 * @since  1.8
1379
 *
1380
 * @param  mixed $field_value Field Value.
1381
 * @param  array $field       Field args.
1382
 * @param  int   $postid      Form/Post ID.
1383
 *
1384
 * @return string
1385
 */
1386
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...
1387
	$show_content = give_get_meta( $postid, '_give_content_option', true );
1388
1389
	if (
1390
		! give_get_meta( $postid, '_give_display_content', true )
1391
		&& $show_content
1392
		&& ( 'none' !== $show_content )
1393
	) {
1394
		$field_value = 'enabled';
1395
	}
1396
1397
	return $field_value;
1398
}
1399
1400
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 );
1401
1402
1403
/**
1404
 * Set value for Form content --> Content placement field setting.
1405
 *
1406
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_content_placement is not
1407
 * set yet.
1408
 *
1409
 * @since  1.8
1410
 *
1411
 * @param  mixed $field_value Field Value.
1412
 * @param  array $field       Field args.
1413
 * @param  int   $postid      Form/Post ID.
1414
 *
1415
 * @return string
1416
 */
1417
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...
1418
	$show_content = give_get_meta( $postid, '_give_content_option', true );
1419
1420
	if (
1421
		! give_get_meta( $postid, '_give_content_placement', true )
1422
		&& ( 'none' !== $show_content )
1423
	) {
1424
		$field_value = $show_content;
1425
	}
1426
1427
	return $field_value;
1428
}
1429
1430
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 );
1431
1432
1433
/**
1434
 * Set value for Terms and Conditions --> Terms and Conditions field setting.
1435
 *
1436
 * Backward compatibility:  set value by _give_terms_option form meta field value if it's value is none.
1437
 *
1438
 * @since  1.8
1439
 *
1440
 * @param  mixed $field_value Field Value.
1441
 * @param  array $field       Field args.
1442
 * @param  int   $postid      Form/Post ID.
1443
 *
1444
 * @return string
1445
 */
1446 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...
1447
	$term_option = give_get_meta( $postid, '_give_terms_option', true );
1448
1449
	if ( in_array( $term_option, array( 'none', 'yes' ) ) ) {
1450
		$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' );
1451
	}
1452
1453
	return $field_value;
1454
}
1455
1456
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 );
1457
1458
1459
/**
1460
 * Set value for Form Display --> Offline Donation --> Billing Fields.
1461
 *
1462
 * Backward compatibility:  set value by _give_offline_donation_enable_billing_fields_single form meta field value if
1463
 * it's value is on.
1464
 *
1465
 * @since  1.8
1466
 *
1467
 * @param  mixed $field_value Field Value.
1468
 * @param  array $field       Field args.
1469
 * @param  int   $postid      Form/Post ID.
1470
 *
1471
 * @return string
1472
 */
1473
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...
1474
	$offline_donation = give_get_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true );
1475
1476
	if ( 'on' === $offline_donation ) {
1477
		$field_value = 'enabled';
1478
	}
1479
1480
	return $field_value;
1481
}
1482
1483
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 );
1484
1485
1486
/**
1487
 * Set value for Donation Options --> Custom Amount.
1488
 *
1489
 * Backward compatibility:  set value by _give_custom_amount form meta field value if it's value is yes or no.
1490
 *
1491
 * @since  1.8
1492
 *
1493
 * @param  mixed $field_value Field Value.
1494
 * @param  array $field       Field args.
1495
 * @param  int   $postid      Form/Post ID.
1496
 *
1497
 * @return string
1498
 */
1499 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...
1500
	$custom_amount = give_get_meta( $postid, '_give_custom_amount', true );
1501
1502
	if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) {
1503
		$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' );
1504
	}
1505
1506
	return $field_value;
1507
}
1508
1509
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 );
1510
1511
1512
/**
1513
 * Set value for Donation Goal --> Donation Goal.
1514
 *
1515
 * Backward compatibility:  set value by _give_goal_option form meta field value if it's value is yes or no.
1516
 *
1517
 * @since  1.8
1518
 *
1519
 * @param  mixed $field_value Field Value.
1520
 * @param  array $field       Field args.
1521
 * @param  int   $postid      Form/Post ID.
1522
 *
1523
 * @return string
1524
 */
1525 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...
1526
	$goal_option = give_get_meta( $postid, '_give_goal_option', true );
1527
1528
	if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) {
1529
		$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' );
1530
	}
1531
1532
	return $field_value;
1533
}
1534
1535
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 );
1536
1537
/**
1538
 * Set value for Donation Goal --> close Form.
1539
 *
1540
 * Backward compatibility:  set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes
1541
 * or no.
1542
 *
1543
 * @since  1.8
1544
 *
1545
 * @param  mixed $field_value Field Value.
1546
 * @param  array $field       Field args.
1547
 * @param  int   $postid      Form/Post ID.
1548
 *
1549
 * @return string
1550
 */
1551 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...
1552
	$close_form = give_get_meta( $postid, '_give_close_form_when_goal_achieved', true );
1553
1554
	if ( in_array( $close_form, array( 'yes', 'no' ) ) ) {
1555
		$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' );
1556
	}
1557
1558
	return $field_value;
1559
}
1560
1561
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 );
1562
1563
1564
/**
1565
 * Set value for Form display --> Guest Donation.
1566
 *
1567
 * Backward compatibility:  set value by _give_logged_in_only form meta field value if it's value is yes or no.
1568
 *
1569
 * @since  1.8
1570
 *
1571
 * @param  mixed $field_value Field Value.
1572
 * @param  array $field       Field args.
1573
 * @param  int   $postid      Form/Post ID.
1574
 *
1575
 * @return string
1576
 */
1577 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...
1578
	$guest_donation = give_get_meta( $postid, '_give_logged_in_only', true );
1579
1580
	if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) {
1581
		$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' );
1582
	}
1583
1584
	return $field_value;
1585
}
1586
1587
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 );
1588
1589
/**
1590
 * Set value for Offline Donations --> Offline Donations.
1591
 *
1592
 * Backward compatibility:  set value by _give_customize_offline_donations form meta field value if it's value is yes
1593
 * or no.
1594
 *
1595
 * @since  1.8
1596
 *
1597
 * @param  mixed $field_value Field Value.
1598
 * @param  array $field       Field args.
1599
 * @param  int   $postid      Form/Post ID.
1600
 *
1601
 * @return string
1602
 */
1603 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...
1604
	$customize_offline_text = give_get_meta( $postid, '_give_customize_offline_donations', true );
1605
1606
	if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) {
1607
		$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' );
1608
	}
1609
1610
	return $field_value;
1611
}
1612
1613
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 );
1614
1615
1616
/**
1617
 * Set repeater field id for multi donation form.
1618
 *
1619
 * @since 1.8
1620
 *
1621
 * @param int   $field_id
1622
 * @param array $field
1623
 * @param array $fields
1624
 * @param bool  $default
1625
 *
1626
 * @return mixed
1627
 */
1628
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...
1629
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1630
	$field_id        = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1631
1632
	return $field_id;
1633
}
1634
1635
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1636
1637
/**
1638
 * Set repeater field value for multi donation form.
1639
 *
1640
 * @since 1.8
1641
 *
1642
 * @param string $field_value
1643
 * @param array  $field
1644
 * @param array  $field_group
1645
 * @param array  $fields
1646
 *
1647
 * @return mixed
1648
 */
1649
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...
1650
	$field_value = $field_group[ $field['id'] ]['level_id'];
1651
1652
	return $field_value;
1653
}
1654
1655
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1656
1657
/**
1658
 * Set default value for _give_id field.
1659
 *
1660
 * @since 1.8
1661
 *
1662
 * @param $field
1663
 *
1664
 * @return string
1665
 */
1666
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...
1667
	return 0;
1668
}
1669
1670
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1671
1672
/**
1673
 * Set default value for _give_default field.
1674
 *
1675
 * @since 1.8
1676
 *
1677
 * @param $field
1678
 *
1679
 * @return string
1680
 */
1681
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...
1682
	return 'default';
1683
}
1684
1685
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1686
1687
/**
1688
 * Set repeater field editor id for field type wysiwyg.
1689
 *
1690
 * @since 1.8
1691
 *
1692
 * @param $field_name
1693
 * @param $field
1694
 *
1695
 * @return string
1696
 */
1697
function give_repeater_field_set_editor_id( $field_name, $field ) {
1698
	if ( isset( $field['repeatable_field_id'] ) && 'wysiwyg' == $field['type'] ) {
1699
		$field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1700
	}
1701
1702
	return $field_name;
1703
}
1704
1705
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );
1706