Completed
Push — issues/1451 ( 076884...61775a )
by Ravinder
25:31 queued 05:35
created

give-metabox-functions.php ➔ give_media()   C

Complexity

Conditions 7
Paths 32

Size

Total Lines 29
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 23
nc 32
nop 1
dl 0
loc 29
rs 6.7272
c 0
b 0
f 0
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' ? '<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' ) == '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
	// Custom attribute handling
260
	$custom_attributes = array();
261
262
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
263
264
		foreach ( $field['attributes'] as $attribute => $value ) {
265
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
266
		}
267
	}
268
269
	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'];
270
271
	if ( ! empty( $field['description'] ) ) {
272
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
273
	}
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
	echo '<input type="hidden" name="' . give_get_field_name( $field ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" ' . implode( ' ', $custom_attributes ) . '/> ';
310
}
311
312
/**
313
 * Output a textarea input box.
314
 *
315
 * @since  1.8
316
 * @since  1.8
317
 * @param  array $field {
318
 *     Optional. Array of textarea input field arguments.
319
 *
320
 *     @type string             $id              Field ID. Default ''.
321
 *     @type string             $style           CSS style for input field. Default ''.
322
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
323
 *     @type string             $value           Value of input field. Default ''.
324
 *     @type string             $name            Name of input field. Default ''.
325
 *     @type string             $description     Description of input field. Default ''.
326
 *     @type array              $attributes      List of attributes of input field. Default array().
327
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
328
 * }
329
 * @return void
330
 */
331
function give_textarea_input( $field ) {
332
	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...
333
334
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
335
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
336
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
337
	$field['value']         = give_get_field_value( $field, $thepostid );
338
339
	// Custom attribute handling
340
	$custom_attributes = array();
341
342
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
343
344
		foreach ( $field['attributes'] as $attribute => $value ) {
345
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
346
		}
347
	}
348
349
	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> ';
350
351
	if ( ! empty( $field['description'] ) ) {
352
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
353
	}
354
	echo '</p>';
355
}
356
357
/**
358
 * Output a wysiwyg.
359
 *
360
 * @since  1.8
361
 * @param  array $field {
362
 *     Optional. Array of WordPress editor field arguments.
363
 *
364
 *     @type string             $id              Field ID. Default ''.
365
 *     @type string             $style           CSS style for input field. Default ''.
366
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
367
 *     @type string             $value           Value of input field. Default ''.
368
 *     @type string             $name            Name of input field. Default ''.
369
 *     @type string             $description     Description of input field. Default ''.
370
 *     @type array              $attributes      List of attributes of input field. Default array().
371
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
372
 * }
373
 * @return void
374
 */
375
function give_wysiwyg( $field ) {
376
	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...
377
378
	$thepostid                = empty( $thepostid ) ? $post->ID : $thepostid;
379
	$field['style']           = isset( $field['style'] ) ? $field['style'] : '';
380
	$field['wrapper_class']   = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
381
	$field['value']           = give_get_field_value( $field, $thepostid );
382
	$field['unique_field_id'] = give_get_field_name( $field );
383
	$editor_attributes        = array(
384
		'textarea_name' => isset( $field['repeatable_field_id'] ) ? $field['repeatable_field_id'] : $field['id'],
385
		'textarea_rows' => '10',
386
		'editor_css'    => esc_attr( $field['style'] ),
387
		'editor_class'  => $field['attributes']['class']
388
	);
389
	$data_wp_editor           = ' data-wp-editor="'. base64_encode( json_encode( array( $field['value'], $field['unique_field_id'],$editor_attributes ) ) ) .'"';
390
	$data_wp_editor           = isset( $field['repeatable_field_id'] ) ? $data_wp_editor : '';
391
392
	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>';
393
394
	wp_editor(
395
		$field['value'],
396
		$field['unique_field_id'],
397
		$editor_attributes
398
	);
399
400
	if ( ! empty( $field['description'] ) ) {
401
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
402
	}
403
	echo '</div>';
404
}
405
406
/**
407
 * Output a checkbox input box.
408
 *
409
 * @since  1.8
410
 * @param  array $field {
411
 *     Optional. Array of checkbox field arguments.
412
 *
413
 *     @type string             $id              Field ID. Default ''.
414
 *     @type string             $style           CSS style for input field. Default ''.
415
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
416
 *     @type string             $value           Value of input field. Default ''.
417
 *     @type string             $cbvalue         Checkbox value. Default 'on'.
418
 *     @type string             $name            Name of input field. Default ''.
419
 *     @type string             $description     Description of input field. Default ''.
420
 *     @type array              $attributes      List of attributes of input field. Default array().
421
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
422
 * }
423
 * @return void
424
 */
425
function give_checkbox( $field ) {
426
	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...
427
428
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
429
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
430
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
431
	$field['value']         = give_get_field_value( $field, $thepostid );
432
	$field['cbvalue']       = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on';
433
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
434
435
	// Custom attribute handling.
436
	$custom_attributes = array();
437
438
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
439
440
		foreach ( $field['attributes'] as $attribute => $value ) {
441
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
442
		}
443
	}
444
445
	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 ) . '/> ';
446
447
	if ( ! empty( $field['description'] ) ) {
448
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
449
	}
450
451
	echo '</p>';
452
}
453
454
/**
455
 * Output a select input box.
456
 *
457
 * @since  1.8
458
 * @param  array $field {
459
 *     Optional. Array of select field arguments.
460
 *
461
 *     @type string             $id              Field ID. Default ''.
462
 *     @type string             $style           CSS style for input field. Default ''.
463
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
464
 *     @type string             $value           Value of input field. Default ''.
465
 *     @type string             $name            Name of input field. Default ''.
466
 *     @type string             $description     Description of input field. Default ''.
467
 *     @type array              $attributes      List of attributes of input field. Default array().
468
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
469
 *     @type array              $options         List of options. Default array().
470
 *                                               for example: 'options' => array( '' => 'None', 'yes' => 'Yes' )
471
 * }
472
 * @return void
473
 */
474
function give_select( $field ) {
475
	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...
476
477
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
478
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
479
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
480
	$field['value']         = give_get_field_value( $field, $thepostid );
481
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
482
483
	// Custom attribute handling
484
	$custom_attributes = array();
485
486
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
487
488
		foreach ( $field['attributes'] as $attribute => $value ) {
489
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
490
		}
491
	}
492
493
	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 ) . '>';
494
495
	foreach ( $field['options'] as $key => $value ) {
496
		echo '<option value="' . esc_attr( $key ) . '" ' . selected( esc_attr( $field['value'] ), esc_attr( $key ), false ) . '>' . esc_html( $value ) . '</option>';
497
	}
498
499
	echo '</select> ';
500
501
	if ( ! empty( $field['description'] ) ) {
502
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
503
	}
504
	echo '</p>';
505
}
506
507
/**
508
 * Output a radio input box.
509
 *
510
 * @since  1.8
511
 * @param  array $field {
512
 *     Optional. Array of radio field arguments.
513
 *
514
 *     @type string             $id              Field ID. Default ''.
515
 *     @type string             $style           CSS style for input field. Default ''.
516
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
517
 *     @type string             $value           Value of input field. Default ''.
518
 *     @type string             $name            Name of input field. Default ''.
519
 *     @type string             $description     Description of input field. Default ''.
520
 *     @type array              $attributes      List of attributes of input field. Default array().
521
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
522
 *     @type array              $options         List of options. Default array().
523
 *                                               for example: 'options' => array( 'enable' => 'Enable', 'disable' => 'Disable' )
524
 * }
525
 * @return void
526
 */
527
function give_radio( $field ) {
528
	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...
529
530
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
531
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
532
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
533
	$field['value']         = give_get_field_value( $field, $thepostid );
534
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
535
536
	// Custom attribute handling
537
	$custom_attributes = array();
538
539
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
540
541
		foreach ( $field['attributes'] as $attribute => $value ) {
542
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
543
		}
544
	}
545
546
	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">';
547
548
	foreach ( $field['options'] as $key => $value ) {
549
550
		echo '<li><label><input
551
				name="' . give_get_field_name( $field ) . '"
552
				value="' . esc_attr( $key ) . '"
553
				type="radio"
554
				style="' . esc_attr( $field['style'] ) . '"
555
				' . checked( esc_attr( $field['value'] ), esc_attr( $key ), false ) . ' '
556
				. implode( ' ', $custom_attributes ) . '
557
				/> ' . esc_html( $value ) . '</label>
558
		</li>';
559
	}
560
	echo '</ul>';
561
562
	if ( ! empty( $field['description'] ) ) {
563
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
564
	}
565
566
	echo '</fieldset>';
567
}
568
569
/**
570
 * Output a colorpicker.
571
 *
572
 * @since  1.8
573
 * @param  array $field {
574
 *     Optional. Array of colorpicker field arguments.
575
 *
576
 *     @type string             $id              Field ID. Default ''.
577
 *     @type string             $style           CSS style for input field. Default ''.
578
 *     @type string             $wrapper_class   CSS class to use for wrapper of input field. Default ''.
579
 *     @type string             $value           Value of input field. Default ''.
580
 *     @type string             $name            Name of input field. Default ''.
581
 *     @type string             $description     Description of input field. Default ''.
582
 *     @type array              $attributes      List of attributes of input field. Default array().
583
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
584
 * }
585
 * @return void
586
 */
587
function give_colorpicker( $field ) {
588
	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...
589
590
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
591
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
592
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
593
	$field['value']         = give_get_field_value( $field, $thepostid );
594
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
595
	$field['type']          = 'text';
596
597
	// Custom attribute handling
598
	$custom_attributes = array();
599
600
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
601
602
		foreach ( $field['attributes'] as $attribute => $value ) {
603
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
604
		}
605
	}
606
607
	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 ) . ' /> ';
608
609
	if ( ! empty( $field['description'] ) ) {
610
		echo '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
611
	}
612
	echo '</p>';
613
}
614
615
616
/**
617
 * Output a media upload field.
618
 *
619
 * @since  1.8
620
 *
621
 * @param array $field
622
 *
623
 */
624
function give_media( $field ) {
625
	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...
626
627
	$thepostid              = empty( $thepostid ) ? $post->ID : $thepostid;
628
	$field['style']         = isset( $field['style'] ) ? $field['style'] : '';
629
	$field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : '';
630
	$field['value']         = give_get_field_value( $field, $thepostid );
631
	$field['name']          = isset( $field['name'] ) ? $field['name'] : $field['id'];
632
	$field['type']          = 'text';
633
634
	// Allow developer to save attachment ID or attachment url as metadata.
635
	$field['fvalue']        = isset( $field['fvalue'] ) ? $field['fvalue'] : 'url';
636
	?>
637
	<p class="give-field-wrap <?php echo esc_attr( $field['id'] ); ?>_field <?php echo esc_attr( $field['wrapper_class'] ); ?>">
638
		<label for="<?php echo $field['id'] ?>"><?php echo wp_kses_post( $field['name'] ); ?></label>
639
		<input
640
			name="<?php echo esc_attr( $field['id'] ); ?>"
641
			id="<?php echo esc_attr( $field['id'] ); ?>"
642
			type="text"
643
			class="give-input-field<?php echo esc_attr( isset( $field['class'] ) ? ' ' . $field['class'] : '' ); ?> give-text-medium"
644
			value="<?php echo $field['value']; ?>"
645
			style="<?php echo esc_attr( $field['style'] ); ?>"
646
			data-fvalue="<?php echo $field['fvalue']; ?>"
647
			<?php echo give_get_custom_attributes( $field ); ?>
648
		/>&nbsp;&nbsp;&nbsp;&nbsp;<input class="give-media-upload button" type="button" value="<?php echo esc_html__( 'Add or Upload File', 'give' ); ?>">
649
		<?php echo give_get_field_description( $field ); ?>
650
	</p>
651
	<?php
652
}
653
654
/**
655
 * Output a select field with payment options list.
656
 *
657
 * @since  1.8
658
 *
659
 * @param  array $field
660
 *
661
 * @return void
662
 */
663
function give_default_gateway( $field ) {
664
	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...
665
666
	// get all active payment gateways.
667
	$gateways         = give_get_enabled_payment_gateways( $thepostid );
668
	$field['options'] = array();
669
670
	// Set field option value.
671
	if( ! empty( $gateways ) ) {
672
		foreach ( $gateways as $key => $option ) {
673
			$field['options'][ $key ] = $option['admin_label'];
674
		}
675
	}
676
677
	//Add a field to the Give Form admin single post view of this field
678
	if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
679
		$field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] );
680
	}
681
682
	// Render select field.
683
	give_select( $field );
684
}
685
686
/**
687
  * Output the documentation link.
688
  *
689
  * @since  1.8
690
  * @param  array $field {
691
  *     Optional. Array of customizable link attributes.
692
  *
693
  *     @type string             $name            Name of input field. Default ''.
694
  *     @type string             $type            Type of input field. Default 'text'.
695
  *     @type string             $url             Value to be passed as a link. Default 'https://givewp.com/documentation'.
696
  *     @type string             $title           Value to be passed as text of link. Default 'Documentation'.
697
  *     @type array              $attributes      List of attributes of input field. Default array().
698
  *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
699
  * }
700
  * @return void
701
*/
702
703
function give_docs_link($field) {
704
	$field['url']   = isset($field['url']) ? $field['url'] : 'https://givewp.com/documentation';
705
	$field['title'] = isset($field['title']) ? $field['title'] : 'Documentation';
706
707
	echo '<p class="give-docs-link"><a href="' . esc_url($field['url'])
708
		. '" target="_blank">'
709
		. sprintf(esc_html__('Need Help? See docs on "%s"'), $field['title'])
710
		. '<span class="dashicons dashicons-editor-help"></span></a></p>';
711
}
712
713
/**
714
 * Get setting field value.
715
 *
716
 * Note: Use only for single post, page or custom post type.
717
 *
718
 * @since  1.8
719
 *
720
 * @param  array $field
721
 * @param  int   $postid
722
 *
723
 * @return mixed
724
 */
725
function give_get_field_value( $field, $postid ) {
726
	if ( isset( $field['attributes']['value'] ) ) {
727
		return $field['attributes']['value'];
728
	}
729
730
	// Get value from db.
731
	$field_value = get_post_meta( $postid, $field['id'], true );
732
733
	/**
734
	 * Filter the field value before apply default value.
735
	 *
736
	 * @since 1.8
737
	 *
738
	 * @param mixed $field_value Field value.
739
	 */
740
	$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
741
742
743
	// Set default value if no any data saved to db.
744
	if ( ! $field_value && isset( $field['default'] ) ) {
745
		$field_value = $field['default'];
746
	}
747
748
	return $field_value;
749
}
750
751
752
/**
753
 * Get field description html.
754
 *
755
 * @since 1.8
756
 * @param $field
757
 *
758
 * @return string
759
 */
760
function give_get_field_description( $field ) {
761
	$field_desc_html = '';
762
	if ( ! empty( $field['description'] ) ) {
763
		$field_desc_html = '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
764
	}
765
766
	return $field_desc_html;
767
}
768
769
770
/**
771
 * Get field custom attributes as string.
772
 *
773
 * @since 1.8
774
 * @param $field
775
 *
776
 * @return string
777
 */
778
function give_get_custom_attributes( $field ) {
779
	// Custom attribute handling
780
	$custom_attributes = array();
781
782
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
783
784
		foreach ( $field['attributes'] as $attribute => $value ) {
785
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
786
		}
787
	}
788
789
	return implode( ' ', $custom_attributes );
790
}
791
792
/**
793
 * Get repeater field value.
794
 *
795
 * Note: Use only for single post, page or custom post type.
796
 *
797
 * @since  1.8
798
 *
799
 * @param array $field
800
 * @param array $field_group
801
 * @param array $fields
802
 *
803
 * @return string
804
 */
805
function give_get_repeater_field_value( $field, $field_group, $fields ) {
806
	$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
807
808
	/**
809
	 * Filter the specific repeater field value
810
	 *
811
	 * @since 1.8
812
	 *
813
	 * @param string $field_id
814
	 */
815
	$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
816
817
	/**
818
	 * Filter the repeater field value
819
	 *
820
	 * @since 1.8
821
	 *
822
	 * @param string $field_id
823
	 */
824
	$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
825
826
	return $field_value;
827
}
828
829
/**
830
 * Get repeater field id.
831
 *
832
 * Note: Use only for single post, page or custom post type.
833
 *
834
 * @since  1.8
835
 *
836
 * @param array    $field
837
 * @param array    $fields
838
 * @param int|bool $default
839
 *
840
 * @return string
841
 */
842
function give_get_repeater_field_id( $field, $fields, $default = false ) {
843
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
844
845
	// Get field id.
846
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
847
848
	/**
849
	 * Filter the specific repeater field id
850
	 *
851
	 * @since 1.8
852
	 *
853
	 * @param string $field_id
854
	 */
855
	$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
856
857
858
	/**
859
	 * Filter the repeater field id
860
	 *
861
	 * @since 1.8
862
	 *
863
	 * @param string $field_id
864
	 */
865
	$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
866
867
	return $field_id;
868
}
869
870
871
/**
872
 * Get field name.
873
 *
874
 * @since  1.8
875
 *
876
 * @param  array $field
877
 *
878
 * @return string
879
 */
880
function give_get_field_name( $field ) {
881
	$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
882
883
	/**
884
	 * Filter the field name.
885
	 *
886
	 * @since 1.8
887
	 *
888
	 * @param string $field_name
889
	 */
890
	$field_name = apply_filters( 'give_get_field_name', $field_name, $field );
891
892
	return $field_name;
893
}
894
895
/**
896
 * Output repeater field or multi donation type form on donation from edit screen.
897
 * Note: internal use only.
898
 * @TODO   : Add support for wysiwyg type field.
899
 *
900
 * @since  1.8
901
 *
902
 * @param  array $fields
903
 *
904
 * @return void
905
 */
906
function _give_metabox_form_data_repeater_fields( $fields ) {
907
	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...
908
909
	// Bailout.
910
	if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) {
911
		return;
912
	}
913
914
	$group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0;
915
	$close_tabs      = isset( $fields['options']['close_tabs'] )      ? (int) $fields['options']['close_tabs']      : 0;
916
	?>
917
	<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; ?>">
918
		<?php if ( ! empty( $fields['name'] ) ) : ?>
919
			<p class="give-repeater-field-name"><?php echo $fields['name']; ?></p>
920
		<?php endif; ?>
921
922
		<?php if ( ! empty( $fields['description'] ) ) : ?>
923
			<p class="give-repeater-field-description"><?php echo $fields['description']; ?></p>
924
		<?php endif; ?>
925
926
		<table class="give-repeatable-fields-section-wrapper" cellspacing="0">
927
			<?php
928
			$repeater_field_values = get_post_meta( $thepostid, $fields['id'], true );
929
			$header_title          = isset( $fields['options']['header_title'] )
930
				? $fields['options']['header_title']
931
				: esc_attr__( 'Group', 'give' );
932
933
			$add_default_donation_field = false;
934
935
			// Check if level is not created or we have to add default level.
936
			if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) {
937
				$repeater_field_values = array_values( $repeater_field_values );
938
			} else {
939
				$fields_count               = 1;
940
				$add_default_donation_field = true;
941
			}
942
			?>
943
			<tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>>
944
				<!--Repeater field group template-->
945
				<tr class="give-template give-row">
946
					<td class="give-repeater-field-wrap give-column" colspan="2">
947
						<div class="give-row-head give-move">
948
							<button type="button" class="handlediv button-link"><span class="toggle-indicator"></span>
949
							</button>
950
							<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span>
951
							<h2>
952
								<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
953
							</h2>
954
						</div>
955
						<div class="give-row-body">
956
							<?php foreach ( $fields['fields'] as $field ) : ?>
957
								<?php if ( ! give_is_field_callback_exist( $field ) ) {
958
									continue;
959
								} ?>
960
								<?php
961
								$field['repeat']              = true;
962
								$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields );
963
								$field['id']                  = str_replace( array( '[', ']' ), array(
964
									'_',
965
									'',
966
								), $field['repeatable_field_id'] );
967
								?>
968
								<?php give_render_field( $field ); ?>
969
							<?php endforeach; ?>
970
						</div>
971
					</td>
972
				</tr>
973
974
				<?php if ( ! empty( $repeater_field_values ) ) : ?>
975
					<!--Stored repeater field group-->
976
					<?php foreach ( $repeater_field_values as $index => $field_group ) : ?>
977
						<tr class="give-row">
978
							<td class="give-repeater-field-wrap give-column" colspan="2">
979
								<div class="give-row-head give-move">
980
									<button type="button" class="handlediv button-link">
981
										<span class="toggle-indicator"></span></button>
982
									<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
983
									</sapn>
984
									<h2>
985
										<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
986
									</h2>
987
								</div>
988
								<div class="give-row-body">
989
									<?php foreach ( $fields['fields'] as $field ) : ?>
990
										<?php if ( ! give_is_field_callback_exist( $field ) ) {
991
											continue;
992
										} ?>
993
										<?php
994
										$field['repeat']              = true;
995
										$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, $index );
996
										$field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields );
997
										$field['id']                  = str_replace( array( '[', ']' ), array(
998
											'_',
999
											'',
1000
										), $field['repeatable_field_id'] );
1001
										?>
1002
										<?php give_render_field( $field ); ?>
1003
									<?php endforeach; ?>
1004
								</div>
1005
							</td>
1006
						</tr>
1007
					<?php endforeach;; ?>
1008
1009
				<?php elseif ( $add_default_donation_field ) : ?>
1010
					<!--Default repeater field group-->
1011
					<tr class="give-row">
1012
						<td class="give-repeater-field-wrap give-column" colspan="2">
1013
							<div class="give-row-head give-move">
1014
								<button type="button" class="handlediv button-link">
1015
									<span class="toggle-indicator"></span></button>
1016
								<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
1017
								</sapn>
1018
								<h2>
1019
									<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
1020
								</h2>
1021
							</div>
1022
							<div class="give-row-body">
1023
								<?php
1024
								foreach ( $fields['fields'] as $field ) :
1025
									if ( ! give_is_field_callback_exist( $field ) ) {
1026
										continue;
1027
									}
1028
1029
									$field['repeat']              = true;
1030
									$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 );
1031
									$field['attributes']['value'] = apply_filters( "give_default_field_group_field_{$field['id']}_value", ( ! empty( $field['default'] ) ? $field['default'] : '' ), $field );
1032
									$field['id']                  = str_replace( array( '[', ']' ), array(
1033
										'_',
1034
										'',
1035
									), $field['repeatable_field_id'] );
1036
									give_render_field( $field );
1037
								endforeach;
1038
								?>
1039
							</div>
1040
						</td>
1041
					</tr>
1042
				<?php endif; ?>
1043
			</tbody>
1044
			<tfoot>
1045
				<tr>
1046
					<?php
1047
					$add_row_btn_title = isset( $fields['options']['add_button'] )
1048
						? $add_row_btn_title = $fields['options']['add_button']
1049
						: esc_html__( 'Add Row', 'give' );
1050
					?>
1051
					<td colspan="2" class="give-add-repeater-field-section-row-wrap">
1052
						<span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span>
1053
					</td>
1054
				</tr>
1055
			</tfoot>
1056
		</table>
1057
	</div>
1058
	<?php
1059
}
1060
1061
1062
/**
1063
 * Get current setting tab.
1064
 *
1065
 * @since  1.8
1066
 * @return string
1067
 */
1068
function give_get_current_setting_tab() {
1069
	// Get current setting page.
1070
	$current_setting_page = give_get_current_setting_page();
1071
1072
	/**
1073
	 * Filter the default tab for current setting page.
1074
	 *
1075
	 * @since 1.8
1076
	 *
1077
	 * @param string
1078
	 */
1079
	$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' );
1080
1081
	// Get current tab.
1082
	$current_tab = empty( $_GET['tab'] ) ? $default_current_tab : urldecode( $_GET['tab'] );
1083
1084
	// Output.
1085
	return $current_tab;
1086
}
1087
1088
1089
/**
1090
 * Get current setting section.
1091
 *
1092
 * @since  1.8
1093
 * @return string
1094
 */
1095
function give_get_current_setting_section() {
1096
	// Get current tab.
1097
	$current_tab = give_get_current_setting_tab();
1098
1099
	/**
1100
	 * Filter the default section for current setting page tab.
1101
	 *
1102
	 * @since 1.8
1103
	 *
1104
	 * @param string
1105
	 */
1106
	$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' );
1107
1108
	// Get current section.
1109
	$current_section = empty( $_REQUEST['section'] ) ? $default_current_section : urldecode( $_REQUEST['section'] );
1110
1111
	//Output.
1112
	return $current_section;
1113
}
1114
1115
/**
1116
 * Get current setting page.
1117
 *
1118
 * @since  1.8
1119
 * @return string
1120
 */
1121
function give_get_current_setting_page() {
1122
	// Get current page.
1123
	$setting_page = ! empty( $_GET['page'] ) ? urldecode( $_GET['page'] ) : '';
1124
1125
	//Output.
1126
	return $setting_page;
1127
}
1128
1129
/**
1130
 * Set value for Form content --> Display content field setting.
1131
 *
1132
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_display_content is not set yet.
1133
 *
1134
 * @since  1.8
1135
 *
1136
 * @param  mixed $field_value Field Value.
1137
 * @param  array $field       Field args.
1138
 * @param  int   $postid      Form/Post ID.
1139
 *
1140
 * @return string
1141
 */
1142
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...
1143
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1144
1145
	if (
1146
		! get_post_meta( $postid, '_give_display_content', true )
1147
		&& $show_content
1148
		&& ( 'none' !== $show_content )
1149
	) {
1150
		$field_value = 'enabled';
1151
	}
1152
1153
	return $field_value;
1154
}
1155
1156
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 );
1157
1158
1159
/**
1160
 * Set value for Form content --> Content placement field setting.
1161
 *
1162
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_content_placement is not set yet.
1163
 *
1164
 * @since  1.8
1165
 *
1166
 * @param  mixed $field_value Field Value.
1167
 * @param  array $field       Field args.
1168
 * @param  int   $postid      Form/Post ID.
1169
 *
1170
 * @return string
1171
 */
1172
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...
1173
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1174
1175
	if (
1176
		! get_post_meta( $postid, '_give_content_placement', true )
1177
		&& ( 'none' !== $show_content )
1178
	) {
1179
		$field_value = $show_content;
1180
	}
1181
1182
	return $field_value;
1183
}
1184
1185
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 );
1186
1187
1188
/**
1189
 * Set value for Terms and Conditions --> Terms and Conditions field setting.
1190
 *
1191
 * Backward compatibility:  set value by _give_terms_option form meta field value if it's value is none.
1192
 *
1193
 * @since  1.8
1194
 *
1195
 * @param  mixed $field_value Field Value.
1196
 * @param  array $field       Field args.
1197
 * @param  int   $postid      Form/Post ID.
1198
 *
1199
 * @return string
1200
 */
1201
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...
1202
	$term_option = get_post_meta( $postid, '_give_terms_option', true );
1203
1204
	if ( in_array( $term_option, array( 'none', 'yes' ) ) ) {
1205
		$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' );
1206
	}
1207
1208
	return $field_value;
1209
}
1210
1211
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 );
1212
1213
1214
/**
1215
 * Set value for Form Display --> Offline Donation --> Billing Fields.
1216
 *
1217
 * Backward compatibility:  set value by _give_offline_donation_enable_billing_fields_single form meta field value if it's value is on.
1218
 *
1219
 * @since  1.8
1220
 *
1221
 * @param  mixed $field_value Field Value.
1222
 * @param  array $field       Field args.
1223
 * @param  int   $postid      Form/Post ID.
1224
 *
1225
 * @return string
1226
 */
1227
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...
1228
	$offline_donation = get_post_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true );
1229
1230
	if ( 'on' === $offline_donation ) {
1231
		$field_value = 'enabled';
1232
	}
1233
1234
	return $field_value;
1235
}
1236
1237
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 );
1238
1239
1240
/**
1241
 * Set value for Donation Options --> Custom Amount.
1242
 *
1243
 * Backward compatibility:  set value by _give_custom_amount form meta field value if it's value is yes or no.
1244
 *
1245
 * @since  1.8
1246
 *
1247
 * @param  mixed $field_value Field Value.
1248
 * @param  array $field       Field args.
1249
 * @param  int   $postid      Form/Post ID.
1250
 *
1251
 * @return string
1252
 */
1253
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...
1254
	$custom_amount = get_post_meta( $postid, '_give_custom_amount', true );
1255
1256
	if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) {
1257
		$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' );
1258
	}
1259
1260
	return $field_value;
1261
}
1262
1263
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 );
1264
1265
1266
/**
1267
 * Set value for Donation Goal --> Donation Goal.
1268
 *
1269
 * Backward compatibility:  set value by _give_goal_option form meta field value if it's value is yes or no.
1270
 *
1271
 * @since  1.8
1272
 *
1273
 * @param  mixed $field_value Field Value.
1274
 * @param  array $field       Field args.
1275
 * @param  int   $postid      Form/Post ID.
1276
 *
1277
 * @return string
1278
 */
1279
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...
1280
	$goal_option = get_post_meta( $postid, '_give_goal_option', true );
1281
1282
	if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) {
1283
		$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' );
1284
	}
1285
1286
	return $field_value;
1287
}
1288
1289
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 );
1290
1291
/**
1292
 * Set value for Donation Goal --> close Form.
1293
 *
1294
 * Backward compatibility:  set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes or no.
1295
 *
1296
 * @since  1.8
1297
 *
1298
 * @param  mixed $field_value Field Value.
1299
 * @param  array $field       Field args.
1300
 * @param  int   $postid      Form/Post ID.
1301
 *
1302
 * @return string
1303
 */
1304
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...
1305
	$close_form = get_post_meta( $postid, '_give_close_form_when_goal_achieved', true );
1306
1307
	if ( in_array( $close_form, array( 'yes', 'no' ) ) ) {
1308
		$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' );
1309
	}
1310
1311
	return $field_value;
1312
}
1313
1314
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 );
1315
1316
1317
/**
1318
 * Set value for Form display --> Guest Donation.
1319
 *
1320
 * Backward compatibility:  set value by _give_logged_in_only form meta field value if it's value is yes or no.
1321
 *
1322
 * @since  1.8
1323
 *
1324
 * @param  mixed $field_value Field Value.
1325
 * @param  array $field       Field args.
1326
 * @param  int   $postid      Form/Post ID.
1327
 *
1328
 * @return string
1329
 */
1330
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...
1331
	$guest_donation = get_post_meta( $postid, '_give_logged_in_only', true );
1332
1333
	if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) {
1334
		$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' );
1335
	}
1336
1337
	return $field_value;
1338
}
1339
1340
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 );
1341
1342
/**
1343
 * Set value for Offline Donations --> Offline Donations.
1344
 *
1345
 * Backward compatibility:  set value by _give_customize_offline_donations form meta field value if it's value is yes or no.
1346
 *
1347
 * @since  1.8
1348
 *
1349
 * @param  mixed $field_value Field Value.
1350
 * @param  array $field       Field args.
1351
 * @param  int   $postid      Form/Post ID.
1352
 *
1353
 * @return string
1354
 */
1355
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...
1356
	$customize_offline_text = get_post_meta( $postid, '_give_customize_offline_donations', true );
1357
1358
	if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) {
1359
		$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' );
1360
	}
1361
1362
	return $field_value;
1363
}
1364
1365
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 );
1366
1367
1368
/**
1369
 * Set repeater field id for multi donation form.
1370
 *
1371
 * @since 1.8
1372
 *
1373
 * @param int   $field_id
1374
 * @param array $field
1375
 * @param array $fields
1376
 * @param bool  $default
1377
 *
1378
 * @return mixed
1379
 */
1380
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...
1381
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1382
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1383
1384
	return $field_id;
1385
}
1386
1387
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1388
1389
/**
1390
 * Set repeater field value for multi donation form.
1391
 *
1392
 * @since 1.8
1393
 *
1394
 * @param string $field_value
1395
 * @param array  $field
1396
 * @param array  $field_group
1397
 * @param array  $fields
1398
 *
1399
 * @return mixed
1400
 */
1401
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...
1402
	$field_value = $field_group[ $field['id'] ]['level_id'];
1403
1404
	return $field_value;
1405
}
1406
1407
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1408
1409
/**
1410
 * Set default value for _give_id field.
1411
 *
1412
 * @since 1.8
1413
 *
1414
 * @param $field
1415
 *
1416
 * @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...
1417
 */
1418
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...
1419
	return 0;
1420
}
1421
1422
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1423
1424
/**
1425
 * Set default value for _give_default field.
1426
 *
1427
 * @since 1.8
1428
 *
1429
 * @param $field
1430
 *
1431
 * @return string
1432
 */
1433
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...
1434
	return 'default';
1435
}
1436
1437
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1438
1439
/**
1440
 * Set repeater field editor id for field type wysiwyg.
1441
 *
1442
 * @since 1.8
1443
 *
1444
 * @param $field_name
1445
 * @param $field
1446
 *
1447
 * @return string
1448
 */
1449
function give_repeater_field_set_editor_id( $field_name, $field ) {
1450
	if ( isset( $field['repeatable_field_id'] ) &&  'wysiwyg' == $field['type'] ) {
1451
		$field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1452
	}
1453
1454
	return $field_name;
1455
}
1456
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );