Completed
Push — issues/1038 ( ccd3e1...b3f622 )
by Ravinder
17:47
created

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

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 18
rs 9.4285
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
		case 'textarea' :
57
			$func_name = "{$func_name_prefix}_textarea_input";
58
			break;
59
60
		case 'colorpicker' :
61
			$func_name = "{$func_name_prefix}_{$field['type']}";
62
			break;
63
64
		case 'hidden':
65
		case 'levels_id':
66
			$func_name = "{$func_name_prefix}_hidden_input";
67
			break;
68
69
		case 'group' :
70
			$func_name = "_{$func_name_prefix}_metabox_form_data_repeater_fields";
71
			break;
72
73
		case 'give_default_radio_inline':
74
			$func_name = "{$func_name_prefix}_radio";
75
			break;
76
77
		default:
78
79
			if (
80
				array_key_exists( 'callback', $field )
81
				&& ! empty( $field['callback'] )
82
			) {
83
				$func_name = $field['callback'];
84
			} else {
85
				$func_name = "{$func_name_prefix}_{$field['type']}";
86
			}
87
	}
88
89
	/**
90
	 * Filter the metabox setting render function
91
	 *
92
	 * @since 1.8
93
	 */
94
	$func_name = apply_filters( 'give_get_field_callback', $func_name, $field );
95
96
	// Exit if not any function exist.
97
	// Check if render callback exist or not.
98
	if ( empty( $func_name ) ) {
99
		return false;
100
	} elseif ( is_string( $func_name ) && ! function_exists( "$func_name" ) ) {
101
		return false;
102
	} elseif ( is_array( $func_name ) && ! method_exists( $func_name[0], "$func_name[1]" ) ) {
103
		return false;
104
	}
105
106
	return $func_name;
107
}
108
109
/**
110
 * This function adds backward compatibility to render cmb2 type field type.
111
 *
112
 * @since  1.8
113
 *
114
 * @param  array $field Field argument array.
115
 *
116
 * @return bool
117
 */
118
function give_render_field( $field ) {
119
120
	// Check if render callback exist or not.
121
	if ( ! ( $func_name = give_get_field_callback( $field ) ) ) {
122
		return false;
123
	}
124
125
	$field = give_backward_compatibility_setting_api_1_8( $field );
126
127
	// Call render function.
128
	if ( is_array( $func_name ) ) {
129
		$func_name[0]->$func_name[1]( $field );
130
	} else {
131
		$func_name( $field );
132
	}
133
134
	return true;
135
}
136
137
/**
138
 * Output a text input box.
139
 *
140
 * @since  1.8
141
 * @since  1.9 Render field with field api
142
 *
143
 * @param array $field Field arguments
144
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
145
 *
146
 * @return void
147
 */
148
function give_text_input( $field ) {
149
	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...
150
151
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
152
	$field['value'] = give_get_field_value( $field, $thepostid );
153
	$data_type      = empty( $field['data_type'] ) ? '' : $field['data_type'];
154
155
	switch ( $data_type ) {
156
		case 'price' :
157
			$field['value'] = ( ! empty( $field['value'] ) ? give_format_amount( $field['value'] ) : $field['value'] );
158
159
			$field['before_field'] = ! empty( $field['before_field'] ) ? $field['before_field'] : ( give_get_option( 'currency_position', 'before' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '' );
160
			$field['after_field']  = ! empty( $field['after_field'] ) ? $field['after_field'] : ( give_get_option( 'currency_position', 'before' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '' );
161
			break;
162
163
		case 'decimal' :
164
			$field['attributes']['class'] .= ' give_input_decimal';
165
			$field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( $field['value'] ) : $field['value'] );
166
			break;
167
168
		default :
169
			break;
170
	}
171
172
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
173
174
	// Set description.
175
	// Backward compatibility ( 1.8=<version>1.9).
176
	$field['after_field'] = ! empty( $field['after_field'] )
177
		? $field['after_field'] . give_get_field_description( $field )
178
		: give_get_field_description( $field );
179
180
	// Reset label for repeater field compatibility.
181
	$field['name'] = give_get_field_name( $field );
182
183
	// Render Field.
184
	echo Give_Fields_API::render_tag( $field );
185
}
186
187
/**
188
 * Output a hidden input box.
189
 *
190
 * @since  1.8
191
 * @since  1.9 Render field with field api
192
 *
193
 * @param array $field Field arguments
194
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
195
 *
196
 * @return void
197
 */
198
function give_hidden_input( $field ) {
199
	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...
200
201
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
202
	$field['value'] = give_get_field_value( $field, $thepostid );
203
204
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
205
206
	// Reset label for repeater field compatibility.
207
	$field['name'] = give_get_field_name( $field );
208
209
	// Render Field.
210
	echo Give_Fields_API::render_tag( $field );
211
}
212
213
/**
214
 * Output a textarea input box.
215
 *
216
 * @since  1.8
217
 * @since  1.9 Render field with field api
218
 *
219
 * @param array $field Field arguments
220
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
221
 *
222
 * @return void
223
 */
224
function give_textarea_input( $field ) {
225
	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...
226
227
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
228
	$field['value'] = give_get_field_value( $field, $thepostid );
229
230
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
231
232
	// Set description.
233
	// Backward compatibility ( 1.8=<version>1.9).
234
	$field['after_field'] = ! empty( $field['after_field'] )
235
		? $field['after_field'] . give_get_field_description( $field )
236
		: give_get_field_description( $field );
237
238
	// Reset label for repeater field compatibility.
239
	$field['name'] = give_get_field_name( $field );
240
241
	// Render Field.
242
	echo Give_Fields_API::render_tag( $field );
243
}
244
245
/**
246
 * Output a wysiwyg.
247
 *
248
 * @since  1.8
249
 *
250
 * @param  array $field         {
251
 *                              Optional. Array of WordPress editor field arguments.
252
 *
253
 * @type string  $id            Field ID. Default ''.
254
 * @type string  $style         CSS style for input field. Default ''.
255
 * @type string  $wrapper_class CSS class to use for wrapper of input field. Default ''.
256
 * @type string  $value         Value of input field. Default ''.
257
 * @type string  $name          Name of input field. Default ''.
258
 * @type string  $description   Description of input field. Default ''.
259
 * @type array   $attributes    List of attributes of input field. Default array().
260
 *                                               for example: 'attributes' => array( 'placeholder' => '*****', 'class'
261
 *                                               => '****' )
262
 * }
263
 * @return void
264
 */
265
function give_wysiwyg( $field ) {
266
	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...
267
268
	$thepostid                = empty( $thepostid ) ? $post->ID : $thepostid;
269
	$field['value']           = give_get_field_value( $field, $thepostid );
270
	$field['unique_field_id'] = give_get_field_name( $field );
271
	$field['wrapper_type']    = 'div';
272
273
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
274
275
	$field['wrapper_attributes']['data-wp-editor'] = base64_encode( json_encode( array(
276
			$field['value'],
277
			$field['unique_field_id'],
278
			//$field['editor_attributes'],
279
		) ) ) . '"';
280
281
	// Set description.
282
	// Backward compatibility ( 1.8=<version>1.9).
283
	$field['after_field'] = ! empty( $field['after_field'] )
284
		? $field['after_field'] . give_get_field_description( $field )
285
		: give_get_field_description( $field );
286
287
	// Render Field.
288
	echo Give_Fields_API::render_tag( $field );
289
290
	// @todo: label must be linked to wordpress editor.
291
}
292
293
/**
294
 * Output a checkbox input box.
295
 *
296
 * @since  1.8
297
 * @since  1.9 Render field with field api
298
 *
299
 * @param array $field Field arguments
300
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
301
 *
302
 * @return void
303
 */
304
function give_checkbox( $field ) {
305
	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...
306
307
	$thepostid        = empty( $thepostid ) ? $post->ID : $thepostid;
308
	$field['value']   = give_get_field_value( $field, $thepostid );
309
	$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on';
310
311
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
312
313
	// Set description.
314
	// Backward compatibility ( 1.8=<version>1.9).
315
	$field['after_field'] = ! empty( $field['after_field'] )
316
		? $field['after_field'] . give_get_field_description( $field )
317
		: give_get_field_description( $field );
318
319
	// Reset label for repeater field compatibility.
320
	$field['name'] = give_get_field_name( $field );
321
322
	// Render Field.
323
	echo Give_Fields_API::render_tag( $field );
324
}
325
326
/**
327
 * Output a select input box.
328
 *
329
 * @since  1.8
330
 * @since  1.9 Render field with field api
331
 *
332
 * @param array $field Field arguments
333
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
334
 *
335
 * @return void
336
 */
337
function give_select( $field ) {
338
	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...
339
340
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
341
	$field['value'] = give_get_field_value( $field, $thepostid );
342
343
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
344
345
	// Set description.
346
	// Backward compatibility ( 1.8=<version>1.9).
347
	$field['after_field'] = ! empty( $field['after_field'] )
348
		? $field['after_field'] . give_get_field_description( $field )
349
		: give_get_field_description( $field );
350
351
	// Reset label for repeater field compatibility.
352
	$field['name'] = give_get_field_name( $field );
353
354
	// Render Field.
355
	echo Give_Fields_API::render_tag( $field );
356
}
357
358
/**
359
 * Output a radio input box.
360
 *
361
 * @since  1.8
362
 * @since  1.9 Render field with field api
363
 *
364
 * @param array $field Field arguments
365
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
366
 * @param array $field
367
 *
368
 * @return void
369
 */
370
function give_radio( $field ) {
371
	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...
372
373
	$thepostid             = empty( $thepostid ) ? $post->ID : $thepostid;
374
	$field['value']        = give_get_field_value( $field, $thepostid );
375
	$field['wrapper_type'] = 'fieldset';
376
377
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
378
379
	// Set description.
380
	// Backward compatibility ( 1.8=<version>1.9).
381
	$field['after_field'] = ! empty( $field['after_field'] )
382
		? $field['after_field'] . give_get_field_description( $field )
383
		: give_get_field_description( $field );
384
385
	// Reset label for repeater field compatibility.
386
	$field['name'] = give_get_field_name( $field );
387
388
	// Render Field.
389
	echo Give_Fields_API::render_tag( $field );
390
}
391
392
/**
393
 * Output a colorpicker.
394
 *
395
 * @since  1.8
396
 * @since  1.9 Render field with field api
397
 *
398
 * @param array $field Field arguments
399
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
400
 * @param array $field
401
 *
402
 * @return void
403
 */
404
function give_colorpicker( $field ) {
405
	global $thepostid, $post;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
406
407
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
408
	$field['value'] = give_get_field_value( $field, $thepostid );
409
	$field['type']  = 'text';
410
411
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
412
413
	// Set description.
414
	// Backward compatibility ( 1.8=<version>1.9).
415
	$field['after_field'] = ! empty( $field['after_field'] )
416
		? $field['after_field'] . give_get_field_description( $field )
417
		: give_get_field_description( $field );
418
419
	// Reset label for repeater field compatibility.
420
	$field['name'] = give_get_field_name( $field );
421
422
	// Render Field.
423
	echo Give_Fields_API::render_tag( $field );
424
}
425
426
427
/**
428
 * Output a media upload field.
429
 *
430
 * @since  1.8
431
 * @since  1.9 Render field with field api
432
 *
433
 * @param array $field Field arguments
434
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
435
 * @param array $field
436
 *
437
 * @return void
438
 */
439
function give_media( $field ) {
440
	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...
441
442
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
443
444
	$thepostid      = empty( $thepostid ) ? $post->ID : $thepostid;
445
	$field['value'] = give_get_field_value( $field, $thepostid );
446
447
	// Set description.
448
	// Backward compatibility ( 1.8=<version>1.9).
449
	$field['after_field'] = ! empty( $field['after_field'] )
450
		? $field['after_field'] . give_get_field_description( $field )
451
		: give_get_field_description( $field );
452
453
	// Reset label for repeater field compatibility.
454
	$field['name'] = give_get_field_name( $field );
455
456
	// Render Field.
457
	echo Give_Fields_API::render_tag( $field );
458
}
459
460
/**
461
 * Output a select field with payment options list.
462
 *
463
 * @since  1.8
464
 *
465
 * @param  array $field
466
 *
467
 * @return void
468
 */
469
function give_default_gateway( $field ) {
470
	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...
471
472
	// get all active payment gateways.
473
	$gateways         = give_get_enabled_payment_gateways( $thepostid );
474
	$field['options'] = array();
475
476
	// Set field option value.
477
	if ( ! empty( $gateways ) ) {
478
		foreach ( $gateways as $key => $option ) {
479
			$field['options'][ $key ] = $option['admin_label'];
480
		}
481
	}
482
483
	// Add a field to the Give Form admin single post view of this field
484
	if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
485
		$field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] );
486
	}
487
488
	$field['type'] = 'select';
489
490
	// Render select field.
491
	give_select( $field );
492
}
493
494
/**
495
 * Output the documentation link.
496
 *
497
 * @since  1.8
498
 * @since  1.9 Render field with field api
499
 *
500
 * @param array $field Field arguments
501
 *                     Check includes/forms/api/class-give-field-api.php:28 for arguments.
502
 *
503
 * @return void
504
 */
505
506
function give_docs_link( $field ) {
507
	// $field = give_backward_compatibility_setting_api_1_8( $field );
0 ignored issues
show
Unused Code Comprehensibility introduced by
42% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
508
509
	// Set default class.
510
	// Backward compatibility ( 1.8=<version>1.9).
511
	$field['wrapper_attributes']['class'] = ! empty( $field['wrapper_attributes']['class'] )
512
		? "{$field['wrapper_attributes']['class']} give-docs-link"
513
		: 'give-docs-link';
514
515
	// Render Field.
516
	echo Give_Fields_API::render_tag( $field );
517
}
518
519
/**
520
 * Get setting field value.
521
 *
522
 * Note: Use only for single post, page or custom post type.
523
 *
524
 * @since  1.8
525
 *
526
 * @param  array $field
527
 * @param  int   $postid
528
 *
529
 * @return mixed
530
 */
531
function give_get_field_value( $field, $postid ) {
532
	if ( isset( $field['attributes']['value'] ) ) {
533
		return $field['attributes']['value'];
534
	}
535
536
	// Get value from db.
537
	$field_value = get_post_meta( $postid, $field['id'], true );
538
539
	/**
540
	 * Filter the field value before apply default value.
541
	 *
542
	 * @since 1.8
543
	 *
544
	 * @param mixed $field_value Field value.
545
	 */
546
	$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid );
547
548
	// Set default value if no any data saved to db.
549
	if ( ! $field_value && isset( $field['default'] ) ) {
550
		$field_value = $field['default'];
551
	}
552
553
	return $field_value;
554
}
555
556
557
/**
558
 * Get field description html.
559
 *
560
 * @since 1.8
561
 *
562
 * @param $field
563
 *
564
 * @return string
565
 */
566
function give_get_field_description( $field ) {
567
	$field_desc_html = '';
568
	if ( ! empty( $field['description'] ) ) {
569
		$field_desc_html = '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>';
570
	}
571
572
	return $field_desc_html;
573
}
574
575
576
/**
577
 * Get field custom attributes as string.
578
 *
579
 * @since 1.8
580
 *
581
 * @param $field
582
 *
583
 * @return string
584
 */
585
function give_get_custom_attributes( $field ) {
586
	// Custom attribute handling
587
	$custom_attributes = array();
588
589
	if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) {
590
591
		foreach ( $field['attributes'] as $attribute => $value ) {
592
			$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"';
593
		}
594
	}
595
596
	return implode( ' ', $custom_attributes );
597
}
598
599
/**
600
 * Get repeater field value.
601
 *
602
 * Note: Use only for single post, page or custom post type.
603
 *
604
 * @since  1.8
605
 *
606
 * @param array $field
607
 * @param array $field_group
608
 * @param array $fields
609
 *
610
 * @return string
611
 */
612
function give_get_repeater_field_value( $field, $field_group, $fields ) {
613
	$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' );
614
615
	/**
616
	 * Filter the specific repeater field value
617
	 *
618
	 * @since 1.8
619
	 *
620
	 * @param string $field_id
621
	 */
622
	$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields );
623
624
	/**
625
	 * Filter the repeater field value
626
	 *
627
	 * @since 1.8
628
	 *
629
	 * @param string $field_id
630
	 */
631
	$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields );
632
633
	return $field_value;
634
}
635
636
/**
637
 * Get repeater field id.
638
 *
639
 * Note: Use only for single post, page or custom post type.
640
 *
641
 * @since  1.8
642
 *
643
 * @param array    $field
644
 * @param array    $fields
645
 * @param int|bool $default
646
 *
647
 * @return string
648
 */
649
function give_get_repeater_field_id( $field, $fields, $default = false ) {
650
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
651
652
	// Get field id.
653
	$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}]";
654
655
	/**
656
	 * Filter the specific repeater field id
657
	 *
658
	 * @since 1.8
659
	 *
660
	 * @param string $field_id
661
	 */
662
	$field_id = apply_filters( "give_get_repeater_field_{$field['id']}_id", $field_id, $field, $fields, $default );
663
664
	/**
665
	 * Filter the repeater field id
666
	 *
667
	 * @since 1.8
668
	 *
669
	 * @param string $field_id
670
	 */
671
	$field_id = apply_filters( 'give_get_repeater_field_id', $field_id, $field, $fields, $default );
672
673
	return $field_id;
674
}
675
676
677
/**
678
 * Get field name.
679
 *
680
 * @since  1.8
681
 *
682
 * @param  array $field
683
 *
684
 * @return string
685
 */
686
function give_get_field_name( $field ) {
687
	$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] );
688
689
	/**
690
	 * Filter the field name.
691
	 *
692
	 * @since 1.8
693
	 *
694
	 * @param string $field_name
695
	 */
696
	$field_name = apply_filters( 'give_get_field_name', $field_name, $field );
697
698
	return $field_name;
699
}
700
701
/**
702
 * Output repeater field or multi donation type form on donation from edit screen.
703
 * Note: internal use only.
704
 *
705
 * @since  1.8
706
 *
707
 * @param  array $fields
708
 *
709
 * @return void
710
 */
711
function _give_metabox_form_data_repeater_fields( $fields ) {
712
	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...
713
	$fields            = give_backward_compatibility_setting_api_1_8( $fields );
714
	$fields['value']   = get_post_meta( $thepostid, $fields['id'], true );
715
	$fields['wrapper'] = false;
716
717
	// error_log( print_r( $fields, true ) . "\n", 3, WP_CONTENT_DIR . '/debug_new.log' );
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
718
719
	echo Give_Fields_API::render_tag( $fields );
720
}
721
722
723
/**
724
 * Get current setting tab.
725
 *
726
 * @since  1.8
727
 * @return string
728
 */
729
function give_get_current_setting_tab() {
730
	// Get current setting page.
731
	$current_setting_page = give_get_current_setting_page();
732
733
	/**
734
	 * Filter the default tab for current setting page.
735
	 *
736
	 * @since 1.8
737
	 *
738
	 * @param string
739
	 */
740
	$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' );
741
742
	// Get current tab.
743
	$current_tab = empty( $_GET['tab'] ) ? $default_current_tab : urldecode( $_GET['tab'] );
744
745
	// Output.
746
	return $current_tab;
747
}
748
749
750
/**
751
 * Get current setting section.
752
 *
753
 * @since  1.8
754
 * @return string
755
 */
756
function give_get_current_setting_section() {
757
	// Get current tab.
758
	$current_tab = give_get_current_setting_tab();
759
760
	/**
761
	 * Filter the default section for current setting page tab.
762
	 *
763
	 * @since 1.8
764
	 *
765
	 * @param string
766
	 */
767
	$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' );
768
769
	// Get current section.
770
	$current_section = empty( $_REQUEST['section'] ) ? $default_current_section : urldecode( $_REQUEST['section'] );
771
772
	// Output.
773
	return $current_section;
774
}
775
776
/**
777
 * Get current setting page.
778
 *
779
 * @since  1.8
780
 * @return string
781
 */
782
function give_get_current_setting_page() {
783
	// Get current page.
784
	$setting_page = ! empty( $_GET['page'] ) ? urldecode( $_GET['page'] ) : '';
785
786
	// Output.
787
	return $setting_page;
788
}
789
790
/**
791
 * Set value for Form content --> Display content field setting.
792
 *
793
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_display_content is not set
794
 * yet.
795
 *
796
 * @since  1.8
797
 *
798
 * @param  mixed $field_value Field Value.
799
 * @param  array $field       Field args.
800
 * @param  int   $postid      Form/Post ID.
801
 *
802
 * @return string
803
 */
804
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...
805
	$show_content = get_post_meta( $postid, '_give_content_option', true );
806
807
	if (
808
		! get_post_meta( $postid, '_give_display_content', true )
809
		&& $show_content
810
		&& ( 'none' !== $show_content )
811
	) {
812
		$field_value = 'enabled';
813
	}
814
815
	return $field_value;
816
}
817
818
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 );
819
820
821
/**
822
 * Set value for Form content --> Content placement field setting.
823
 *
824
 * Backward compatibility:  set value by _give_content_option form meta field value if _give_content_placement is not
825
 * set yet.
826
 *
827
 * @since  1.8
828
 *
829
 * @param  mixed $field_value Field Value.
830
 * @param  array $field       Field args.
831
 * @param  int   $postid      Form/Post ID.
832
 *
833
 * @return string
834
 */
835
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...
836
	$show_content = get_post_meta( $postid, '_give_content_option', true );
837
838
	if (
839
		! get_post_meta( $postid, '_give_content_placement', true )
840
		&& ( 'none' !== $show_content )
841
	) {
842
		$field_value = $show_content;
843
	}
844
845
	return $field_value;
846
}
847
848
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 );
849
850
851
/**
852
 * Set value for Terms and Conditions --> Terms and Conditions field setting.
853
 *
854
 * Backward compatibility:  set value by _give_terms_option form meta field value if it's value is none.
855
 *
856
 * @since  1.8
857
 *
858
 * @param  mixed $field_value Field Value.
859
 * @param  array $field       Field args.
860
 * @param  int   $postid      Form/Post ID.
861
 *
862
 * @return string
863
 */
864
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...
865
	$term_option = get_post_meta( $postid, '_give_terms_option', true );
866
867
	if ( in_array( $term_option, array( 'none', 'yes' ) ) ) {
868
		$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' );
869
	}
870
871
	return $field_value;
872
}
873
874
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 );
875
876
877
/**
878
 * Set value for Form Display --> Offline Donation --> Billing Fields.
879
 *
880
 * Backward compatibility:  set value by _give_offline_donation_enable_billing_fields_single form meta field value if
881
 * it's value is on.
882
 *
883
 * @since  1.8
884
 *
885
 * @param  mixed $field_value Field Value.
886
 * @param  array $field       Field args.
887
 * @param  int   $postid      Form/Post ID.
888
 *
889
 * @return string
890
 */
891
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...
892
	$offline_donation = get_post_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true );
893
894
	if ( 'on' === $offline_donation ) {
895
		$field_value = 'enabled';
896
	}
897
898
	return $field_value;
899
}
900
901
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 );
902
903
904
/**
905
 * Set value for Donation Options --> Custom Amount.
906
 *
907
 * Backward compatibility:  set value by _give_custom_amount form meta field value if it's value is yes or no.
908
 *
909
 * @since  1.8
910
 *
911
 * @param  mixed $field_value Field Value.
912
 * @param  array $field       Field args.
913
 * @param  int   $postid      Form/Post ID.
914
 *
915
 * @return string
916
 */
917
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...
918
	$custom_amount = get_post_meta( $postid, '_give_custom_amount', true );
919
920
	if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) {
921
		$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' );
922
	}
923
924
	return $field_value;
925
}
926
927
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 );
928
929
930
/**
931
 * Set value for Donation Goal --> Donation Goal.
932
 *
933
 * Backward compatibility:  set value by _give_goal_option form meta field value if it's value is yes or no.
934
 *
935
 * @since  1.8
936
 *
937
 * @param  mixed $field_value Field Value.
938
 * @param  array $field       Field args.
939
 * @param  int   $postid      Form/Post ID.
940
 *
941
 * @return string
942
 */
943
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...
944
	$goal_option = get_post_meta( $postid, '_give_goal_option', true );
945
946
	if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) {
947
		$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' );
948
	}
949
950
	return $field_value;
951
}
952
953
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 );
954
955
/**
956
 * Set value for Donation Goal --> close Form.
957
 *
958
 * Backward compatibility:  set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes
959
 * or no.
960
 *
961
 * @since  1.8
962
 *
963
 * @param  mixed $field_value Field Value.
964
 * @param  array $field       Field args.
965
 * @param  int   $postid      Form/Post ID.
966
 *
967
 * @return string
968
 */
969
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...
970
	$close_form = get_post_meta( $postid, '_give_close_form_when_goal_achieved', true );
971
972
	if ( in_array( $close_form, array( 'yes', 'no' ) ) ) {
973
		$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' );
974
	}
975
976
	return $field_value;
977
}
978
979
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 );
980
981
982
/**
983
 * Set value for Form display --> Guest Donation.
984
 *
985
 * Backward compatibility:  set value by _give_logged_in_only form meta field value if it's value is yes or no.
986
 *
987
 * @since  1.8
988
 *
989
 * @param  mixed $field_value Field Value.
990
 * @param  array $field       Field args.
991
 * @param  int   $postid      Form/Post ID.
992
 *
993
 * @return string
994
 */
995
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...
996
	$guest_donation = get_post_meta( $postid, '_give_logged_in_only', true );
997
998
	if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) {
999
		$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' );
1000
	}
1001
1002
	return $field_value;
1003
}
1004
1005
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 );
1006
1007
/**
1008
 * Set value for Offline Donations --> Offline Donations.
1009
 *
1010
 * Backward compatibility:  set value by _give_customize_offline_donations form meta field value if it's value is yes
1011
 * or no.
1012
 *
1013
 * @since  1.8
1014
 *
1015
 * @param  mixed $field_value Field Value.
1016
 * @param  array $field       Field args.
1017
 * @param  int   $postid      Form/Post ID.
1018
 *
1019
 * @return string
1020
 */
1021
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...
1022
	$customize_offline_text = get_post_meta( $postid, '_give_customize_offline_donations', true );
1023
1024
	if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) {
1025
		$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' );
1026
	}
1027
1028
	return $field_value;
1029
}
1030
1031
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 );
1032
1033
1034
/**
1035
 * Set repeater field id for multi donation form.
1036
 *
1037
 * @since 1.8
1038
 *
1039
 * @param int   $field_id
1040
 * @param array $field
1041
 * @param array $fields
1042
 * @param bool  $default
1043
 *
1044
 * @return mixed
1045
 */
1046
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...
1047
	$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}';
1048
	$field_id        = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]";
1049
1050
	return $field_id;
1051
}
1052
1053
add_filter( 'give_get_repeater_field__give_id_id', '_give_set_multi_level_repeater_field_id', 10, 4 );
1054
1055
/**
1056
 * Set repeater field value for multi donation form.
1057
 *
1058
 * @since 1.8
1059
 *
1060
 * @param string $field_value
1061
 * @param array  $field
1062
 * @param array  $field_group
1063
 * @param array  $fields
1064
 *
1065
 * @return mixed
1066
 */
1067
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...
1068
	$field_value = $field_group[ $field['id'] ]['level_id'];
1069
1070
	return $field_value;
1071
}
1072
1073
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 );
1074
1075
/**
1076
 * Set default value for _give_id field.
1077
 *
1078
 * @since 1.8
1079
 *
1080
 * @param $field
1081
 *
1082
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be integer?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
1083
 */
1084
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...
1085
	return 0;
1086
}
1087
1088
add_filter( 'give_default_field_group_field__give_id_value', '_give_set_field_give_id_default_value' );
1089
1090
/**
1091
 * Set default value for _give_default field.
1092
 *
1093
 * @since 1.8
1094
 *
1095
 * @param $field
1096
 *
1097
 * @return string
1098
 */
1099
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...
1100
	return 'default';
1101
}
1102
1103
add_filter( 'give_default_field_group_field__give_default_value', '_give_set_field_give_default_default_value' );
1104
1105
/**
1106
 * Set repeater field editor id for field type wysiwyg.
1107
 *
1108
 * @since 1.8
1109
 *
1110
 * @param $field_name
1111
 * @param $field
1112
 *
1113
 * @return string
1114
 */
1115
function give_repeater_field_set_editor_id( $field_name, $field ) {
1116
	if ( isset( $field['repeatable_field_id'] ) && 'wysiwyg' == $field['type'] ) {
1117
		$field_name = '_give_repeater_' . uniqid() . '_wysiwyg';
1118
	}
1119
1120
	return $field_name;
1121
}
1122
1123
add_filter( 'give_get_field_name', 'give_repeater_field_set_editor_id', 10, 2 );
1124