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