Completed
Push — master ( 0af146...0e0d02 )
by Devin
13s
created

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

Complexity

Conditions 14
Paths 1120

Size

Total Lines 46
Code Lines 38

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 38
nc 1120
nop 1
dl 0
loc 46
rs 2.6955
c 0
b 0
f 0

How to fix   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
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 25 and the first side effect is on line 12.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * Give Meta Box Functions
4
 *
5
 * @package     Give
6
 * @subpackage  Functions
7
 * @copyright   Copyright (c) 2016, WordImpress
8
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
9
 * @since       1.8
10
 */
11
if ( ! defined( 'ABSPATH' ) ) {
12
	exit; // Exit if accessed directly
13
}
14
15
16
/**
17
 * Check if field callback exist or not.
18
 *
19
 * @since  1.8
20
 *
21
 * @param  $field
22
 *
23
 * @return bool|string
24
 */
25
function give_is_field_callback_exist( $field ) {
26
	return ( give_get_field_callback( $field ) ? true : false );
27
}
28
29
/**
30
 * Get field callback.
31
 *
32
 * @since  1.8
33
 *
34
 * @param  $field
35
 *
36
 * @return bool|string
37
 */
38
function give_get_field_callback( $field ) {
39
	$func_name_prefix = 'give';
40
	$func_name        = '';
41
42
	// Set callback function on basis of cmb2 field name.
43
	switch ( $field['type'] ) {
44
		case 'radio_inline':
45
			$func_name = "{$func_name_prefix}_radio";
46
			break;
47
48
		case 'text':
49
		case 'text-medium':
50
		case 'text_medium':
51
		case 'text-small' :
52
		case 'text_small' :
53
			$func_name = "{$func_name_prefix}_text_input";
54
			break;
55
56
57
		case 'textarea' :
58
			$func_name = "{$func_name_prefix}_textarea_input";
59
			break;
60
61
		case 'colorpicker' :
62
			$func_name = "{$func_name_prefix}_{$field['type']}";
63
			break;
64
65
		case 'levels_id':
66
			$func_name = "{$func_name_prefix}_hidden_input";
67
			break;
68
69
		case 'group' :
70
			$func_name = "_{$func_name_prefix}_metabox_form_data_repeater_fields";
71
			break;
72
73
		case 'give_default_radio_inline':
74
			$func_name = "{$func_name_prefix}_radio";
75
			break;
76
77
		default:
78
79
			if (
80
				array_key_exists( 'callback', $field )
81
				&& ! empty( $field['callback'] )
82
			) {
83
				$func_name = $field['callback'];
84
			} else {
85
				$func_name = "{$func_name_prefix}_{$field['type']}";
86
			}
87
	}
88
89
	/**
90
	 * Filter the metabox setting render function
91
	 *
92
	 * @since 1.8
93
	 */
94
	$func_name = apply_filters( 'give_get_field_callback', $func_name, $field );
95
96
	// Exit if not any function exist.
97
	// Check if render callback exist or not.
98
	if ( empty( $func_name ) ) {
99
		return false;
100
	} elseif ( is_string( $func_name ) && ! function_exists( "$func_name" ) ) {
101
		return false;
102
	} elseif ( is_array( $func_name ) && ! method_exists( $func_name[0], "$func_name[1]" ) ) {
103
		return false;
104
	}
105
106
	return $func_name;
107
}
108
109
/**
110
 * This function adds backward compatibility to render cmb2 type field type.
111
 *
112
 * @since  1.8
113
 *
114
 * @param  array $field Field argument array.
115
 *
116
 * @return bool
117
 */
118
function give_render_field( $field ) {
119
120
	// Check if render callback exist or not.
121
	if ( ! ( $func_name = give_get_field_callback( $field ) ) ) {
122
		return false;
123
	}
124
125
	// CMB2 compatibility: Push all classes to attributes's class key
126
	if ( empty( $field['class'] ) ) {
127
		$field['class'] = '';
128
	}
129
130
	if ( empty( $field['attributes']['class'] ) ) {
131
		$field['attributes']['class'] = '';
132
	}
133
134
	$field['attributes']['class'] = trim( "give-field {$field['attributes']['class']} give-{$field['type']} {$field['class']}" );
135
	unset( $field['class'] );
136
137
138
	// CMB2 compatibility: Set wrapper class if any.
139
	if ( ! empty( $field['row_classes'] ) ) {
140
		$field['wrapper_class'] = $field['row_classes'];
141
		unset( $field['row_classes'] );
142
	}
143
144
	// Set field params on basis of cmb2 field name.
145
	switch ( $field['type'] ) {
146
		case 'radio_inline':
147
			if ( empty( $field['wrapper_class'] ) ) {
148
				$field['wrapper_class'] = '';
149
			}
150
			$field['wrapper_class'] .= ' give-inline-radio-fields';
151
152
			break;
153
154
		case 'text':
155
		case 'text-medium':
156
		case 'text_medium':
157
		case 'text-small' :
158
		case 'text_small' :
159
			// CMB2 compatibility: Set field type to text.
160
			$field['type'] = isset( $field['attributes']['type'] ) ? $field['attributes']['type'] : 'text';
161
162
			// CMB2 compatibility: Set data type to price.
163
			if (
164
				empty( $field['data_type'] )
165
				&& ! empty( $field['attributes']['class'] )
166
				&& (
167
					false !== strpos( $field['attributes']['class'], 'money' )
168
					|| false !== strpos( $field['attributes']['class'], 'amount' )
169
				)
170
			) {
171
				$field['data_type'] = 'decimal';
172
			}
173
			break;
174
175
		case 'levels_id':
176
			$field['type'] = 'hidden';
177
			break;
178
179
		case 'colorpicker' :
180
			$field['type']  = 'text';
181
			$field['class'] = 'give-colorpicker';
182
			break;
183
184
		case 'give_default_radio_inline':
185
			$field['type']    = 'radio';
186
			$field['options'] = array(
187
				'default' => __( 'Default' ),
188
			);
189
			break;
190
	}
191
192
	// CMB2 compatibility: Add support to define field description by desc & description param.
193
	// We encourage you to use description param.
194
	$field['description'] = ( ! empty( $field['description'] )
195
		? $field['description']
196
		: ( ! empty( $field['desc'] ) ? $field['desc'] : '' ) );
197
198
	// Call render function.
199
	if ( is_array( $func_name ) ) {
200
		$func_name[0]->$func_name[1]( $field );
201
	} else {
202
		$func_name( $field );
203
	}
204
205
	return true;
206
}
207
208
/**
209
 * Output a text input box.
210
 *
211
 * @since  1.8
212
 * @param  array $field {
213
 *     Optional. Array of text input field arguments.
214
 *
215
 *     @type string             $id              Field ID. Default ''.
216
 *     @type string             $style           CSS style for input field. Default ''.
217
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
218
 *     @type string             $value           Value of input field. Default ''.
219
 *     @type string             $name            Name of input field. Default ''.
220
 *     @type string             $type            Type of input field. Default 'text'.
221
 *     @type string             $before_field    Text/HTML to add before input field. Default ''.
222
 *     @type string             $after_field     Text/HTML to add after input field. Default ''.
223
 *     @type string             $data_type       Define data type for value of input to filter it properly. Default ''.
224
 *     @type string             $description     Description of input field. Default ''.
225
 *     @type array              $attributes      List of attributes of input field. Default array().
226
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
227
 * }
228
 * @return void
229
 */
230
function give_text_input( $field ) {
231
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
232
233
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
234
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
235
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
236
	$field['value']         = give_get_field_value( $field, $thepostid );
237
	$field['type']          = isset( $field['type'] ) ? $field['type'] : 'text';
238
	$field['before_field']  = '';
239
	$field['after_field']   = '';
240
	$data_type              = empty( $field['data_type'] ) ? '' : $field['data_type'];
241
242
	switch ( $data_type ) {
243
		case 'price' :
244
			$field['value'] = ( ! empty( $field['value'] ) ? give_format_amount( $field['value'] ) : $field['value'] );
245
246
			$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>' : '' );
247
			$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>' : '' );
248
			break;
249
250
		case 'decimal' :
251
			$field['attributes']['class'] .= ' give_input_decimal';
252
			$field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( $field['value'] ) : $field['value'] );
253
			break;
254
255
		default :
256
			break;
257
	}
258
259
	?>
260
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
261
		<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
262
		<?php echo $field['before_field']; ?>
263
		<input
264
			type="<?php echo esc_attr( $field['type'] ); ?>"
265
			style="<?php echo esc_attr( $field['style'] ); ?>"
266
			name="<?php echo give_get_field_name( $field ); ?>"
267
			id="<?php echo esc_attr( $field['id'] ); ?>"
268
			value="<?php echo esc_attr( $field['value'] ); ?>"
269
			<?php echo give_get_custom_attributes( $field ); ?>
270
		/>
271
		<?php echo $field['after_field']; ?>
272
	<?php
273
	echo give_get_field_description( $field );
274
	echo '</p>';
275
}
276
277
/**
278
 * Output a hidden input box.
279
 *
280
 * @since  1.8
281
 * @param  array $field {
282
 *     Optional. Array of hidden text input field arguments.
283
 *
284
 *     @type string             $id              Field ID. Default ''.
285
 *     @type string             $value           Value of input field. Default ''.
286
 *     @type string             $name            Name of input field. Default ''.
287
 *     @type string             $type            Type of input field. Default 'text'.
288
 *     @type array              $attributes      List of attributes of input field. Default array().
289
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
290
 * }
291
 * @return void
292
 */
293
function give_hidden_input( $field ) {
294
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
295
296
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
297
	$field['value'] = give_get_field_value( $field, $thepostid );
298
299
	// Custom attribute handling
300
	$custom_attributes = array();
301
302
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
303
304
		foreach ( $field['attributes'] as $attribute => $value ) {
305
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
306
		}
307
	}
308
	?>
309
310
	<input
311
		type="hidden"
312
		name="<?php echo give_get_field_name( $field ); ?>"
313
		id="<?php echo esc_attr( $field['id'] ); ?>"
314
		value="<?php echo esc_attr( $field['value'] ); ?>"
315
		<?php echo give_get_custom_attributes( $field ); ?>
316
	/>
317
	<?php
318
}
319
320
/**
321
 * Output a textarea input box.
322
 *
323
 * @since  1.8
324
 * @since  1.8
325
 * @param  array $field {
326
 *     Optional. Array of textarea input field arguments.
327
 *
328
 *     @type string             $id              Field ID. Default ''.
329
 *     @type string             $style           CSS style for input field. Default ''.
330
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
331
 *     @type string             $value           Value of input field. Default ''.
332
 *     @type string             $name            Name of input field. Default ''.
333
 *     @type string             $description     Description of input field. Default ''.
334
 *     @type array              $attributes      List of attributes of input field. Default array().
335
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
336
 * }
337
 * @return void
338
 */
339
function give_textarea_input( $field ) {
340
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
341
342
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
343
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
344
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
345
	$field['value']         = give_get_field_value( $field, $thepostid );
346
347
	?>
348
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
349
		<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
350
		<textarea
351
			style="<?php echo esc_attr( $field['style'] ); ?>"
352
			name="<?php echo give_get_field_name( $field ); ?>"
353
			id="<?php echo esc_attr( $field['id'] ); ?>"
354
			rows="10"
355
			cols="20"
356
			<?php echo give_get_custom_attributes( $field ); ?>
357
		><?php echo esc_textarea( $field['value'] ); ?></textarea>
358
	<?php
359
	echo give_get_field_description( $field );
360
	echo '</p>';
361
}
362
363
/**
364
 * Output a wysiwyg.
365
 *
366
 * @since  1.8
367
 * @param  array $field {
368
 *     Optional. Array of WordPress editor field arguments.
369
 *
370
 *     @type string             $id              Field ID. Default ''.
371
 *     @type string             $style           CSS style for input field. Default ''.
372
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
373
 *     @type string             $value           Value of input field. Default ''.
374
 *     @type string             $name            Name of input field. Default ''.
375
 *     @type string             $description     Description of input field. Default ''.
376
 *     @type array              $attributes      List of attributes of input field. Default array().
377
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
378
 * }
379
 * @return void
380
 */
381
function give_wysiwyg( $field ) {
382
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
383
384
	$thepostid                = empty( $thepostid ) ? $post->ID : $thepostid;
385
	$field['style']           = isset( $field['style'] ) ? $field['style'] : '';
386
	$field['wrapper_class']   = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
387
	$field['value']           = give_get_field_value( $field, $thepostid );
388
	$field['unique_field_id'] = give_get_field_name( $field );
389
	$editor_attributes        = array(
390
		'textarea_name' => isset( $field['repeatable_field_id'] ) ? $field['repeatable_field_id'] : $field['id'],
391
		'textarea_rows' => '10',
392
		'editor_css'    => esc_attr( $field['style'] ),
393
		'editor_class'  => $field['attributes']['class']
394
	);
395
	$data_wp_editor           = ' data-wp-editor="'. base64_encode( json_encode( array( $field['value'], $field['unique_field_id'],$editor_attributes ) ) ) .'"';
396
	$data_wp_editor           = isset( $field['repeatable_field_id'] ) ? $data_wp_editor : '';
397
398
	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>';
399
400
	wp_editor(
401
		$field['value'],
402
		$field['unique_field_id'],
403
		$editor_attributes
404
	);
405
406
	echo give_get_field_description( $field );
407
	echo '</div>';
408
}
409
410
/**
411
 * Output a checkbox input box.
412
 *
413
 * @since  1.8
414
 * @param  array $field {
415
 *     Optional. Array of checkbox field arguments.
416
 *
417
 *     @type string             $id              Field ID. Default ''.
418
 *     @type string             $style           CSS style for input field. Default ''.
419
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
420
 *     @type string             $value           Value of input field. Default ''.
421
 *     @type string             $cbvalue         Checkbox value. Default 'on'.
422
 *     @type string             $name            Name of input field. Default ''.
423
 *     @type string             $description     Description of input field. Default ''.
424
 *     @type array              $attributes      List of attributes of input field. Default array().
425
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
426
 * }
427
 * @return void
428
 */
429
function give_checkbox( $field ) {
430
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
431
432
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
433
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
434
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
435
	$field['value']         = give_get_field_value( $field, $thepostid );
436
	$field['cbvalue']       = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on';
437
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
438
	?>
439
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
440
		<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
441
		<input
442
			type="checkbox"
443
			style="<?php echo esc_attr( $field['style'] ); ?>"
444
			name="<?php echo give_get_field_name( $field ); ?>"
445
			id="<?php echo esc_attr( $field['id'] ); ?>"
446
			value="<?php echo esc_attr( $field['cbvalue'] ); ?>"
447
			<?php echo checked( $field['value'], $field['cbvalue'], false ); ?>
448
			<?php echo give_get_custom_attributes( $field ); ?>
449
		/>
450
	<?php
451
	echo give_get_field_description( $field );
452
	echo '</p>';
453
}
454
455
/**
456
 * Output a select input box.
457
 *
458
 * @since  1.8
459
 * @param  array $field {
460
 *     Optional. Array of select field arguments.
461
 *
462
 *     @type string             $id              Field ID. Default ''.
463
 *     @type string             $style           CSS style for input field. Default ''.
464
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
465
 *     @type string             $value           Value of input field. Default ''.
466
 *     @type string             $name            Name of input field. Default ''.
467
 *     @type string             $description     Description of input field. Default ''.
468
 *     @type array              $attributes      List of attributes of input field. Default array().
469
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
470
 *     @type array              $options         List of options. Default array().
471
 *                                               for example: 'options' => array( '' => 'None', 'yes' => 'Yes' )
472
 * }
473
 * @return void
474
 */
475
function give_select( $field ) {
476
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
477
478
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
479
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
480
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
481
	$field['value']         = give_get_field_value( $field, $thepostid );
482
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
483
	?>
484
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
485
		<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
486
		<select
487
			id="<?php echo esc_attr( $field['id'] ); ?>"
488
			name="<?php echo give_get_field_name( $field ); ?>"
489
			style="<?php echo esc_attr( $field['style'] ) ?>"
490
			<?php echo give_get_custom_attributes( $field ); ?>
491
		>
492
	<?php
493
	foreach ( $field['options'] as $key => $value ) {
494
		echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
495
	}
496
	echo '</select>';
497
	echo give_get_field_description( $field );
498
	echo '</p>';
499
}
500
501
/**
502
 * Output a radio input box.
503
 *
504
 * @since  1.8
505
 * @param  array $field {
506
 *     Optional. Array of radio field arguments.
507
 *
508
 *     @type string             $id              Field ID. Default ''.
509
 *     @type string             $style           CSS style for input field. Default ''.
510
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
511
 *     @type string             $value           Value of input field. Default ''.
512
 *     @type string             $name            Name of input field. Default ''.
513
 *     @type string             $description     Description of input field. Default ''.
514
 *     @type array              $attributes      List of attributes of input field. Default array().
515
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
516
 *     @type array              $options         List of options. Default array().
517
 *                                               for example: 'options' => array( 'enable' => 'Enable', 'disable' => 'Disable' )
518
 * }
519
 * @return void
520
 */
521
function give_radio( $field ) {
522
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
523
524
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
525
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
526
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
527
	$field['value']         = give_get_field_value( $field, $thepostid );
528
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
529
530
	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">';
531
532
	foreach ( $field['options'] as $key => $value ) {
533
534
		echo '<li><label><input
535
				name="' . give_get_field_name( $field ) . '"
536
				value="' . esc_attr( $key ) . '"
537
				type="radio"
538
				style="' . esc_attr( $field['style'] ) . '"
539
				' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' '
540
				. give_get_custom_attributes( $field ) . '
541
				/> ' . esc_html( $value ) . '</label>
542
		</li>';
543
	}
544
	echo '</ul>';
545
546
	echo give_get_field_description( $field );
547
	echo '</fieldset>';
548
}
549
550
/**
551
 * Output a colorpicker.
552
 *
553
 * @since  1.8
554
 * @param  array $field {
555
 *     Optional. Array of colorpicker field arguments.
556
 *
557
 *     @type string             $id              Field ID. Default ''.
558
 *     @type string             $style           CSS style for input field. Default ''.
559
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
560
 *     @type string             $value           Value of input field. Default ''.
561
 *     @type string             $name            Name of input field. Default ''.
562
 *     @type string             $description     Description of input field. Default ''.
563
 *     @type array              $attributes      List of attributes of input field. Default array().
564
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
565
 * }
566
 * @return void
567
 */
568
function give_colorpicker( $field ) {
569
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
570
571
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
572
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
573
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
574
	$field['value']         = give_get_field_value( $field, $thepostid );
575
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
576
	$field['type']          = 'text';
577
	?>
578
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
579
		<label for="<?php echo give_get_field_name( $field ); ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
580
		<input
581
			type="<?php echo esc_attr( $field['type'] ); ?>"
582
			style="<?php echo esc_attr( $field['style'] ); ?>"
583
			name="<?php echo give_get_field_name( $field ); ?>"
584
			id="' . esc_attr( $field['id'] ) . '" value="<?php echo esc_attr( $field['value'] ); ?>"
585
			<?php echo give_get_custom_attributes( $field ); ?>
586
		/>
587
	<?php
588
	echo give_get_field_description( $field );
589
	echo '</p>';
590
}
591
592
593
/**
594
 * Output a media upload field.
595
 *
596
 * @since  1.8
597
 *
598
 * @param array $field
599
 *
600
 */
601
function give_media( $field ) {
602
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
603
604
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
605
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
606
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
607
	$field['value']         = give_get_field_value( $field, $thepostid );
608
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
609
	$field['type']          = 'text';
610
	$field['attributes']['class'] = "{$field['attributes']['class']} give-text-medium";
611
612
	// Allow developer to save attachment ID or attachment url as metadata.
613
	$field['fvalue']        = isset( $field['fvalue'] ) ? $field['fvalue'] : 'url';
614
	?>
615
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
616
		<label for="<?php echo give_get_field_name( $field ) ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
617
		<input
618
			name="<?php echo give_get_field_name( $field ); ?>"
619
			id="<?php echo esc_attr( $field['id'] ); ?>"
620
			type="text"
621
			value="<?php echo $field['value']; ?>"
622
			style="<?php echo esc_attr( $field['style'] ); ?>"
623
			data-fvalue="<?php echo $field['fvalue']; ?>"
624
			<?php echo give_get_custom_attributes( $field ); ?>
625
		/>&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-media-upload button" type="button" value="<?php echo esc_html__( 'Add or Upload File', 'give' ); ?>">
626
		<?php echo give_get_field_description( $field ); ?>
627
	</p>
628
	<?php
629
}
630
631
/**
632
 * Output a select field with payment options list.
633
 *
634
 * @since  1.8
635
 *
636
 * @param  array $field
637
 *
638
 * @return void
639
 */
640
function give_default_gateway( $field ) {
641
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
642
643
	// get all active payment gateways.
644
	$gateways         = give_get_enabled_payment_gateways( $thepostid );
645
	$field['options'] = array();
646
647
	// Set field option value.
648
	if( ! empty( $gateways ) ) {
649
		foreach ( $gateways as $key => $option ) {
650
			$field['options'][ $key ] = $option['admin_label'];
651
		}
652
	}
653
654
	//Add a field to the Give Form admin single post view of this field
655
	if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
656
		$field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] );
657
	}
658
659
	// Render select field.
660
	give_select( $field );
661
}
662
663
/**
664
  * Output the documentation link.
665
  *
666
  * @since  1.8
667
  * @param  array $field {
668
  *     Optional. Array of customizable link attributes.
669
  *
670
  *     @type string             $name            Name of input field. Default ''.
671
  *     @type string             $type            Type of input field. Default 'text'.
672
  *     @type string             $url             Value to be passed as a link. Default 'https://givewp.com/documentation'.
673
  *     @type string             $title           Value to be passed as text of link. Default 'Documentation'.
674
  *     @type array              $attributes      List of attributes of input field. Default array().
675
  *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
676
  * }
677
  * @return void
678
*/
679
680
function give_docs_link($field) {
681
	$field['url']   = isset($field['url']) ? $field['url'] : 'https://givewp.com/documentation';
682
	$field['title'] = isset($field['title']) ? $field['title'] : 'Documentation';
683
684
	echo '<p class="give-docs-link"><a href="' . esc_url($field['url'])
685
		. '" target="_blank">'
686
		. sprintf(esc_html__('Need Help? See docs on "%s"'), $field['title'])
687
		. '<span class="dashicons dashicons-editor-help"></span></a></p>';
688
}
689
690
/**
691
 * Get setting field value.
692
 *
693
 * Note: Use only for single post, page or custom post type.
694
 *
695
 * @since  1.8
696
 *
697
 * @param  array $field
698
 * @param  int   $postid
699
 *
700
 * @return mixed
701
 */
702
function give_get_field_value( $field, $postid ) {
703
	if ( isset( $field['attributes']['value'] ) ) {
704
		return $field['attributes']['value'];
705
	}
706
707
	// Get value from db.
708
	$field_value = get_post_meta( $postid, $field['id'], true );
709
710
	/**
711
	 * Filter the field value before apply default value.
712
	 *
713
	 * @since 1.8
714
	 *
715
	 * @param mixed $field_value Field value.
716
	 */
717
	$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
718
719
720
	// Set default value if no any data saved to db.
721
	if ( ! $field_value && isset( $field['default'] ) ) {
722
		$field_value = $field['default'];
723
	}
724
725
	return $field_value;
726
}
727
728
729
/**
730
 * Get field description html.
731
 *
732
 * @since 1.8
733
 * @param $field
734
 *
735
 * @return string
736
 */
737
function give_get_field_description( $field ) {
738
	$field_desc_html = '';
739
	if ( ! empty( $field['description'] ) ) {
740
		$field_desc_html = '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
741
	}
742
743
	return $field_desc_html;
744
}
745
746
747
/**
748
 * Get field custom attributes as string.
749
 *
750
 * @since 1.8
751
 * @param $field
752
 *
753
 * @return string
754
 */
755
function give_get_custom_attributes( $field ) {
756
	// Custom attribute handling
757
	$custom_attributes = array();
758
759
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
760
761
		foreach ( $field['attributes'] as $attribute => $value ) {
762
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
763
		}
764
	}
765
766
	return implode( ' ', $custom_attributes );
767
}
768
769
/**
770
 * Get repeater field value.
771
 *
772
 * Note: Use only for single post, page or custom post type.
773
 *
774
 * @since  1.8
775
 *
776
 * @param array $field
777
 * @param array $field_group
778
 * @param array $fields
779
 *
780
 * @return string
781
 */
782
function give_get_repeater_field_value( $field, $field_group, $fields ) {
783
	$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
784
785
	/**
786
	 * Filter the specific repeater field value
787
	 *
788
	 * @since 1.8
789
	 *
790
	 * @param string $field_id
791
	 */
792
	$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
793
794
	/**
795
	 * Filter the repeater field value
796
	 *
797
	 * @since 1.8
798
	 *
799
	 * @param string $field_id
800
	 */
801
	$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
802
803
	return $field_value;
804
}
805
806
/**
807
 * Get repeater field id.
808
 *
809
 * Note: Use only for single post, page or custom post type.
810
 *
811
 * @since  1.8
812
 *
813
 * @param array    $field
814
 * @param array    $fields
815
 * @param int|bool $default
816
 *
817
 * @return string
818
 */
819
function give_get_repeater_field_id( $field, $fields, $default = false ) {
820
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
821
822
	// Get field id.
823
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
824
825
	/**
826
	 * Filter the specific repeater field id
827
	 *
828
	 * @since 1.8
829
	 *
830
	 * @param string $field_id
831
	 */
832
	$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
833
834
835
	/**
836
	 * Filter the repeater field id
837
	 *
838
	 * @since 1.8
839
	 *
840
	 * @param string $field_id
841
	 */
842
	$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
843
844
	return $field_id;
845
}
846
847
848
/**
849
 * Get field name.
850
 *
851
 * @since  1.8
852
 *
853
 * @param  array $field
854
 *
855
 * @return string
856
 */
857
function give_get_field_name( $field ) {
858
	$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
859
860
	/**
861
	 * Filter the field name.
862
	 *
863
	 * @since 1.8
864
	 *
865
	 * @param string $field_name
866
	 */
867
	$field_name = apply_filters( 'give_get_field_name', $field_name, $field );
868
869
	return $field_name;
870
}
871
872
/**
873
 * Output repeater field or multi donation type form on donation from edit screen.
874
 * Note: internal use only.
875
 * @TODO   : Add support for wysiwyg type field.
876
 *
877
 * @since  1.8
878
 *
879
 * @param  array $fields
880
 *
881
 * @return void
882
 */
883
function _give_metabox_form_data_repeater_fields( $fields ) {
884
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
885
886
	// Bailout.
887
	if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) {
888
		return;
889
	}
890
891
	$group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0;
892
	$close_tabs      = isset( $fields['options']['close_tabs'] )      ? (int) $fields['options']['close_tabs']      : 0;
893
	?>
894
	<div class="give-repeatable-field-section" id="<?php echo "{$fields['id']}_field"; ?>" data-group-numbering="<?php echo $group_numbering; ?>" data-close-tabs="<?php echo $close_tabs; ?>">
895
		<?php if ( ! empty( $fields['name'] ) ) : ?>
896
			<p class="give-repeater-field-name"><?php echo $fields['name']; ?></p>
897
		<?php endif; ?>
898
899
		<?php if ( ! empty( $fields['description'] ) ) : ?>
900
			<p class="give-repeater-field-description"><?php echo $fields['description']; ?></p>
901
		<?php endif; ?>
902
903
		<table class="give-repeatable-fields-section-wrapper" cellspacing="0">
904
			<?php
905
			$repeater_field_values = get_post_meta( $thepostid, $fields['id'], true );
906
			$header_title          = isset( $fields['options']['header_title'] )
907
				? $fields['options']['header_title']
908
				: esc_attr__( 'Group', 'give' );
909
910
			$add_default_donation_field = false;
911
912
			// Check if level is not created or we have to add default level.
913
			if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) {
914
				$repeater_field_values = array_values( $repeater_field_values );
915
			} else {
916
				$fields_count               = 1;
917
				$add_default_donation_field = true;
918
			}
919
			?>
920
			<tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>>
921
				<!--Repeater field group template-->
922
				<tr class="give-template give-row">
923
					<td class="give-repeater-field-wrap give-column" colspan="2">
924
						<div class="give-row-head give-move">
925
							<button type="button" class="handlediv button-link"><span class="toggle-indicator"></span>
926
							</button>
927
							<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span>
928
							<h2>
929
								<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
930
							</h2>
931
						</div>
932
						<div class="give-row-body">
933
							<?php foreach ( $fields['fields'] as $field ) : ?>
934
								<?php if ( ! give_is_field_callback_exist( $field ) ) {
935
									continue;
936
								} ?>
937
								<?php
938
								$field['repeat']              = true;
939
								$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields );
940
								$field['id']                  = str_replace( array( '[', ']' ), array(
941
									'_',
942
									'',
943
								), $field['repeatable_field_id'] );
944
								?>
945
								<?php give_render_field( $field ); ?>
946
							<?php endforeach; ?>
947
						</div>
948
					</td>
949
				</tr>
950
951
				<?php if ( ! empty( $repeater_field_values ) ) : ?>
952
					<!--Stored repeater field group-->
953
					<?php foreach ( $repeater_field_values as $index => $field_group ) : ?>
954
						<tr class="give-row">
955
							<td class="give-repeater-field-wrap give-column" colspan="2">
956
								<div class="give-row-head give-move">
957
									<button type="button" class="handlediv button-link">
958
										<span class="toggle-indicator"></span></button>
959
									<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
960
									</sapn>
961
									<h2>
962
										<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
963
									</h2>
964
								</div>
965
								<div class="give-row-body">
966
									<?php foreach ( $fields['fields'] as $field ) : ?>
967
										<?php if ( ! give_is_field_callback_exist( $field ) ) {
968
											continue;
969
										} ?>
970
										<?php
971
										$field['repeat']              = true;
972
										$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index );
973
										$field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields );
974
										$field['id']                  = str_replace( array( '[', ']' ), array(
975
											'_',
976
											'',
977
										), $field['repeatable_field_id'] );
978
										?>
979
										<?php give_render_field( $field ); ?>
980
									<?php endforeach; ?>
981
								</div>
982
							</td>
983
						</tr>
984
					<?php endforeach;; ?>
985
986
				<?php elseif ( $add_default_donation_field ) : ?>
987
					<!--Default repeater field group-->
988
					<tr class="give-row">
989
						<td class="give-repeater-field-wrap give-column" colspan="2">
990
							<div class="give-row-head give-move">
991
								<button type="button" class="handlediv button-link">
992
									<span class="toggle-indicator"></span></button>
993
								<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
994
								</sapn>
995
								<h2>
996
									<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
997
								</h2>
998
							</div>
999
							<div class="give-row-body">
1000
								<?php
1001
								foreach ( $fields['fields'] as $field ) :
1002
									if ( ! give_is_field_callback_exist( $field ) ) {
1003
										continue;
1004
									}
1005
1006
									$field['repeat']              = true;
1007
									$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 );
1008
									$field['attributes']['value'] = apply_filters( "give_default_field_group_field_{$field['id']}_value", ( ! empty( $field['default'] ) ? $field['default'] : '' ), $field );
1009
									$field['id']                  = str_replace( array( '[', ']' ), array(
1010
										'_',
1011
										'',
1012
									), $field['repeatable_field_id'] );
1013
									give_render_field( $field );
1014
								endforeach;
1015
								?>
1016
							</div>
1017
						</td>
1018
					</tr>
1019
				<?php endif; ?>
1020
			</tbody>
1021
			<tfoot>
1022
				<tr>
1023
					<?php
1024
					$add_row_btn_title = isset( $fields['options']['add_button'] )
1025
						? $add_row_btn_title = $fields['options']['add_button']
1026
						: esc_html__( 'Add Row', 'give' );
1027
					?>
1028
					<td colspan="2" class="give-add-repeater-field-section-row-wrap">
1029
						<span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span>
1030
					</td>
1031
				</tr>
1032
			</tfoot>
1033
		</table>
1034
	</div>
1035
	<?php
1036
}
1037
1038
1039
/**
1040
 * Get current setting tab.
1041
 *
1042
 * @since  1.8
1043
 * @return string
1044
 */
1045
function give_get_current_setting_tab() {
1046
	// Get current setting page.
1047
	$current_setting_page = give_get_current_setting_page();
1048
1049
	/**
1050
	 * Filter the default tab for current setting page.
1051
	 *
1052
	 * @since 1.8
1053
	 *
1054
	 * @param string
1055
	 */
1056
	$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' );
1057
1058
	// Get current tab.
1059
	$current_tab = empty( $_GET['tab'] ) ? $default_current_tab : urldecode( $_GET['tab'] );
1060
1061
	// Output.
1062
	return $current_tab;
1063
}
1064
1065
1066
/**
1067
 * Get current setting section.
1068
 *
1069
 * @since  1.8
1070
 * @return string
1071
 */
1072
function give_get_current_setting_section() {
1073
	// Get current tab.
1074
	$current_tab = give_get_current_setting_tab();
1075
1076
	/**
1077
	 * Filter the default section for current setting page tab.
1078
	 *
1079
	 * @since 1.8
1080
	 *
1081
	 * @param string
1082
	 */
1083
	$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' );
1084
1085
	// Get current section.
1086
	$current_section = empty( $_REQUEST['section'] ) ? $default_current_section : urldecode( $_REQUEST['section'] );
1087
1088
	//Output.
1089
	return $current_section;
1090
}
1091
1092
/**
1093
 * Get current setting page.
1094
 *
1095
 * @since  1.8
1096
 * @return string
1097
 */
1098
function give_get_current_setting_page() {
1099
	// Get current page.
1100
	$setting_page = ! empty( $_GET['page'] ) ? urldecode( $_GET['page'] ) : '';
1101
1102
	//Output.
1103
	return $setting_page;
1104
}
1105
1106
/**
1107
 * Set value for Form content --> Display content field setting.
1108
 *
1109
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_display_content is not set yet.
1110
 *
1111
 * @since  1.8
1112
 *
1113
 * @param  mixed $field_value Field Value.
1114
 * @param  array $field       Field args.
1115
 * @param  int   $postid      Form/Post ID.
1116
 *
1117
 * @return string
1118
 */
1119
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...
1120
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1121
1122
	if (
1123
		! get_post_meta( $postid, '_give_display_content', true )
1124
		&& $show_content
1125
		&& ( 'none' !== $show_content )
1126
	) {
1127
		$field_value = 'enabled';
1128
	}
1129
1130
	return $field_value;
1131
}
1132
1133
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 );
1134
1135
1136
/**
1137
 * Set value for Form content --> Content placement field setting.
1138
 *
1139
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_content_placement is not set yet.
1140
 *
1141
 * @since  1.8
1142
 *
1143
 * @param  mixed $field_value Field Value.
1144
 * @param  array $field       Field args.
1145
 * @param  int   $postid      Form/Post ID.
1146
 *
1147
 * @return string
1148
 */
1149
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...
1150
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1151
1152
	if (
1153
		! get_post_meta( $postid, '_give_content_placement', true )
1154
		&& ( 'none' !== $show_content )
1155
	) {
1156
		$field_value = $show_content;
1157
	}
1158
1159
	return $field_value;
1160
}
1161
1162
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 );
1163
1164
1165
/**
1166
 * Set value for Terms and Conditions --> Terms and Conditions field setting.
1167
 *
1168
 * Backward compatibility:  set value by _give_terms_option form meta field value if it's value is none.
1169
 *
1170
 * @since  1.8
1171
 *
1172
 * @param  mixed $field_value Field Value.
1173
 * @param  array $field       Field args.
1174
 * @param  int   $postid      Form/Post ID.
1175
 *
1176
 * @return string
1177
 */
1178
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...
1179
	$term_option = get_post_meta( $postid, '_give_terms_option', true );
1180
1181
	if ( in_array( $term_option, array( 'none', 'yes' ) ) ) {
1182
		$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' );
1183
	}
1184
1185
	return $field_value;
1186
}
1187
1188
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 );
1189
1190
1191
/**
1192
 * Set value for Form Display --> Offline Donation --> Billing Fields.
1193
 *
1194
 * Backward compatibility:  set value by _give_offline_donation_enable_billing_fields_single form meta field value if it's value is on.
1195
 *
1196
 * @since  1.8
1197
 *
1198
 * @param  mixed $field_value Field Value.
1199
 * @param  array $field       Field args.
1200
 * @param  int   $postid      Form/Post ID.
1201
 *
1202
 * @return string
1203
 */
1204
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...
1205
	$offline_donation = get_post_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true );
1206
1207
	if ( 'on' === $offline_donation ) {
1208
		$field_value = 'enabled';
1209
	}
1210
1211
	return $field_value;
1212
}
1213
1214
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 );
1215
1216
1217
/**
1218
 * Set value for Donation Options --> Custom Amount.
1219
 *
1220
 * Backward compatibility:  set value by _give_custom_amount form meta field value if it's value is yes or no.
1221
 *
1222
 * @since  1.8
1223
 *
1224
 * @param  mixed $field_value Field Value.
1225
 * @param  array $field       Field args.
1226
 * @param  int   $postid      Form/Post ID.
1227
 *
1228
 * @return string
1229
 */
1230
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...
1231
	$custom_amount = get_post_meta( $postid, '_give_custom_amount', true );
1232
1233
	if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) {
1234
		$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' );
1235
	}
1236
1237
	return $field_value;
1238
}
1239
1240
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 );
1241
1242
1243
/**
1244
 * Set value for Donation Goal --> Donation Goal.
1245
 *
1246
 * Backward compatibility:  set value by _give_goal_option form meta field value if it's value is yes or no.
1247
 *
1248
 * @since  1.8
1249
 *
1250
 * @param  mixed $field_value Field Value.
1251
 * @param  array $field       Field args.
1252
 * @param  int   $postid      Form/Post ID.
1253
 *
1254
 * @return string
1255
 */
1256
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...
1257
	$goal_option = get_post_meta( $postid, '_give_goal_option', true );
1258
1259
	if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) {
1260
		$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' );
1261
	}
1262
1263
	return $field_value;
1264
}
1265
1266
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 );
1267
1268
/**
1269
 * Set value for Donation Goal --> close Form.
1270
 *
1271
 * Backward compatibility:  set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes or no.
1272
 *
1273
 * @since  1.8
1274
 *
1275
 * @param  mixed $field_value Field Value.
1276
 * @param  array $field       Field args.
1277
 * @param  int   $postid      Form/Post ID.
1278
 *
1279
 * @return string
1280
 */
1281
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...
1282
	$close_form = get_post_meta( $postid, '_give_close_form_when_goal_achieved', true );
1283
1284
	if ( in_array( $close_form, array( 'yes', 'no' ) ) ) {
1285
		$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' );
1286
	}
1287
1288
	return $field_value;
1289
}
1290
1291
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 );
1292
1293
1294
/**
1295
 * Set value for Form display --> Guest Donation.
1296
 *
1297
 * Backward compatibility:  set value by _give_logged_in_only form meta field value if it's value is yes or no.
1298
 *
1299
 * @since  1.8
1300
 *
1301
 * @param  mixed $field_value Field Value.
1302
 * @param  array $field       Field args.
1303
 * @param  int   $postid      Form/Post ID.
1304
 *
1305
 * @return string
1306
 */
1307
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...
1308
	$guest_donation = get_post_meta( $postid, '_give_logged_in_only', true );
1309
1310
	if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) {
1311
		$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' );
1312
	}
1313
1314
	return $field_value;
1315
}
1316
1317
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 );
1318
1319
/**
1320
 * Set value for Offline Donations --> Offline Donations.
1321
 *
1322
 * Backward compatibility:  set value by _give_customize_offline_donations form meta field value if it's value is yes or no.
1323
 *
1324
 * @since  1.8
1325
 *
1326
 * @param  mixed $field_value Field Value.
1327
 * @param  array $field       Field args.
1328
 * @param  int   $postid      Form/Post ID.
1329
 *
1330
 * @return string
1331
 */
1332
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...
1333
	$customize_offline_text = get_post_meta( $postid, '_give_customize_offline_donations', true );
1334
1335
	if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) {
1336
		$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' );
1337
	}
1338
1339
	return $field_value;
1340
}
1341
1342
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 );
1343
1344
1345
/**
1346
 * Set repeater field id for multi donation form.
1347
 *
1348
 * @since 1.8
1349
 *
1350
 * @param int   $field_id
1351
 * @param array $field
1352
 * @param array $fields
1353
 * @param bool  $default
1354
 *
1355
 * @return mixed
1356
 */
1357
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...
1358
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1359
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1360
1361
	return $field_id;
1362
}
1363
1364
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1365
1366
/**
1367
 * Set repeater field value for multi donation form.
1368
 *
1369
 * @since 1.8
1370
 *
1371
 * @param string $field_value
1372
 * @param array  $field
1373
 * @param array  $field_group
1374
 * @param array  $fields
1375
 *
1376
 * @return mixed
1377
 */
1378
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...
1379
	$field_value = $field_group[ $field['id'] ]['level_id'];
1380
1381
	return $field_value;
1382
}
1383
1384
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1385
1386
/**
1387
 * Set default value for _give_id field.
1388
 *
1389
 * @since 1.8
1390
 *
1391
 * @param $field
1392
 *
1393
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1394
 */
1395
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...
1396
	return 0;
1397
}
1398
1399
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1400
1401
/**
1402
 * Set default value for _give_default field.
1403
 *
1404
 * @since 1.8
1405
 *
1406
 * @param $field
1407
 *
1408
 * @return string
1409
 */
1410
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...
1411
	return 'default';
1412
}
1413
1414
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1415
1416
/**
1417
 * Set repeater field editor id for field type wysiwyg.
1418
 *
1419
 * @since 1.8
1420
 *
1421
 * @param $field_name
1422
 * @param $field
1423
 *
1424
 * @return string
1425
 */
1426
function give_repeater_field_set_editor_id( $field_name, $field ) {
1427
	if ( isset( $field['repeatable_field_id'] ) &&  'wysiwyg' == $field['type'] ) {
1428
		$field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1429
	}
1430
1431
	return $field_name;
1432
}
1433
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );