Completed
Push — issues/1038 ( c73fe9...501a6c )
by Ravinder
35:53 queued 16:08
created

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

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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

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...
1442
 */
1443
function give_backward_compatibility_metabox_setting_api_1_8( &$field ) {
1444
	if ( ! empty( $field['id'] ) ) {
1445
		$field_args = array(
1446
			'name'               => ( ! empty( $field['id'] ) ? $field['id'] : $field['name'] ),
1447
			'label'              => ! empty( $field['id'] ) ? ( $field['name'] ) : ( ! empty( $field['label'] ) ? $field['label'] : '' ),
1448
			'field_attributes'   => array(
1449
				'class' => ( empty( $field['class'] ) ? '' : ' ' . esc_attr( $field['class'] ) ),
1450
				'style' => ( empty( $field['style'] ) ? '' : $field['style'] ),
1451
				'id'    => ( ! empty( $field['id'] ) ? $field['id'] : $field['name'] ),
1452
1453
			),
1454
			'wrapper_attributes' => array(
1455
				'class'  => ( ! empty( $field['wrapper_class'] ) ? $field['wrapper_class'] : '' ),
1456
			),
1457
		);
1458
1459
		if ( ! empty( $field['attributes'] ) ) {
1460
			$field_args['field_attributes'] = array_merge( $field_args['field_attributes'], $field['attributes'] );
1461
		}
1462
1463
		$field = array_merge( $field, $field_args );
1464
	}
1465
}
1466