Completed
Push — hotfix/fix_notices ( b1c4c9 )
by Ravinder
21:03
created

give-metabox-functions.php ➔ give_radio()   D

Complexity

Conditions 10
Paths 128

Size

Total Lines 41
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 24
nc 128
nop 1
dl 0
loc 41
rs 4.606
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
			$func_name = "{$func_name_prefix}_{$field['type']}";
79
	}
80
81
	$func_name = apply_filters( 'give_setting_callback', $func_name, $field );
82
83
	// Check if render callback exist or not.
84
	if ( ! function_exists( "$func_name" ) || empty( $func_name ) ) {
85
		return false;
86
	}
87
88
	return apply_filters( 'give_setting_callback', $func_name, $field );
89
}
90
91
/**
92
 * This function add backward compatibility to render cmb2 type field type.
93
 *
94
 * @since  1.8
95
 *
96
 * @param  array $field Field argument array.
97
 *
98
 * @return bool
99
 */
100
function give_render_field( $field ) {
101
	$func_name = give_get_field_callback( $field );
102
103
	// Check if render callback exist or not.
104
	if ( ! $func_name ) {
105
		return false;
106
	}
107
108
	// CMB2 compatibility: Push all classes to attributes's class key
109
	if ( empty( $field['class'] ) ) {
110
		$field['class'] = '';
111
	}
112
113
	if ( empty( $field['attributes']['class'] ) ) {
114
		$field['attributes']['class'] = '';
115
	}
116
117
	$field['attributes']['class'] = trim( "give-field {$field['attributes']['class']} give-{$field['type']} {$field['class']}" );
118
	unset( $field['class'] );
119
120
121
	// CMB2 compatibility: Set wrapper class if any.
122
	if ( ! empty( $field['row_classes'] ) ) {
123
		$field['wrapper_class'] = $field['row_classes'];
124
		unset( $field['row_classes'] );
125
	}
126
127
	// Set field params on basis of cmb2 field name.
128
	switch ( $field['type'] ) {
129
		case 'radio_inline':
130
			if ( empty( $field['wrapper_class'] ) ) {
131
				$field['wrapper_class'] = '';
132
			}
133
			$field['wrapper_class'] .= ' give-inline-radio-fields';
134
135
			break;
136
137
		case 'text':
138
		case 'text-medium':
139
		case 'text_medium':
140
		case 'text-small' :
141
		case 'text_small' :
142
			// CMB2 compatibility: Set field type to text.
143
			$field['type'] = isset( $field['attributes']['type'] ) ? $field['attributes']['type'] : 'text';
144
145
			// CMB2 compatibility: Set data type to price.
146
			if (
147
				empty( $field['data_type'] )
148
				&& ! empty( $field['attributes']['class'] )
149
				&& (
150
					false !== strpos( $field['attributes']['class'], 'money' )
151
					|| false !== strpos( $field['attributes']['class'], 'amount' )
152
				)
153
			) {
154
				$field['data_type'] = 'decimal';
155
			}
156
			break;
157
158
		case 'levels_id':
159
			$field['type'] = 'hidden';
160
			break;
161
162
		case 'colorpicker' :
163
			$field['type']  = 'text';
164
			$field['class'] = 'give-colorpicker';
165
			break;
166
167
		case 'give_default_radio_inline':
168
			$field['type']    = 'radio';
169
			$field['options'] = array(
170
				'default' => __( 'Default' ),
171
			);
172
			break;
173
	}
174
175
	// CMB2 compatibility: Add support to define field description by desc & description param.
176
	// We encourage you to use description param.
177
	$field['description'] = ( ! empty( $field['description'] )
178
		? $field['description']
179
		: ( ! empty( $field['desc'] ) ? $field['desc'] : '' ) );
180
181
	// Call render function.
182
	$func_name( $field );
183
184
	return true;
185
}
186
187
/**
188
 * Output a text input box.
189
 *
190
 * @since  1.8
191
 * @param  array $field {
192
 *     Optional. Array of text input field arguments.
193
 *
194
 *     @type string             $id              Field ID. Default ''.
195
 *     @type string             $style           CSS style for input field. Default ''.
196
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
197
 *     @type string             $value           Value of input field. Default ''.
198
 *     @type string             $name            Name of input field. Default ''.
199
 *     @type string             $type            Type of input field. Default 'text'.
200
 *     @type string             $before_field    Text/HTML to add before input field. Default ''.
201
 *     @type string             $after_field     Text/HTML to add after input field. Default ''.
202
 *     @type string             $data_type       Define data type for value of input to filter it properly. Default ''.
203
 *     @type string             $description     Description of input field. Default ''.
204
 *     @type array              $attributes      List of attributes of input field. Default array().
205
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
206
 * }
207
 * @return void
208
 */
209
function give_text_input( $field ) {
210
	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...
211
212
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
213
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
214
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
215
	$field['value']         = give_get_field_value( $field, $thepostid );
216
	$field['type']          = isset( $field['type'] ) ? $field['type'] : 'text';
217
	$field['before_field']  = '';
218
	$field['after_field']   = '';
219
	$data_type              = empty( $field['data_type'] ) ? '' : $field['data_type'];
220
221
	switch ( $data_type ) {
222
		case 'price' :
223
			$field['value'] = ( ! empty( $field['value'] ) ? give_format_amount( $field['value'] ) : $field['value'] );
224
225
			$field['before_field'] = ! empty( $field['before_field'] ) ? $field['before_field'] : ( give_get_option( 'currency_position' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '' );
226
			$field['after_field']  = ! empty( $field['after_field'] ) ? $field['after_field'] : ( give_get_option( 'currency_position' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '' );
227
			break;
228
229
		case 'decimal' :
230
			$field['attributes']['class'] .= ' give_input_decimal';
231
			$field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( $field['value'] ) : $field['value'] );
232
			break;
233
234
		default :
235
			break;
236
	}
237
238
	// Custom attribute handling
239
	$custom_attributes = array();
240
241
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
242
243
		foreach ( $field['attributes'] as $attribute => $value ) {
244
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
245
		}
246
	}
247
248
	echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label>' . $field['before_field'] . '<input type="' . esc_attr( $field['type'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . give_get_field_name( $field ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" ' . implode( ' ', $custom_attributes ) . ' />' . $field['after_field'];
249
250
	if ( ! empty( $field['description'] ) ) {
251
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
252
	}
253
	echo '</p>';
254
}
255
256
/**
257
 * Output a hidden input box.
258
 *
259
 * @since  1.8
260
 * @param  array $field {
261
 *     Optional. Array of hidden text input field arguments.
262
 *
263
 *     @type string             $id              Field ID. Default ''.
264
 *     @type string             $value           Value of input field. Default ''.
265
 *     @type string             $name            Name of input field. Default ''.
266
 *     @type string             $type            Type of input field. Default 'text'.
267
 *     @type array              $attributes      List of attributes of input field. Default array().
268
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
269
 * }
270
 * @return void
271
 */
272
function give_hidden_input( $field ) {
273
	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...
274
275
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
276
	$field['value'] = give_get_field_value( $field, $thepostid );
277
278
	// Custom attribute handling
279
	$custom_attributes = array();
280
281
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
282
283
		foreach ( $field['attributes'] as $attribute => $value ) {
284
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
285
		}
286
	}
287
288
	echo '<input type="hidden" name="' . give_get_field_name( $field ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" ' . implode( ' ', $custom_attributes ) . '/> ';
289
}
290
291
/**
292
 * Output a textarea input box.
293
 *
294
 * @since  1.8
295
 * @since  1.8
296
 * @param  array $field {
297
 *     Optional. Array of textarea input field arguments.
298
 *
299
 *     @type string             $id              Field ID. Default ''.
300
 *     @type string             $style           CSS style for input field. Default ''.
301
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
302
 *     @type string             $value           Value of input field. Default ''.
303
 *     @type string             $name            Name of input field. 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
 * @return void
309
 */
310
function give_textarea_input( $field ) {
311
	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...
312
313
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
314
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
315
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
316
	$field['value']         = give_get_field_value( $field, $thepostid );
317
318
	// Custom attribute handling
319
	$custom_attributes = array();
320
321
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
322
323
		foreach ( $field['attributes'] as $attribute => $value ) {
324
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
325
		}
326
	}
327
328
	echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label><textarea style="' . esc_attr( $field['style'] ) . '"  name="' . give_get_field_name( $field ) . '" id="' . esc_attr( $field['id'] ) . '" rows="10" cols="20" ' . implode( ' ', $custom_attributes ) . '>' . esc_textarea( $field['value'] ) . '</textarea> ';
329
330
	if ( ! empty( $field['description'] ) ) {
331
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
332
	}
333
	echo '</p>';
334
}
335
336
/**
337
 * Output a wysiwyg.
338
 *
339
 * @since  1.8
340
 * @param  array $field {
341
 *     Optional. Array of WordPress editor field arguments.
342
 *
343
 *     @type string             $id              Field ID. Default ''.
344
 *     @type string             $style           CSS style for input field. Default ''.
345
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
346
 *     @type string             $value           Value of input field. Default ''.
347
 *     @type string             $name            Name of input field. Default ''.
348
 *     @type string             $description     Description of input field. Default ''.
349
 *     @type array              $attributes      List of attributes of input field. Default array().
350
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
351
 * }
352
 * @return void
353
 */
354
function give_wysiwyg( $field ) {
355
	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...
356
357
	$thepostid                = empty( $thepostid ) ? $post->ID : $thepostid;
358
	$field['style']           = isset( $field['style'] ) ? $field['style'] : '';
359
	$field['wrapper_class']   = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
360
	$field['value']           = give_get_field_value( $field, $thepostid );
361
	$field['unique_field_id'] = give_get_field_name( $field );
362
	$editor_attributes        = array(
363
		'textarea_name' => isset( $field['repeatable_field_id'] ) ? $field['repeatable_field_id'] : $field['id'],
364
		'textarea_rows' => '10',
365
		'editor_css'    => esc_attr( $field['style'] ),
366
		'editor_class'  => $field['attributes']['class']
367
	);
368
	$data_wp_editor           = ' data-wp-editor="'. base64_encode( json_encode( array( $field['value'], $field['unique_field_id'],$editor_attributes ) ) ) .'"';
369
	$data_wp_editor           = isset( $field['repeatable_field_id'] ) ? $data_wp_editor : '';
370
371
	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>';
372
373
	wp_editor(
374
		$field['value'],
375
		$field['unique_field_id'],
376
		$editor_attributes
377
	);
378
379
	if ( ! empty( $field['description'] ) ) {
380
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
381
	}
382
	echo '</div>';
383
}
384
385
/**
386
 * Output a checkbox input box.
387
 *
388
 * @since  1.8
389
 * @param  array $field {
390
 *     Optional. Array of checkbox field arguments.
391
 *
392
 *     @type string             $id              Field ID. Default ''.
393
 *     @type string             $style           CSS style for input field. Default ''.
394
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
395
 *     @type string             $value           Value of input field. Default ''.
396
 *     @type string             $cbvalue         Checkbox value. Default 'on'.
397
 *     @type string             $name            Name of input field. Default ''.
398
 *     @type string             $description     Description of input field. Default ''.
399
 *     @type array              $attributes      List of attributes of input field. Default array().
400
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
401
 * }
402
 * @return void
403
 */
404
function give_checkbox( $field ) {
405
	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...
406
407
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
408
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
409
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
410
	$field['value']         = give_get_field_value( $field, $thepostid );
411
	$field['cbvalue']       = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on';
412
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
413
414
	// Custom attribute handling.
415
	$custom_attributes = array();
416
417
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
418
419
		foreach ( $field['attributes'] as $attribute => $value ) {
420
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
421
		}
422
	}
423
424
	echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label><input type="checkbox" style="' . esc_attr( $field['style'] ) . '" name="' . give_get_field_name( $field ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['cbvalue'] ) . '" ' . checked( $field['value'], $field['cbvalue'], false ) . '  ' . implode( ' ', $custom_attributes ) . '/> ';
425
426
	if ( ! empty( $field['description'] ) ) {
427
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
428
	}
429
430
	echo '</p>';
431
}
432
433
/**
434
 * Output a select input box.
435
 *
436
 * @since  1.8
437
 * @param  array $field {
438
 *     Optional. Array of select field arguments.
439
 *
440
 *     @type string             $id              Field ID. Default ''.
441
 *     @type string             $style           CSS style for input field. Default ''.
442
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
443
 *     @type string             $value           Value of input field. Default ''.
444
 *     @type string             $name            Name of input field. Default ''.
445
 *     @type string             $description     Description of input field. Default ''.
446
 *     @type array              $attributes      List of attributes of input field. Default array().
447
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
448
 *     @type array              $options         List of options. Default array().
449
 *                                               for example: 'options' => array( '' => 'None', 'yes' => 'Yes' )
450
 * }
451
 * @return void
452
 */
453
function give_select( $field ) {
454
	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...
455
456
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
457
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
458
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
459
	$field['value']         = give_get_field_value( $field, $thepostid );
460
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
461
462
	// Custom attribute handling
463
	$custom_attributes = array();
464
465
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
466
467
		foreach ( $field['attributes'] as $attribute => $value ) {
468
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
469
		}
470
	}
471
472
	echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label><select id="' . esc_attr( $field['id'] ) . '" name="' . give_get_field_name( $field ) . '" style="' . esc_attr( $field['style'] ) . '" ' . implode( ' ', $custom_attributes ) . '>';
473
474
	foreach ( $field['options'] as $key => $value ) {
475
		echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
476
	}
477
478
	echo '</select> ';
479
480
	if ( ! empty( $field['description'] ) ) {
481
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
482
	}
483
	echo '</p>';
484
}
485
486
/**
487
 * Output a radio input box.
488
 *
489
 * @since  1.8
490
 * @param  array $field {
491
 *     Optional. Array of radio field arguments.
492
 *
493
 *     @type string             $id              Field ID. Default ''.
494
 *     @type string             $style           CSS style for input field. Default ''.
495
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
496
 *     @type string             $value           Value of input field. Default ''.
497
 *     @type string             $name            Name of input field. Default ''.
498
 *     @type string             $description     Description of input field. Default ''.
499
 *     @type array              $attributes      List of attributes of input field. Default array().
500
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
501
 *     @type array              $options         List of options. Default array().
502
 *                                               for example: 'options' => array( 'enable' => 'Enable', 'disable' => 'Disable' )
503
 * }
504
 * @return void
505
 */
506
function give_radio( $field ) {
507
	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...
508
509
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
510
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
511
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
512
	$field['value']         = give_get_field_value( $field, $thepostid );
513
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
514
515
	// Custom attribute handling
516
	$custom_attributes = array();
517
518
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
519
520
		foreach ( $field['attributes'] as $attribute => $value ) {
521
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
522
		}
523
	}
524
525
	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">';
526
527
	foreach ( $field['options'] as $key => $value ) {
528
529
		echo '<li><label><input
530
				name="' . give_get_field_name( $field ) . '"
531
				value="' . esc_attr( $key ) . '"
532
				type="radio"
533
				style="' . esc_attr( $field['style'] ) . '"
534
				' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' '
535
				. implode( ' ', $custom_attributes ) . '
536
				/> ' . esc_html( $value ) . '</label>
537
		</li>';
538
	}
539
	echo '</ul>';
540
541
	if ( ! empty( $field['description'] ) ) {
542
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
543
	}
544
545
	echo '</fieldset>';
546
}
547
548
/**
549
 * Output a colorpicker.
550
 *
551
 * @since  1.8
552
 * @param  array $field {
553
 *     Optional. Array of colorpicker field arguments.
554
 *
555
 *     @type string             $id              Field ID. Default ''.
556
 *     @type string             $style           CSS style for input field. Default ''.
557
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
558
 *     @type string             $value           Value of input field. Default ''.
559
 *     @type string             $name            Name of input field. Default ''.
560
 *     @type string             $description     Description of input field. Default ''.
561
 *     @type array              $attributes      List of attributes of input field. Default array().
562
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
563
 * }
564
 * @return void
565
 */
566
function give_colorpicker( $field ) {
567
	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...
568
569
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
570
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
571
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
572
	$field['value']         = give_get_field_value( $field, $thepostid );
573
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
574
	$field['type']          = 'text';
575
576
	// Custom attribute handling
577
	$custom_attributes = array();
578
579
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
580
581
		foreach ( $field['attributes'] as $attribute => $value ) {
582
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
583
		}
584
	}
585
586
	echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label><input type="' . esc_attr( $field['type'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . give_get_field_name( $field ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> ';
587
588
	if ( ! empty( $field['description'] ) ) {
589
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
590
	}
591
	echo '</p>';
592
}
593
594
/**
595
 * Output a select field with payment options list.
596
 *
597
 * @since  1.8
598
 *
599
 * @param  array $field
600
 *
601
 * @return void
602
 */
603
function give_default_gateway( $field ) {
604
	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...
605
606
	// get all active payment gateways.
607
	$gateways         = give_get_enabled_payment_gateways( $thepostid );
608
	$field['options'] = array();
609
610
	// Set field option value.
611
	if( ! empty( $gateways ) ) {
612
		foreach ( $gateways as $key => $option ) {
613
			$field['options'][ $key ] = $option['admin_label'];
614
		}
615
	}
616
617
	//Add a field to the Give Form admin single post view of this field
618
	if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
619
		$field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] );
620
	}
621
622
	// Render select field.
623
	give_select( $field );
624
}
625
626
627
/**
628
 * Get setting field value.
629
 *
630
 * Note: Use only for single post, page or custom post type.
631
 *
632
 * @since  1.8
633
 *
634
 * @param  array $field
635
 * @param  int   $postid
636
 *
637
 * @return mixed
638
 */
639
function give_get_field_value( $field, $postid ) {
640
	if ( isset( $field['attributes']['value'] ) ) {
641
		return $field['attributes']['value'];
642
	}
643
644
	// Get value from db.
645
	$field_value = get_post_meta( $postid, $field['id'], true );
646
647
	/**
648
	 * Filter the field value before apply default value.
649
	 *
650
	 * @since 1.8
651
	 *
652
	 * @param mixed $field_value Field value.
653
	 */
654
	$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
655
656
657
	// Set default value if no any data saved to db.
658
	if ( ! $field_value && isset( $field['default'] ) ) {
659
		$field_value = $field['default'];
660
	}
661
662
	return $field_value;
663
}
664
665
/**
666
 * Get repeater field value.
667
 *
668
 * Note: Use only for single post, page or custom post type.
669
 *
670
 * @since  1.8
671
 *
672
 * @param array $field
673
 * @param array $field_group
674
 * @param array $fields
675
 *
676
 * @return string
677
 */
678
function give_get_repeater_field_value( $field, $field_group, $fields ) {
679
	$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
680
681
	/**
682
	 * Filter the specific repeater field value
683
	 *
684
	 * @since 1.8
685
	 *
686
	 * @param string $field_id
687
	 */
688
	$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
689
690
	/**
691
	 * Filter the repeater field value
692
	 *
693
	 * @since 1.8
694
	 *
695
	 * @param string $field_id
696
	 */
697
	$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
698
699
	return $field_value;
700
}
701
702
/**
703
 * Get repeater field id.
704
 *
705
 * Note: Use only for single post, page or custom post type.
706
 *
707
 * @since  1.8
708
 *
709
 * @param array    $field
710
 * @param array    $fields
711
 * @param int|bool $default
712
 *
713
 * @return string
714
 */
715
function give_get_repeater_field_id( $field, $fields, $default = false ) {
716
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
717
718
	// Get field id.
719
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
720
721
	/**
722
	 * Filter the specific repeater field id
723
	 *
724
	 * @since 1.8
725
	 *
726
	 * @param string $field_id
727
	 */
728
	$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
729
730
731
	/**
732
	 * Filter the repeater field id
733
	 *
734
	 * @since 1.8
735
	 *
736
	 * @param string $field_id
737
	 */
738
	$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
739
740
	return $field_id;
741
}
742
743
744
/**
745
 * Get field name.
746
 *
747
 * @since  1.8
748
 *
749
 * @param  array $field
750
 *
751
 * @return string
752
 */
753
function give_get_field_name( $field ) {
754
	$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
755
756
	/**
757
	 * Filter the field name.
758
	 *
759
	 * @since 1.8
760
	 *
761
	 * @param string $field_name
762
	 */
763
	$field_name = apply_filters( 'give_get_field_name', $field_name, $field );
764
765
	return $field_name;
766
}
767
768
/**
769
 * Output repeater field or multi donation type form on donation from edit screen.
770
 * Note: internal use only.
771
 * @TODO   : Add support for wysiwyg type field.
772
 *
773
 * @since  1.8
774
 *
775
 * @param  array $fields
776
 *
777
 * @return void
778
 */
779
function _give_metabox_form_data_repeater_fields( $fields ) {
780
	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...
781
782
	// Bailout.
783
	if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) {
784
		return;
785
	}
786
787
	$group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0;
788
	$close_tabs      = isset( $fields['options']['close_tabs'] )      ? (int) $fields['options']['close_tabs']      : 0;
789
	?>
790
	<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; ?>">
791
		<?php if ( ! empty( $fields['name'] ) ) : ?>
792
			<p class="give-repeater-field-name"><?php echo $fields['name']; ?></p>
793
		<?php endif; ?>
794
795
		<?php if ( ! empty( $fields['description'] ) ) : ?>
796
			<p class="give-repeater-field-description"><?php echo $fields['description']; ?></p>
797
		<?php endif; ?>
798
799
		<table class="give-repeatable-fields-section-wrapper" cellspacing="0">
800
			<?php
801
			$repeater_field_values = get_post_meta( $thepostid, $fields['id'], true );
802
			$header_title          = isset( $fields['options']['header_title'] )
803
				? $fields['options']['header_title']
804
				: esc_attr__( 'Group', 'give' );
805
806
			$add_default_donation_field = false;
807
808
			// Check if level is not created or we have to add default level.
809
			if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) {
810
				$repeater_field_values = array_values( $repeater_field_values );
811
			} else {
812
				$fields_count               = 1;
813
				$add_default_donation_field = true;
814
			}
815
			?>
816
			<tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>>
817
				<!--Repeater field group template-->
818
				<tr class="give-template give-row">
819
					<td class="give-repeater-field-wrap give-column" colspan="2">
820
						<div class="give-row-head give-move">
821
							<button type="button" class="handlediv button-link"><span class="toggle-indicator"></span>
822
							</button>
823
							<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span>
824
							<h2>
825
								<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
826
							</h2>
827
						</div>
828
						<div class="give-row-body">
829
							<?php foreach ( $fields['fields'] as $field ) : ?>
830
								<?php if ( ! give_is_field_callback_exist( $field ) ) {
831
									continue;
832
								} ?>
833
								<?php
834
								$field['repeat']              = true;
835
								$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields );
836
								$field['id']                  = str_replace( array( '[', ']' ), array(
837
									'_',
838
									'',
839
								), $field['repeatable_field_id'] );
840
								?>
841
								<?php give_render_field( $field ); ?>
842
							<?php endforeach; ?>
843
						</div>
844
					</td>
845
				</tr>
846
847
				<?php if ( ! empty( $repeater_field_values ) ) : ?>
848
					<!--Stored repeater field group-->
849
					<?php foreach ( $repeater_field_values as $index => $field_group ) : ?>
850
						<tr class="give-row">
851
							<td class="give-repeater-field-wrap give-column" colspan="2">
852
								<div class="give-row-head give-move">
853
									<button type="button" class="handlediv button-link">
854
										<span class="toggle-indicator"></span></button>
855
									<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
856
									</sapn>
857
									<h2>
858
										<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
859
									</h2>
860
								</div>
861
								<div class="give-row-body">
862
									<?php foreach ( $fields['fields'] as $field ) : ?>
863
										<?php if ( ! give_is_field_callback_exist( $field ) ) {
864
											continue;
865
										} ?>
866
										<?php
867
										$field['repeat']              = true;
868
										$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index );
869
										$field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields );
870
										$field['id']                  = str_replace( array( '[', ']' ), array(
871
											'_',
872
											'',
873
										), $field['repeatable_field_id'] );
874
										?>
875
										<?php give_render_field( $field ); ?>
876
									<?php endforeach; ?>
877
								</div>
878
							</td>
879
						</tr>
880
					<?php endforeach;; ?>
881
882
				<?php elseif ( $add_default_donation_field ) : ?>
883
					<!--Default repeater field group-->
884
					<tr class="give-row">
885
						<td class="give-repeater-field-wrap give-column" colspan="2">
886
							<div class="give-row-head give-move">
887
								<button type="button" class="handlediv button-link">
888
									<span class="toggle-indicator"></span></button>
889
								<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
890
								</sapn>
891
								<h2>
892
									<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
893
								</h2>
894
							</div>
895
							<div class="give-row-body">
896
								<?php
897
								foreach ( $fields['fields'] as $field ) :
898
									if ( ! give_is_field_callback_exist( $field ) ) {
899
										continue;
900
									}
901
902
									$field['repeat']              = true;
903
									$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 );
904
									$field['attributes']['value'] = apply_filters( "give_default_field_group_field_{$field['id']}_value", ( ! empty( $field['default'] ) ? $field['default'] : '' ), $field );
905
									$field['id']                  = str_replace( array( '[', ']' ), array(
906
										'_',
907
										'',
908
									), $field['repeatable_field_id'] );
909
									give_render_field( $field );
910
								endforeach;
911
								?>
912
							</div>
913
						</td>
914
					</tr>
915
				<?php endif; ?>
916
			</tbody>
917
			<tfoot>
918
				<tr>
919
					<?php
920
					$add_row_btn_title = isset( $fields['options']['add_button'] )
921
						? $add_row_btn_title = $fields['options']['add_button']
922
						: esc_html__( 'Add Row', 'give' );
923
					?>
924
					<td colspan="2" class="give-add-repeater-field-section-row-wrap">
925
						<span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span>
926
					</td>
927
				</tr>
928
			</tfoot>
929
		</table>
930
	</div>
931
	<?php
932
}
933
934
935
/**
936
 * Get current setting tab.
937
 *
938
 * @since  1.8
939
 * @return string
940
 */
941
function give_get_current_setting_tab() {
942
	// Get current setting page.
943
	$current_setting_page = give_get_current_setting_page();
944
945
	/**
946
	 * Filter the default tab for current setting page.
947
	 *
948
	 * @since 1.8
949
	 *
950
	 * @param string
951
	 */
952
	$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' );
953
954
	// Get current tab.
955
	$current_tab = empty( $_GET['tab'] ) ? $default_current_tab : urldecode( $_GET['tab'] );
956
957
	// Output.
958
	return $current_tab;
959
}
960
961
962
/**
963
 * Get current setting section.
964
 *
965
 * @since  1.8
966
 * @return string
967
 */
968
function give_get_current_setting_section() {
969
	// Get current tab.
970
	$current_tab = give_get_current_setting_tab();
971
972
	/**
973
	 * Filter the default section for current setting page tab.
974
	 *
975
	 * @since 1.8
976
	 *
977
	 * @param string
978
	 */
979
	$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' );
980
981
	// Get current section.
982
	$current_section = empty( $_REQUEST['section'] ) ? $default_current_section : urldecode( $_REQUEST['section'] );
983
984
	//Output.
985
	return $current_section;
986
}
987
988
/**
989
 * Get current setting page.
990
 *
991
 * @since  1.8
992
 * @return string
993
 */
994
function give_get_current_setting_page() {
995
	// Get current page.
996
	$setting_page = ! empty( $_GET['page'] ) ? urldecode( $_GET['page'] ) : '';
997
998
	//Output.
999
	return $setting_page;
1000
}
1001
1002
/**
1003
 * Set value for Form content --> Display content field setting.
1004
 *
1005
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_display_content is not set yet.
1006
 *
1007
 * @since  1.8
1008
 *
1009
 * @param  mixed $field_value Field Value.
1010
 * @param  array $field       Field args.
1011
 * @param  int   $postid      Form/Post ID.
1012
 *
1013
 * @return string
1014
 */
1015
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...
1016
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1017
1018
	if (
1019
		! get_post_meta( $postid, '_give_display_content', true )
1020
		&& $show_content
1021
		&& ( 'none' !== $show_content )
1022
	) {
1023
		$field_value = 'enabled';
1024
	}
1025
1026
	return $field_value;
1027
}
1028
1029
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 );
1030
1031
1032
/**
1033
 * Set value for Form content --> Content placement field setting.
1034
 *
1035
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_content_placement is not set yet.
1036
 *
1037
 * @since  1.8
1038
 *
1039
 * @param  mixed $field_value Field Value.
1040
 * @param  array $field       Field args.
1041
 * @param  int   $postid      Form/Post ID.
1042
 *
1043
 * @return string
1044
 */
1045
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...
1046
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1047
1048
	if (
1049
		! get_post_meta( $postid, '_give_content_placement', true )
1050
		&& ( 'none' !== $show_content )
1051
	) {
1052
		$field_value = $show_content;
1053
	}
1054
1055
	return $field_value;
1056
}
1057
1058
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 );
1059
1060
1061
/**
1062
 * Set value for Terms and Conditions --> Terms and Conditions field setting.
1063
 *
1064
 * Backward compatibility:  set value by _give_terms_option form meta field value if it's value is none.
1065
 *
1066
 * @since  1.8
1067
 *
1068
 * @param  mixed $field_value Field Value.
1069
 * @param  array $field       Field args.
1070
 * @param  int   $postid      Form/Post ID.
1071
 *
1072
 * @return string
1073
 */
1074
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...
1075
	$term_option = get_post_meta( $postid, '_give_terms_option', true );
1076
1077
	if ( in_array( $term_option, array( 'none', 'yes' ) ) ) {
1078
		$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' );
1079
	}
1080
1081
	return $field_value;
1082
}
1083
1084
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 );
1085
1086
1087
/**
1088
 * Set value for Form Display --> Offline Donation --> Billing Fields.
1089
 *
1090
 * Backward compatibility:  set value by _give_offline_donation_enable_billing_fields_single form meta field value if it's value is on.
1091
 *
1092
 * @since  1.8
1093
 *
1094
 * @param  mixed $field_value Field Value.
1095
 * @param  array $field       Field args.
1096
 * @param  int   $postid      Form/Post ID.
1097
 *
1098
 * @return string
1099
 */
1100
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...
1101
	$offline_donation = get_post_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true );
1102
1103
	if ( 'on' === $offline_donation ) {
1104
		$field_value = 'enabled';
1105
	}
1106
1107
	return $field_value;
1108
}
1109
1110
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 );
1111
1112
1113
/**
1114
 * Set value for Donation Options --> Custom Amount.
1115
 *
1116
 * Backward compatibility:  set value by _give_custom_amount form meta field value if it's value is yes or no.
1117
 *
1118
 * @since  1.8
1119
 *
1120
 * @param  mixed $field_value Field Value.
1121
 * @param  array $field       Field args.
1122
 * @param  int   $postid      Form/Post ID.
1123
 *
1124
 * @return string
1125
 */
1126
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...
1127
	$custom_amount = get_post_meta( $postid, '_give_custom_amount', true );
1128
1129
	if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) {
1130
		$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' );
1131
	}
1132
1133
	return $field_value;
1134
}
1135
1136
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 );
1137
1138
1139
/**
1140
 * Set value for Donation Goal --> Donation Goal.
1141
 *
1142
 * Backward compatibility:  set value by _give_goal_option form meta field value if it's value is yes or no.
1143
 *
1144
 * @since  1.8
1145
 *
1146
 * @param  mixed $field_value Field Value.
1147
 * @param  array $field       Field args.
1148
 * @param  int   $postid      Form/Post ID.
1149
 *
1150
 * @return string
1151
 */
1152
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...
1153
	$goal_option = get_post_meta( $postid, '_give_goal_option', true );
1154
1155
	if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) {
1156
		$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' );
1157
	}
1158
1159
	return $field_value;
1160
}
1161
1162
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 );
1163
1164
/**
1165
 * Set value for Donation Goal --> close Form.
1166
 *
1167
 * Backward compatibility:  set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes or no.
1168
 *
1169
 * @since  1.8
1170
 *
1171
 * @param  mixed $field_value Field Value.
1172
 * @param  array $field       Field args.
1173
 * @param  int   $postid      Form/Post ID.
1174
 *
1175
 * @return string
1176
 */
1177
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...
1178
	$close_form = get_post_meta( $postid, '_give_close_form_when_goal_achieved', true );
1179
1180
	if ( in_array( $close_form, array( 'yes', 'no' ) ) ) {
1181
		$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' );
1182
	}
1183
1184
	return $field_value;
1185
}
1186
1187
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 );
1188
1189
1190
/**
1191
 * Set value for Form display --> Guest Donation.
1192
 *
1193
 * Backward compatibility:  set value by _give_logged_in_only form meta field value if it's value is yes or no.
1194
 *
1195
 * @since  1.8
1196
 *
1197
 * @param  mixed $field_value Field Value.
1198
 * @param  array $field       Field args.
1199
 * @param  int   $postid      Form/Post ID.
1200
 *
1201
 * @return string
1202
 */
1203
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...
1204
	$guest_donation = get_post_meta( $postid, '_give_logged_in_only', true );
1205
1206
	if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) {
1207
		$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' );
1208
	}
1209
1210
	return $field_value;
1211
}
1212
1213
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 );
1214
1215
/**
1216
 * Set value for Offline Donations --> Offline Donations.
1217
 *
1218
 * Backward compatibility:  set value by _give_customize_offline_donations form meta field value if it's value is yes or no.
1219
 *
1220
 * @since  1.8
1221
 *
1222
 * @param  mixed $field_value Field Value.
1223
 * @param  array $field       Field args.
1224
 * @param  int   $postid      Form/Post ID.
1225
 *
1226
 * @return string
1227
 */
1228
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...
1229
	$customize_offline_text = get_post_meta( $postid, '_give_customize_offline_donations', true );
1230
1231
	if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) {
1232
		$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' );
1233
	}
1234
1235
	return $field_value;
1236
}
1237
1238
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 );
1239
1240
1241
/**
1242
 * Set repeater field id for multi donation form.
1243
 *
1244
 * @since 1.8
1245
 *
1246
 * @param int   $field_id
1247
 * @param array $field
1248
 * @param array $fields
1249
 * @param bool  $default
1250
 *
1251
 * @return mixed
1252
 */
1253
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...
1254
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1255
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1256
1257
	return $field_id;
1258
}
1259
1260
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1261
1262
/**
1263
 * Set repeater field value for multi donation form.
1264
 *
1265
 * @since 1.8
1266
 *
1267
 * @param string $field_value
1268
 * @param array  $field
1269
 * @param array  $field_group
1270
 * @param array  $fields
1271
 *
1272
 * @return mixed
1273
 */
1274
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...
1275
	$field_value = $field_group[ $field['id'] ]['level_id'];
1276
1277
	return $field_value;
1278
}
1279
1280
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1281
1282
/**
1283
 * Set default value for _give_id field.
1284
 *
1285
 * @since 1.8
1286
 *
1287
 * @param $field
1288
 *
1289
 * @return string
1290
 */
1291
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...
1292
	return 0;
1293
}
1294
1295
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1296
1297
/**
1298
 * Set default value for _give_default field.
1299
 *
1300
 * @since 1.8
1301
 *
1302
 * @param $field
1303
 *
1304
 * @return string
1305
 */
1306
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...
1307
	return 'default';
1308
}
1309
1310
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1311
1312
/**
1313
 * Set repeater field editor id for field type wysiwyg.
1314
 *
1315
 * @since 1.8
1316
 *
1317
 * @param $field_name
1318
 * @param $field
1319
 *
1320
 * @return string
1321
 */
1322
function give_repeater_field_set_editor_id( $field_name, $field ) {
1323
	if ( isset( $field['repeatable_field_id'] ) &&  'wysiwyg' == $field['type'] ) {
1324
		$field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1325
	}
1326
1327
	return $field_name;
1328
}
1329
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );