Completed
Push — issues/611 ( 19900c...46c90d )
by Ravinder
21:01
created

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

Complexity

Conditions 2
Paths 2

Size

Total Lines 39
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

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