Completed
Push — backup/611 ( 661115 )
by Ravinder
1411:51 queued 1394:16
created

give-metabox-functions.php ➔ give_email_preview_buttons()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 39

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 39
rs 9.296
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
 * Output a select field with payment options list.
617
 *
618
 * @since  1.8
619
 *
620
 * @param  array $field
621
 *
622
 * @return void
623
 */
624
function give_default_gateway( $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
	// get all active payment gateways.
628
	$gateways         = give_get_enabled_payment_gateways( $thepostid );
629
	$field['options'] = array();
630
631
	// Set field option value.
632
	if( ! empty( $gateways ) ) {
633
		foreach ( $gateways as $key => $option ) {
634
			$field['options'][ $key ] = $option['admin_label'];
635
		}
636
	}
637
638
	//Add a field to the Give Form admin single post view of this field
639
	if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
640
		$field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] );
641
	}
642
643
	// Render select field.
644
	give_select( $field );
645
}
646
647
/**
648
  * Output the documentation link.
649
  *
650
  * @since  1.8
651
  * @param  array $field {
652
  *     Optional. Array of customizable link attributes.
653
  *
654
  *     @type string             $name            Name of input field. Default ''.
655
  *     @type string             $type            Type of input field. Default 'text'.
656
  *     @type string             $url             Value to be passed as a link. Default 'https://givewp.com/documentation'.
657
  *     @type string             $title           Value to be passed as text of link. Default 'Documentation'.
658
  *     @type array              $attributes      List of attributes of input field. Default array().
659
  *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class' => '****' )
660
  * }
661
  * @return void
662
*/
663
664
function give_docs_link($field) {
665
	$field['url']   = isset($field['url']) ? $field['url'] : 'https://givewp.com/documentation';
666
	$field['title'] = isset($field['title']) ? $field['title'] : 'Documentation';
667
668
	echo '<p class="give-docs-link"><a href="' . esc_url($field['url'])
669
		. '" target="_blank">'
670
		. sprintf(esc_html__('Need Help? See docs on "%s"'), $field['title'])
671
		. '<span class="dashicons dashicons-editor-help"></span></a></p>';
672
}
673
674
675
/**
676
 * Output preview buttons.
677
 *
678
 * @since 1.9
679
 * @param $field
680
 */
681
function give_email_preview_buttons( $field ){
682
	/* @var WP_Post $post */
683
	global $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...
684
685
	$field_id = str_replace( '_preview_buttons', '', $field['id'] );
686
687
	ob_start();
688
689
	echo '<p class="give-field-wrap ' . esc_attr( $field['id'] ) . '_field"><label for="' . give_get_field_name( $field ) . '">' . wp_kses_post( $field['name'] ) . '</label>';
690
691
	echo sprintf(
692
		'<a href="%1$s" class="button-secondary" target="_blank">%2$s</a>',
693
		wp_nonce_url(
694
			add_query_arg(
695
				array( 'give_action' => 'preview_email', 'email_type' => $field_id ),
696
				home_url()
697
			), 'give-preview-email'
698
		),
699
		$field['name']
700
	);
701
702
	echo sprintf(
703
		' <a href="%1$s" aria-label="%2$s" class="button-secondary">%3$s</a>',
704
		wp_nonce_url(
705
			add_query_arg(
706
				array( 'give_action'  => 'send_preview_email', 'email_type' => $field_id, 'give-message' => 'sent-test-email' )
707
			), 'give-send-preview-email' ),
708
		esc_attr__( 'Send Test Email.', 'give' ),
709
		esc_html__( 'Send Test Email', 'give' )
710
	);
711
712
	if ( ! empty( $field['description'] ) ) {
713
		echo '<span class="give-field-description">' . wp_kses_post( $field['desc'] ) . '</span>';
714
	}
715
716
	echo '</p>';
717
718
	echo ob_get_clean();
719
}
720
721
/**
722
 * Get setting field value.
723
 *
724
 * Note: Use only for single post, page or custom post type.
725
 *
726
 * @since  1.8
727
 *
728
 * @param  array $field
729
 * @param  int   $postid
730
 *
731
 * @return mixed
732
 */
733
function give_get_field_value( $field, $postid ) {
734
	if ( isset( $field['attributes']['value'] ) ) {
735
		return $field['attributes']['value'];
736
	}
737
738
	// Get value from db.
739
	$field_value = get_post_meta( $postid, $field['id'], true );
740
741
	/**
742
	 * Filter the field value before apply default value.
743
	 *
744
	 * @since 1.8
745
	 *
746
	 * @param mixed $field_value Field value.
747
	 */
748
	$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
749
750
751
	// Set default value if no any data saved to db.
752
	if ( ! $field_value && isset( $field['default'] ) ) {
753
		$field_value = $field['default'];
754
	}
755
756
	return $field_value;
757
}
758
759
/**
760
 * Get repeater field value.
761
 *
762
 * Note: Use only for single post, page or custom post type.
763
 *
764
 * @since  1.8
765
 *
766
 * @param array $field
767
 * @param array $field_group
768
 * @param array $fields
769
 *
770
 * @return string
771
 */
772
function give_get_repeater_field_value( $field, $field_group, $fields ) {
773
	$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
774
775
	/**
776
	 * Filter the specific repeater field value
777
	 *
778
	 * @since 1.8
779
	 *
780
	 * @param string $field_id
781
	 */
782
	$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
783
784
	/**
785
	 * Filter the repeater field value
786
	 *
787
	 * @since 1.8
788
	 *
789
	 * @param string $field_id
790
	 */
791
	$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
792
793
	return $field_value;
794
}
795
796
/**
797
 * Get repeater field id.
798
 *
799
 * Note: Use only for single post, page or custom post type.
800
 *
801
 * @since  1.8
802
 *
803
 * @param array    $field
804
 * @param array    $fields
805
 * @param int|bool $default
806
 *
807
 * @return string
808
 */
809
function give_get_repeater_field_id( $field, $fields, $default = false ) {
810
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
811
812
	// Get field id.
813
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
814
815
	/**
816
	 * Filter the specific repeater field id
817
	 *
818
	 * @since 1.8
819
	 *
820
	 * @param string $field_id
821
	 */
822
	$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
823
824
825
	/**
826
	 * Filter the repeater field id
827
	 *
828
	 * @since 1.8
829
	 *
830
	 * @param string $field_id
831
	 */
832
	$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
833
834
	return $field_id;
835
}
836
837
838
/**
839
 * Get field name.
840
 *
841
 * @since  1.8
842
 *
843
 * @param  array $field
844
 *
845
 * @return string
846
 */
847
function give_get_field_name( $field ) {
848
	$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
849
850
	/**
851
	 * Filter the field name.
852
	 *
853
	 * @since 1.8
854
	 *
855
	 * @param string $field_name
856
	 */
857
	$field_name = apply_filters( 'give_get_field_name', $field_name, $field );
858
859
	return $field_name;
860
}
861
862
/**
863
 * Output repeater field or multi donation type form on donation from edit screen.
864
 * Note: internal use only.
865
 * @TODO   : Add support for wysiwyg type field.
866
 *
867
 * @since  1.8
868
 *
869
 * @param  array $fields
870
 *
871
 * @return void
872
 */
873
function _give_metabox_form_data_repeater_fields( $fields ) {
874
	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...
875
876
	// Bailout.
877
	if ( ! isset( $fields['fields'] ) || empty( $fields['fields'] ) ) {
878
		return;
879
	}
880
881
	$group_numbering = isset( $fields['options']['group_numbering'] ) ? (int) $fields['options']['group_numbering'] : 0;
882
	$close_tabs      = isset( $fields['options']['close_tabs'] )      ? (int) $fields['options']['close_tabs']      : 0;
883
	?>
884
	<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; ?>">
885
		<?php if ( ! empty( $fields['name'] ) ) : ?>
886
			<p class="give-repeater-field-name"><?php echo $fields['name']; ?></p>
887
		<?php endif; ?>
888
889
		<?php if ( ! empty( $fields['description'] ) ) : ?>
890
			<p class="give-repeater-field-description"><?php echo $fields['description']; ?></p>
891
		<?php endif; ?>
892
893
		<table class="give-repeatable-fields-section-wrapper" cellspacing="0">
894
			<?php
895
			$repeater_field_values = get_post_meta( $thepostid, $fields['id'], true );
896
			$header_title          = isset( $fields['options']['header_title'] )
897
				? $fields['options']['header_title']
898
				: esc_attr__( 'Group', 'give' );
899
900
			$add_default_donation_field = false;
901
902
			// Check if level is not created or we have to add default level.
903
			if ( is_array( $repeater_field_values ) && ( $fields_count = count( $repeater_field_values ) ) ) {
904
				$repeater_field_values = array_values( $repeater_field_values );
905
			} else {
906
				$fields_count               = 1;
907
				$add_default_donation_field = true;
908
			}
909
			?>
910
			<tbody class="container"<?php echo " data-rf-row-count=\"{$fields_count}\""; ?>>
911
				<!--Repeater field group template-->
912
				<tr class="give-template give-row">
913
					<td class="give-repeater-field-wrap give-column" colspan="2">
914
						<div class="give-row-head give-move">
915
							<button type="button" class="handlediv button-link"><span class="toggle-indicator"></span>
916
							</button>
917
							<span class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-</span>
918
							<h2>
919
								<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
920
							</h2>
921
						</div>
922
						<div class="give-row-body">
923
							<?php foreach ( $fields['fields'] as $field ) : ?>
924
								<?php if ( ! give_is_field_callback_exist( $field ) ) {
925
									continue;
926
								} ?>
927
								<?php
928
								$field['repeat']              = true;
929
								$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields );
930
								$field['id']                  = str_replace( array( '[', ']' ), array(
931
									'_',
932
									'',
933
								), $field['repeatable_field_id'] );
934
								?>
935
								<?php give_render_field( $field ); ?>
936
							<?php endforeach; ?>
937
						</div>
938
					</td>
939
				</tr>
940
941
				<?php if ( ! empty( $repeater_field_values ) ) : ?>
942
					<!--Stored repeater field group-->
943
					<?php foreach ( $repeater_field_values as $index => $field_group ) : ?>
944
						<tr class="give-row">
945
							<td class="give-repeater-field-wrap give-column" colspan="2">
946
								<div class="give-row-head give-move">
947
									<button type="button" class="handlediv button-link">
948
										<span class="toggle-indicator"></span></button>
949
									<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
950
									</sapn>
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, $index );
963
										$field['attributes']['value'] = give_get_repeater_field_value( $field, $field_group, $fields );
964
										$field['id']                  = str_replace( array( '[', ']' ), array(
965
											'_',
966
											'',
967
										), $field['repeatable_field_id'] );
968
										?>
969
										<?php give_render_field( $field ); ?>
970
									<?php endforeach; ?>
971
								</div>
972
							</td>
973
						</tr>
974
					<?php endforeach;; ?>
975
976
				<?php elseif ( $add_default_donation_field ) : ?>
977
					<!--Default repeater field group-->
978
					<tr class="give-row">
979
						<td class="give-repeater-field-wrap give-column" colspan="2">
980
							<div class="give-row-head give-move">
981
								<button type="button" class="handlediv button-link">
982
									<span class="toggle-indicator"></span></button>
983
								<sapn class="give-remove" title="<?php esc_html_e( 'Remove Group', 'give' ); ?>">-
984
								</sapn>
985
								<h2>
986
									<span data-header-title="<?php echo $header_title; ?>"><?php echo $header_title; ?></span>
987
								</h2>
988
							</div>
989
							<div class="give-row-body">
990
								<?php
991
								foreach ( $fields['fields'] as $field ) :
992
									if ( ! give_is_field_callback_exist( $field ) ) {
993
										continue;
994
									}
995
996
									$field['repeat']              = true;
997
									$field['repeatable_field_id'] = give_get_repeater_field_id( $field, $fields, 0 );
998
									$field['attributes']['value'] = apply_filters( "give_default_field_group_field_{$field['id']}_value", ( ! empty( $field['default'] ) ? $field['default'] : '' ), $field );
999
									$field['id']                  = str_replace( array( '[', ']' ), array(
1000
										'_',
1001
										'',
1002
									), $field['repeatable_field_id'] );
1003
									give_render_field( $field );
1004
								endforeach;
1005
								?>
1006
							</div>
1007
						</td>
1008
					</tr>
1009
				<?php endif; ?>
1010
			</tbody>
1011
			<tfoot>
1012
				<tr>
1013
					<?php
1014
					$add_row_btn_title = isset( $fields['options']['add_button'] )
1015
						? $add_row_btn_title = $fields['options']['add_button']
1016
						: esc_html__( 'Add Row', 'give' );
1017
					?>
1018
					<td colspan="2" class="give-add-repeater-field-section-row-wrap">
1019
						<span class="button button-primary give-add-repeater-field-section-row"><?php echo $add_row_btn_title; ?></span>
1020
					</td>
1021
				</tr>
1022
			</tfoot>
1023
		</table>
1024
	</div>
1025
	<?php
1026
}
1027
1028
1029
/**
1030
 * Get current setting tab.
1031
 *
1032
 * @since  1.8
1033
 * @return string
1034
 */
1035
function give_get_current_setting_tab() {
1036
	// Get current setting page.
1037
	$current_setting_page = give_get_current_setting_page();
1038
1039
	/**
1040
	 * Filter the default tab for current setting page.
1041
	 *
1042
	 * @since 1.8
1043
	 *
1044
	 * @param string
1045
	 */
1046
	$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' );
1047
1048
	// Get current tab.
1049
	$current_tab = empty( $_GET['tab'] ) ? $default_current_tab : urldecode( $_GET['tab'] );
1050
1051
	// Output.
1052
	return $current_tab;
1053
}
1054
1055
1056
/**
1057
 * Get current setting section.
1058
 *
1059
 * @since  1.8
1060
 * @return string
1061
 */
1062
function give_get_current_setting_section() {
1063
	// Get current tab.
1064
	$current_tab = give_get_current_setting_tab();
1065
1066
	/**
1067
	 * Filter the default section for current setting page tab.
1068
	 *
1069
	 * @since 1.8
1070
	 *
1071
	 * @param string
1072
	 */
1073
	$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' );
1074
1075
	// Get current section.
1076
	$current_section = empty( $_REQUEST['section'] ) ? $default_current_section : urldecode( $_REQUEST['section'] );
1077
1078
	//Output.
1079
	return $current_section;
1080
}
1081
1082
/**
1083
 * Get current setting page.
1084
 *
1085
 * @since  1.8
1086
 * @return string
1087
 */
1088
function give_get_current_setting_page() {
1089
	// Get current page.
1090
	$setting_page = ! empty( $_GET['page'] ) ? urldecode( $_GET['page'] ) : '';
1091
1092
	//Output.
1093
	return $setting_page;
1094
}
1095
1096
/**
1097
 * Set value for Form content --> Display content field setting.
1098
 *
1099
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_display_content is not set yet.
1100
 *
1101
 * @since  1.8
1102
 *
1103
 * @param  mixed $field_value Field Value.
1104
 * @param  array $field       Field args.
1105
 * @param  int   $postid      Form/Post ID.
1106
 *
1107
 * @return string
1108
 */
1109
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...
1110
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1111
1112
	if (
1113
		! get_post_meta( $postid, '_give_display_content', true )
1114
		&& $show_content
1115
		&& ( 'none' !== $show_content )
1116
	) {
1117
		$field_value = 'enabled';
1118
	}
1119
1120
	return $field_value;
1121
}
1122
1123
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 );
1124
1125
1126
/**
1127
 * Set value for Form content --> Content placement field setting.
1128
 *
1129
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_content_placement is not set yet.
1130
 *
1131
 * @since  1.8
1132
 *
1133
 * @param  mixed $field_value Field Value.
1134
 * @param  array $field       Field args.
1135
 * @param  int   $postid      Form/Post ID.
1136
 *
1137
 * @return string
1138
 */
1139
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...
1140
	$show_content = get_post_meta( $postid, '_give_content_option', true );
1141
1142
	if (
1143
		! get_post_meta( $postid, '_give_content_placement', true )
1144
		&& ( 'none' !== $show_content )
1145
	) {
1146
		$field_value = $show_content;
1147
	}
1148
1149
	return $field_value;
1150
}
1151
1152
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 );
1153
1154
1155
/**
1156
 * Set value for Terms and Conditions --> Terms and Conditions field setting.
1157
 *
1158
 * Backward compatibility:  set value by _give_terms_option form meta field value if it's value is none.
1159
 *
1160
 * @since  1.8
1161
 *
1162
 * @param  mixed $field_value Field Value.
1163
 * @param  array $field       Field args.
1164
 * @param  int   $postid      Form/Post ID.
1165
 *
1166
 * @return string
1167
 */
1168
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...
1169
	$term_option = get_post_meta( $postid, '_give_terms_option', true );
1170
1171
	if ( in_array( $term_option, array( 'none', 'yes' ) ) ) {
1172
		$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' );
1173
	}
1174
1175
	return $field_value;
1176
}
1177
1178
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 );
1179
1180
1181
/**
1182
 * Set value for Form Display --> Offline Donation --> Billing Fields.
1183
 *
1184
 * Backward compatibility:  set value by _give_offline_donation_enable_billing_fields_single form meta field value if it's value is on.
1185
 *
1186
 * @since  1.8
1187
 *
1188
 * @param  mixed $field_value Field Value.
1189
 * @param  array $field       Field args.
1190
 * @param  int   $postid      Form/Post ID.
1191
 *
1192
 * @return string
1193
 */
1194
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...
1195
	$offline_donation = get_post_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true );
1196
1197
	if ( 'on' === $offline_donation ) {
1198
		$field_value = 'enabled';
1199
	}
1200
1201
	return $field_value;
1202
}
1203
1204
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 );
1205
1206
1207
/**
1208
 * Set value for Donation Options --> Custom Amount.
1209
 *
1210
 * Backward compatibility:  set value by _give_custom_amount form meta field value if it's value is yes or no.
1211
 *
1212
 * @since  1.8
1213
 *
1214
 * @param  mixed $field_value Field Value.
1215
 * @param  array $field       Field args.
1216
 * @param  int   $postid      Form/Post ID.
1217
 *
1218
 * @return string
1219
 */
1220
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...
1221
	$custom_amount = get_post_meta( $postid, '_give_custom_amount', true );
1222
1223
	if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) {
1224
		$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' );
1225
	}
1226
1227
	return $field_value;
1228
}
1229
1230
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 );
1231
1232
1233
/**
1234
 * Set value for Donation Goal --> Donation Goal.
1235
 *
1236
 * Backward compatibility:  set value by _give_goal_option form meta field value if it's value is yes or no.
1237
 *
1238
 * @since  1.8
1239
 *
1240
 * @param  mixed $field_value Field Value.
1241
 * @param  array $field       Field args.
1242
 * @param  int   $postid      Form/Post ID.
1243
 *
1244
 * @return string
1245
 */
1246
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...
1247
	$goal_option = get_post_meta( $postid, '_give_goal_option', true );
1248
1249
	if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) {
1250
		$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' );
1251
	}
1252
1253
	return $field_value;
1254
}
1255
1256
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 );
1257
1258
/**
1259
 * Set value for Donation Goal --> close Form.
1260
 *
1261
 * Backward compatibility:  set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes or no.
1262
 *
1263
 * @since  1.8
1264
 *
1265
 * @param  mixed $field_value Field Value.
1266
 * @param  array $field       Field args.
1267
 * @param  int   $postid      Form/Post ID.
1268
 *
1269
 * @return string
1270
 */
1271
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...
1272
	$close_form = get_post_meta( $postid, '_give_close_form_when_goal_achieved', true );
1273
1274
	if ( in_array( $close_form, array( 'yes', 'no' ) ) ) {
1275
		$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' );
1276
	}
1277
1278
	return $field_value;
1279
}
1280
1281
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 );
1282
1283
1284
/**
1285
 * Set value for Form display --> Guest Donation.
1286
 *
1287
 * Backward compatibility:  set value by _give_logged_in_only form meta field value if it's value is yes or no.
1288
 *
1289
 * @since  1.8
1290
 *
1291
 * @param  mixed $field_value Field Value.
1292
 * @param  array $field       Field args.
1293
 * @param  int   $postid      Form/Post ID.
1294
 *
1295
 * @return string
1296
 */
1297
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...
1298
	$guest_donation = get_post_meta( $postid, '_give_logged_in_only', true );
1299
1300
	if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) {
1301
		$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' );
1302
	}
1303
1304
	return $field_value;
1305
}
1306
1307
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 );
1308
1309
/**
1310
 * Set value for Offline Donations --> Offline Donations.
1311
 *
1312
 * Backward compatibility:  set value by _give_customize_offline_donations form meta field value if it's value is yes or no.
1313
 *
1314
 * @since  1.8
1315
 *
1316
 * @param  mixed $field_value Field Value.
1317
 * @param  array $field       Field args.
1318
 * @param  int   $postid      Form/Post ID.
1319
 *
1320
 * @return string
1321
 */
1322
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...
1323
	$customize_offline_text = get_post_meta( $postid, '_give_customize_offline_donations', true );
1324
1325
	if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) {
1326
		$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' );
1327
	}
1328
1329
	return $field_value;
1330
}
1331
1332
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 );
1333
1334
1335
/**
1336
 * Set repeater field id for multi donation form.
1337
 *
1338
 * @since 1.8
1339
 *
1340
 * @param int   $field_id
1341
 * @param array $field
1342
 * @param array $fields
1343
 * @param bool  $default
1344
 *
1345
 * @return mixed
1346
 */
1347
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...
1348
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1349
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1350
1351
	return $field_id;
1352
}
1353
1354
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1355
1356
/**
1357
 * Set repeater field value for multi donation form.
1358
 *
1359
 * @since 1.8
1360
 *
1361
 * @param string $field_value
1362
 * @param array  $field
1363
 * @param array  $field_group
1364
 * @param array  $fields
1365
 *
1366
 * @return mixed
1367
 */
1368
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...
1369
	$field_value = $field_group[ $field['id'] ]['level_id'];
1370
1371
	return $field_value;
1372
}
1373
1374
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1375
1376
/**
1377
 * Set default value for _give_id field.
1378
 *
1379
 * @since 1.8
1380
 *
1381
 * @param $field
1382
 *
1383
 * @return string
1384
 */
1385
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...
1386
	return 0;
1387
}
1388
1389
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1390
1391
/**
1392
 * Set default value for _give_default field.
1393
 *
1394
 * @since 1.8
1395
 *
1396
 * @param $field
1397
 *
1398
 * @return string
1399
 */
1400
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...
1401
	return 'default';
1402
}
1403
1404
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1405
1406
/**
1407
 * Set repeater field editor id for field type wysiwyg.
1408
 *
1409
 * @since 1.8
1410
 *
1411
 * @param $field_name
1412
 * @param $field
1413
 *
1414
 * @return string
1415
 */
1416
function give_repeater_field_set_editor_id( $field_name, $field ) {
1417
	if ( isset( $field['repeatable_field_id'] ) &&  'wysiwyg' == $field['type'] ) {
1418
		$field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1419
	}
1420
1421
	return $field_name;
1422
}
1423
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );