Completed
Push — hotfix/fix_notices ( 9d56c9...88019d )
by Ravinder
17:04
created

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

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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