|
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 'hidden': |
|
65
|
|
|
case 'levels_id': |
|
66
|
|
|
$func_name = "{$func_name_prefix}_hidden_input"; |
|
67
|
|
|
break; |
|
68
|
|
|
|
|
69
|
|
|
case 'group' : |
|
70
|
|
|
$func_name = "_{$func_name_prefix}_metabox_form_data_repeater_fields"; |
|
71
|
|
|
break; |
|
72
|
|
|
|
|
73
|
|
|
case 'give_default_radio_inline': |
|
74
|
|
|
$func_name = "{$func_name_prefix}_radio"; |
|
75
|
|
|
break; |
|
76
|
|
|
|
|
77
|
|
|
default: |
|
78
|
|
|
|
|
79
|
|
|
if ( |
|
80
|
|
|
array_key_exists( 'callback', $field ) |
|
81
|
|
|
&& ! empty( $field['callback'] ) |
|
82
|
|
|
) { |
|
83
|
|
|
$func_name = $field['callback']; |
|
84
|
|
|
} else { |
|
85
|
|
|
$func_name = "{$func_name_prefix}_{$field['type']}"; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Filter the metabox setting render function |
|
91
|
|
|
* |
|
92
|
|
|
* @since 1.8 |
|
93
|
|
|
*/ |
|
94
|
|
|
$func_name = apply_filters( 'give_get_field_callback', $func_name, $field ); |
|
95
|
|
|
|
|
96
|
|
|
// Exit if not any function exist. |
|
97
|
|
|
// Check if render callback exist or not. |
|
98
|
|
|
if ( empty( $func_name ) ) { |
|
99
|
|
|
return false; |
|
100
|
|
|
} elseif ( is_string( $func_name ) && ! function_exists( "$func_name" ) ) { |
|
101
|
|
|
return false; |
|
102
|
|
|
} elseif ( is_array( $func_name ) && ! method_exists( $func_name[0], "$func_name[1]" ) ) { |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
return $func_name; |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* This function adds backward compatibility to render cmb2 type field type. |
|
111
|
|
|
* |
|
112
|
|
|
* @since 1.8 |
|
113
|
|
|
* |
|
114
|
|
|
* @param array $field Field argument array. |
|
115
|
|
|
* |
|
116
|
|
|
* @return bool |
|
117
|
|
|
*/ |
|
118
|
|
|
function give_render_field( $field ) { |
|
119
|
|
|
|
|
120
|
|
|
// Check if render callback exist or not. |
|
121
|
|
|
if ( ! ( $func_name = give_get_field_callback( $field ) ) ) { |
|
122
|
|
|
return false; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
$field = give_backward_compatibility_setting_api_1_8( $field ); |
|
126
|
|
|
|
|
127
|
|
|
// Call render function. |
|
128
|
|
|
if ( is_array( $func_name ) ) { |
|
129
|
|
|
$func_name[0]->$func_name[1]( $field ); |
|
130
|
|
|
} else { |
|
131
|
|
|
$func_name( $field ); |
|
132
|
|
|
} |
|
133
|
|
|
|
|
134
|
|
|
return true; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Output a text input box. |
|
139
|
|
|
* |
|
140
|
|
|
* @since 1.8 |
|
141
|
|
|
* @since 1.9 Render field with field api |
|
142
|
|
|
* |
|
143
|
|
|
* @param array $field Field arguments |
|
144
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
145
|
|
|
* |
|
146
|
|
|
* @return void |
|
147
|
|
|
*/ |
|
148
|
|
|
function give_text_input( $field ) { |
|
149
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
150
|
|
|
|
|
151
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
152
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
153
|
|
|
$data_type = empty( $field['data_type'] ) ? '' : $field['data_type']; |
|
154
|
|
|
|
|
155
|
|
|
switch ( $data_type ) { |
|
156
|
|
|
case 'price' : |
|
157
|
|
|
$field['value'] = ( ! empty( $field['value'] ) ? give_format_amount( $field['value'] ) : $field['value'] ); |
|
158
|
|
|
|
|
159
|
|
|
$field['before_field'] = ! empty( $field['before_field'] ) ? $field['before_field'] : ( give_get_option( 'currency_position', 'before' ) == 'before' ? '<span class="give-money-symbol give-money-symbol-before">' . give_currency_symbol() . '</span>' : '' ); |
|
160
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) ? $field['after_field'] : ( give_get_option( 'currency_position', 'before' ) == 'after' ? '<span class="give-money-symbol give-money-symbol-after">' . give_currency_symbol() . '</span>' : '' ); |
|
161
|
|
|
break; |
|
162
|
|
|
|
|
163
|
|
|
case 'decimal' : |
|
164
|
|
|
$field['attributes']['class'] .= ' give_input_decimal'; |
|
165
|
|
|
$field['value'] = ( ! empty( $field['value'] ) ? give_format_decimal( $field['value'] ) : $field['value'] ); |
|
166
|
|
|
break; |
|
167
|
|
|
|
|
168
|
|
|
default : |
|
169
|
|
|
break; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
// Set description. |
|
173
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
174
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
175
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
176
|
|
|
: give_get_field_description( $field ); |
|
177
|
|
|
|
|
178
|
|
|
// Reset label for repeater field compatibility. |
|
179
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
180
|
|
|
|
|
181
|
|
|
// Render Field. |
|
182
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
/** |
|
186
|
|
|
* Output a hidden input box. |
|
187
|
|
|
* |
|
188
|
|
|
* @since 1.8 |
|
189
|
|
|
* @since 1.9 Render field with field api |
|
190
|
|
|
* |
|
191
|
|
|
* @param array $field Field arguments |
|
192
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
193
|
|
|
* |
|
194
|
|
|
* @return void |
|
195
|
|
|
*/ |
|
196
|
|
|
function give_hidden_input( $field ) { |
|
197
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
198
|
|
|
|
|
199
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
200
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
201
|
|
|
|
|
202
|
|
|
// Reset label for repeater field compatibility. |
|
203
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
204
|
|
|
|
|
205
|
|
|
// Render Field. |
|
206
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
/** |
|
210
|
|
|
* Output a textarea input box. |
|
211
|
|
|
* |
|
212
|
|
|
* @since 1.8 |
|
213
|
|
|
* @since 1.9 Render field with field api |
|
214
|
|
|
* |
|
215
|
|
|
* @param array $field Field arguments |
|
216
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
217
|
|
|
* |
|
218
|
|
|
* @return void |
|
219
|
|
|
*/ |
|
220
|
|
|
function give_textarea_input( $field ) { |
|
221
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
222
|
|
|
|
|
223
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
224
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
225
|
|
|
|
|
226
|
|
|
// Set description. |
|
227
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
228
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
229
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
230
|
|
|
: give_get_field_description( $field ); |
|
231
|
|
|
|
|
232
|
|
|
// Reset label for repeater field compatibility. |
|
233
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
234
|
|
|
|
|
235
|
|
|
// Render Field. |
|
236
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
/** |
|
240
|
|
|
* Output a wysiwyg. |
|
241
|
|
|
* |
|
242
|
|
|
* @since 1.8 |
|
243
|
|
|
* |
|
244
|
|
|
* @param array $field { |
|
245
|
|
|
* Optional. Array of WordPress editor field arguments. |
|
246
|
|
|
* |
|
247
|
|
|
* @type string $id Field ID. Default ''. |
|
248
|
|
|
* @type string $style CSS style for input field. Default ''. |
|
249
|
|
|
* @type string $wrapper_class CSS class to use for wrapper of input field. Default ''. |
|
250
|
|
|
* @type string $value Value of input field. Default ''. |
|
251
|
|
|
* @type string $name Name of input field. Default ''. |
|
252
|
|
|
* @type string $description Description of input field. Default ''. |
|
253
|
|
|
* @type array $attributes List of attributes of input field. Default array(). |
|
254
|
|
|
* for example: 'attributes' => array( 'placeholder' => '*****', 'class' |
|
255
|
|
|
* => '****' ) |
|
256
|
|
|
* } |
|
257
|
|
|
* @return void |
|
258
|
|
|
*/ |
|
259
|
|
|
function give_wysiwyg( $field ) { |
|
260
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
261
|
|
|
|
|
262
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
263
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
264
|
|
|
$field['unique_field_id'] = give_get_field_name( $field ); |
|
265
|
|
|
$field['wrapper_type'] = 'div'; |
|
266
|
|
|
|
|
267
|
|
|
// Set description. |
|
268
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
269
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
270
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
271
|
|
|
: give_get_field_description( $field ); |
|
272
|
|
|
|
|
273
|
|
|
// Render Field. |
|
274
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
275
|
|
|
} |
|
276
|
|
|
|
|
277
|
|
|
/** |
|
278
|
|
|
* Output a checkbox input box. |
|
279
|
|
|
* |
|
280
|
|
|
* @since 1.8 |
|
281
|
|
|
* @since 1.9 Render field with field api |
|
282
|
|
|
* |
|
283
|
|
|
* @param array $field Field arguments |
|
284
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
285
|
|
|
* |
|
286
|
|
|
* @return void |
|
287
|
|
|
*/ |
|
288
|
|
|
function give_checkbox( $field ) { |
|
289
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
290
|
|
|
|
|
291
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
292
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
293
|
|
|
$field['cbvalue'] = isset( $field['cbvalue'] ) ? $field['cbvalue'] : 'on'; |
|
294
|
|
|
|
|
295
|
|
|
// Set description. |
|
296
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
297
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
298
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
299
|
|
|
: give_get_field_description( $field ); |
|
300
|
|
|
|
|
301
|
|
|
// Reset label for repeater field compatibility. |
|
302
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
303
|
|
|
|
|
304
|
|
|
// Render Field. |
|
305
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
/** |
|
309
|
|
|
* Output a select input box. |
|
310
|
|
|
* |
|
311
|
|
|
* @since 1.8 |
|
312
|
|
|
* @since 1.9 Render field with field api |
|
313
|
|
|
* |
|
314
|
|
|
* @param array $field Field arguments |
|
315
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
316
|
|
|
* |
|
317
|
|
|
* @return void |
|
318
|
|
|
*/ |
|
319
|
|
|
function give_select( $field ) { |
|
320
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
321
|
|
|
|
|
322
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
323
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
324
|
|
|
|
|
325
|
|
|
// Set description. |
|
326
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
327
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
328
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
329
|
|
|
: give_get_field_description( $field ); |
|
330
|
|
|
|
|
331
|
|
|
// Reset label for repeater field compatibility. |
|
332
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
333
|
|
|
|
|
334
|
|
|
// Render Field. |
|
335
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
336
|
|
|
} |
|
337
|
|
|
|
|
338
|
|
|
/** |
|
339
|
|
|
* Output a radio input box. |
|
340
|
|
|
* |
|
341
|
|
|
* @since 1.8 |
|
342
|
|
|
* @since 1.9 Render field with field api |
|
343
|
|
|
* |
|
344
|
|
|
* @param array $field Field arguments |
|
345
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
346
|
|
|
* @param array $field |
|
347
|
|
|
* |
|
348
|
|
|
* @return void |
|
349
|
|
|
*/ |
|
350
|
|
|
function give_radio( $field ) { |
|
351
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
352
|
|
|
|
|
353
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
354
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
355
|
|
|
$field['wrapper_type'] = 'fieldset'; |
|
356
|
|
|
|
|
357
|
|
|
// Set description. |
|
358
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
359
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
360
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
361
|
|
|
: give_get_field_description( $field ); |
|
362
|
|
|
|
|
363
|
|
|
// Reset label for repeater field compatibility. |
|
364
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
365
|
|
|
|
|
366
|
|
|
// Render Field. |
|
367
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
368
|
|
|
} |
|
369
|
|
|
|
|
370
|
|
|
/** |
|
371
|
|
|
* Output a colorpicker. |
|
372
|
|
|
* |
|
373
|
|
|
* @since 1.8 |
|
374
|
|
|
* @since 1.9 Render field with field api |
|
375
|
|
|
* |
|
376
|
|
|
* @param array $field Field arguments |
|
377
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
378
|
|
|
* @param array $field |
|
379
|
|
|
* |
|
380
|
|
|
* @return void |
|
381
|
|
|
*/ |
|
382
|
|
|
function give_colorpicker( $field ) { |
|
383
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
384
|
|
|
|
|
385
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
386
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
387
|
|
|
$field['type'] = 'text'; |
|
388
|
|
|
|
|
389
|
|
|
// Set description. |
|
390
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
391
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
392
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
393
|
|
|
: give_get_field_description( $field ); |
|
394
|
|
|
|
|
395
|
|
|
// Reset label for repeater field compatibility. |
|
396
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
397
|
|
|
|
|
398
|
|
|
// Render Field. |
|
399
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
400
|
|
|
} |
|
401
|
|
|
|
|
402
|
|
|
|
|
403
|
|
|
/** |
|
404
|
|
|
* Output a media upload field. |
|
405
|
|
|
* |
|
406
|
|
|
* @since 1.8 |
|
407
|
|
|
* @since 1.9 Render field with field api |
|
408
|
|
|
* |
|
409
|
|
|
* @param array $field Field arguments |
|
410
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
411
|
|
|
* @param array $field |
|
412
|
|
|
* |
|
413
|
|
|
* @return void |
|
414
|
|
|
*/ |
|
415
|
|
|
function give_media( $field ) { |
|
416
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
417
|
|
|
|
|
418
|
|
|
$thepostid = empty( $thepostid ) ? $post->ID : $thepostid; |
|
419
|
|
|
$field['value'] = give_get_field_value( $field, $thepostid ); |
|
420
|
|
|
|
|
421
|
|
|
// Set description. |
|
422
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
423
|
|
|
$field['after_field'] = ! empty( $field['after_field'] ) |
|
424
|
|
|
? $field['after_field'] . give_get_field_description( $field ) |
|
425
|
|
|
: give_get_field_description( $field ); |
|
426
|
|
|
|
|
427
|
|
|
// Reset label for repeater field compatibility. |
|
428
|
|
|
$field['name'] = give_get_field_name( $field ); |
|
429
|
|
|
|
|
430
|
|
|
// Render Field. |
|
431
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
432
|
|
|
} |
|
433
|
|
|
|
|
434
|
|
|
/** |
|
435
|
|
|
* Output a select field with payment options list. |
|
436
|
|
|
* |
|
437
|
|
|
* @since 1.8 |
|
438
|
|
|
* |
|
439
|
|
|
* @param array $field |
|
440
|
|
|
* |
|
441
|
|
|
* @return void |
|
442
|
|
|
*/ |
|
443
|
|
|
function give_default_gateway( $field ) { |
|
444
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
445
|
|
|
|
|
446
|
|
|
// get all active payment gateways. |
|
447
|
|
|
$gateways = give_get_enabled_payment_gateways( $thepostid ); |
|
448
|
|
|
$field['options'] = array(); |
|
449
|
|
|
|
|
450
|
|
|
// Set field option value. |
|
451
|
|
|
if ( ! empty( $gateways ) ) { |
|
452
|
|
|
foreach ( $gateways as $key => $option ) { |
|
453
|
|
|
$field['options'][ $key ] = $option['admin_label']; |
|
454
|
|
|
} |
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
// Add a field to the Give Form admin single post view of this field |
|
458
|
|
|
if ( is_object( $post ) && 'give_forms' === $post->post_type ) { |
|
459
|
|
|
$field['options'] = array_merge( array( 'global' => esc_html__( 'Global Default', 'give' ) ), $field['options'] ); |
|
460
|
|
|
} |
|
461
|
|
|
|
|
462
|
|
|
$field['type'] = 'select'; |
|
463
|
|
|
|
|
464
|
|
|
// Render select field. |
|
465
|
|
|
give_select( $field ); |
|
466
|
|
|
} |
|
467
|
|
|
|
|
468
|
|
|
/** |
|
469
|
|
|
* Output the documentation link. |
|
470
|
|
|
* |
|
471
|
|
|
* @since 1.8 |
|
472
|
|
|
* @since 1.9 Render field with field api |
|
473
|
|
|
* |
|
474
|
|
|
* @param array $field Field arguments |
|
475
|
|
|
* Check includes/forms/api/class-give-field-api.php:28 for arguments. |
|
476
|
|
|
* |
|
477
|
|
|
* @return void |
|
478
|
|
|
*/ |
|
479
|
|
|
|
|
480
|
|
|
function give_docs_link( $field ) { |
|
481
|
|
|
|
|
482
|
|
|
// Set default class. |
|
483
|
|
|
// Backward compatibility ( 1.8=<version>1.9). |
|
484
|
|
|
$field['wrapper_attributes']['class'] = ! empty( $field['wrapper_attributes']['class'] ) |
|
485
|
|
|
? "{$field['wrapper_attributes']['class']} give-docs-link" |
|
486
|
|
|
: 'give-docs-link'; |
|
487
|
|
|
|
|
488
|
|
|
// Render Field. |
|
489
|
|
|
echo Give_Fields_API::render_tag( $field ); |
|
490
|
|
|
} |
|
491
|
|
|
|
|
492
|
|
|
/** |
|
493
|
|
|
* Get setting field value. |
|
494
|
|
|
* |
|
495
|
|
|
* Note: Use only for single post, page or custom post type. |
|
496
|
|
|
* |
|
497
|
|
|
* @since 1.8 |
|
498
|
|
|
* |
|
499
|
|
|
* @param array $field |
|
500
|
|
|
* @param int $postid |
|
501
|
|
|
* |
|
502
|
|
|
* @return mixed |
|
503
|
|
|
*/ |
|
504
|
|
|
function give_get_field_value( $field, $postid ) { |
|
505
|
|
|
if ( isset( $field['field_attributes']['value'] ) ) { |
|
506
|
|
|
return $field['field_attributes']['value']; |
|
507
|
|
|
} |
|
508
|
|
|
|
|
509
|
|
|
// Get value from db. |
|
510
|
|
|
$field_value = get_post_meta( $postid, $field['id'], true ); |
|
511
|
|
|
|
|
512
|
|
|
/** |
|
513
|
|
|
* Filter the field value before apply default value. |
|
514
|
|
|
* |
|
515
|
|
|
* @since 1.8 |
|
516
|
|
|
* |
|
517
|
|
|
* @param mixed $field_value Field value. |
|
518
|
|
|
*/ |
|
519
|
|
|
$field_value = apply_filters( "{$field['id']}_field_value", $field_value, $field, $postid ); |
|
520
|
|
|
|
|
521
|
|
|
// Set default value if no any data saved to db. |
|
522
|
|
|
if ( ! $field_value && isset( $field['default'] ) ) { |
|
523
|
|
|
$field_value = $field['default']; |
|
524
|
|
|
} |
|
525
|
|
|
|
|
526
|
|
|
return $field_value; |
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
|
|
|
|
530
|
|
|
/** |
|
531
|
|
|
* Get field description html. |
|
532
|
|
|
* |
|
533
|
|
|
* @since 1.8 |
|
534
|
|
|
* |
|
535
|
|
|
* @param $field |
|
536
|
|
|
* |
|
537
|
|
|
* @return string |
|
538
|
|
|
*/ |
|
539
|
|
|
function give_get_field_description( $field ) { |
|
540
|
|
|
$field_desc_html = ''; |
|
541
|
|
|
if ( ! empty( $field['description'] ) ) { |
|
542
|
|
|
$field_desc_html = '<span class="give-field-description">' . wp_kses_post( $field['description'] ) . '</span>'; |
|
543
|
|
|
} |
|
544
|
|
|
|
|
545
|
|
|
return $field_desc_html; |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
|
|
549
|
|
|
/** |
|
550
|
|
|
* Get field custom attributes as string. |
|
551
|
|
|
* |
|
552
|
|
|
* @since 1.8 |
|
553
|
|
|
* |
|
554
|
|
|
* @param $field |
|
555
|
|
|
* |
|
556
|
|
|
* @return string |
|
557
|
|
|
*/ |
|
558
|
|
|
function give_get_custom_attributes( $field ) { |
|
559
|
|
|
// Custom attribute handling |
|
560
|
|
|
$custom_attributes = array(); |
|
561
|
|
|
|
|
562
|
|
|
if ( ! empty( $field['attributes'] ) && is_array( $field['attributes'] ) ) { |
|
563
|
|
|
|
|
564
|
|
|
foreach ( $field['attributes'] as $attribute => $value ) { |
|
565
|
|
|
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; |
|
566
|
|
|
} |
|
567
|
|
|
} |
|
568
|
|
|
|
|
569
|
|
|
return implode( ' ', $custom_attributes ); |
|
570
|
|
|
} |
|
571
|
|
|
|
|
572
|
|
|
/** |
|
573
|
|
|
* Get repeater field value. |
|
574
|
|
|
* |
|
575
|
|
|
* Note: Use only for single post, page or custom post type. |
|
576
|
|
|
* |
|
577
|
|
|
* @since 1.8 |
|
578
|
|
|
* |
|
579
|
|
|
* @param array $field |
|
580
|
|
|
* @param array $field_group |
|
581
|
|
|
* @param array $fields |
|
582
|
|
|
* |
|
583
|
|
|
* @return string |
|
584
|
|
|
*/ |
|
585
|
|
|
function give_get_repeater_field_value( $field, $field_group, $fields ) { |
|
586
|
|
|
$field_value = ( isset( $field_group[ $field['id'] ] ) ? $field_group[ $field['id'] ] : '' ); |
|
587
|
|
|
|
|
588
|
|
|
/** |
|
589
|
|
|
* Filter the specific repeater field value |
|
590
|
|
|
* |
|
591
|
|
|
* @since 1.8 |
|
592
|
|
|
* |
|
593
|
|
|
* @param string $field_id |
|
594
|
|
|
*/ |
|
595
|
|
|
$field_value = apply_filters( "give_get_repeater_field_{$field['id']}_value", $field_value, $field, $field_group, $fields ); |
|
596
|
|
|
|
|
597
|
|
|
/** |
|
598
|
|
|
* Filter the repeater field value |
|
599
|
|
|
* |
|
600
|
|
|
* @since 1.8 |
|
601
|
|
|
* |
|
602
|
|
|
* @param string $field_id |
|
603
|
|
|
*/ |
|
604
|
|
|
$field_value = apply_filters( 'give_get_repeater_field_value', $field_value, $field, $field_group, $fields ); |
|
605
|
|
|
|
|
606
|
|
|
return $field_value; |
|
607
|
|
|
} |
|
608
|
|
|
|
|
609
|
|
|
/** |
|
610
|
|
|
* Get repeater field id. |
|
611
|
|
|
* |
|
612
|
|
|
* Note: Use only for single post, page or custom post type. |
|
613
|
|
|
* |
|
614
|
|
|
* @since 1.8 |
|
615
|
|
|
* |
|
616
|
|
|
* @param array $field |
|
617
|
|
|
* @param array $fields |
|
618
|
|
|
* @param int|bool $default |
|
619
|
|
|
* |
|
620
|
|
|
* @return string |
|
621
|
|
|
*/ |
|
622
|
|
|
function give_get_repeater_field_id( $field, $fields, $default = false ) { |
|
623
|
|
|
return Give_Fields_API::get_repeater_field_name( $field, $fields, $default ); |
|
624
|
|
|
} |
|
625
|
|
|
|
|
626
|
|
|
|
|
627
|
|
|
/** |
|
628
|
|
|
* Get field name. |
|
629
|
|
|
* |
|
630
|
|
|
* @since 1.8 |
|
631
|
|
|
* |
|
632
|
|
|
* @param array $field |
|
633
|
|
|
* |
|
634
|
|
|
* @return string |
|
635
|
|
|
*/ |
|
636
|
|
|
function give_get_field_name( $field ) { |
|
637
|
|
|
$field_name = esc_attr( empty( $field['repeat'] ) ? $field['id'] : $field['repeatable_field_id'] ); |
|
638
|
|
|
|
|
639
|
|
|
/** |
|
640
|
|
|
* Filter the field name. |
|
641
|
|
|
* |
|
642
|
|
|
* @since 1.8 |
|
643
|
|
|
* |
|
644
|
|
|
* @param string $field_name |
|
645
|
|
|
*/ |
|
646
|
|
|
$field_name = apply_filters( 'give_get_field_name', $field_name, $field ); |
|
647
|
|
|
|
|
648
|
|
|
return $field_name; |
|
649
|
|
|
} |
|
650
|
|
|
|
|
651
|
|
|
/** |
|
652
|
|
|
* Output repeater field or multi donation type form on donation from edit screen. |
|
653
|
|
|
* Note: internal use only. |
|
654
|
|
|
* |
|
655
|
|
|
* @since 1.8 |
|
656
|
|
|
* |
|
657
|
|
|
* @param array $fields |
|
658
|
|
|
* |
|
659
|
|
|
* @return void |
|
660
|
|
|
*/ |
|
661
|
|
|
function _give_metabox_form_data_repeater_fields( $fields ) { |
|
662
|
|
|
global $thepostid, $post; |
|
|
|
|
|
|
663
|
|
|
$fields = give_backward_compatibility_setting_api_1_8( $fields ); |
|
664
|
|
|
$fields['value'] = get_post_meta( $thepostid, $fields['id'], true ); |
|
665
|
|
|
$fields['wrapper'] = false; |
|
666
|
|
|
|
|
667
|
|
|
echo Give_Fields_API::render_tag( $fields ); |
|
668
|
|
|
} |
|
669
|
|
|
|
|
670
|
|
|
|
|
671
|
|
|
/** |
|
672
|
|
|
* Get current setting tab. |
|
673
|
|
|
* |
|
674
|
|
|
* @since 1.8 |
|
675
|
|
|
* @return string |
|
676
|
|
|
*/ |
|
677
|
|
|
function give_get_current_setting_tab() { |
|
678
|
|
|
// Get current setting page. |
|
679
|
|
|
$current_setting_page = give_get_current_setting_page(); |
|
680
|
|
|
|
|
681
|
|
|
/** |
|
682
|
|
|
* Filter the default tab for current setting page. |
|
683
|
|
|
* |
|
684
|
|
|
* @since 1.8 |
|
685
|
|
|
* |
|
686
|
|
|
* @param string |
|
687
|
|
|
*/ |
|
688
|
|
|
$default_current_tab = apply_filters( "give_default_setting_tab_{$current_setting_page}", 'general' ); |
|
689
|
|
|
|
|
690
|
|
|
// Get current tab. |
|
691
|
|
|
$current_tab = empty( $_GET['tab'] ) ? $default_current_tab : urldecode( $_GET['tab'] ); |
|
692
|
|
|
|
|
693
|
|
|
// Output. |
|
694
|
|
|
return $current_tab; |
|
695
|
|
|
} |
|
696
|
|
|
|
|
697
|
|
|
|
|
698
|
|
|
/** |
|
699
|
|
|
* Get current setting section. |
|
700
|
|
|
* |
|
701
|
|
|
* @since 1.8 |
|
702
|
|
|
* @return string |
|
703
|
|
|
*/ |
|
704
|
|
|
function give_get_current_setting_section() { |
|
705
|
|
|
// Get current tab. |
|
706
|
|
|
$current_tab = give_get_current_setting_tab(); |
|
707
|
|
|
|
|
708
|
|
|
/** |
|
709
|
|
|
* Filter the default section for current setting page tab. |
|
710
|
|
|
* |
|
711
|
|
|
* @since 1.8 |
|
712
|
|
|
* |
|
713
|
|
|
* @param string |
|
714
|
|
|
*/ |
|
715
|
|
|
$default_current_section = apply_filters( "give_default_setting_tab_section_{$current_tab}", '' ); |
|
716
|
|
|
|
|
717
|
|
|
// Get current section. |
|
718
|
|
|
$current_section = empty( $_REQUEST['section'] ) ? $default_current_section : urldecode( $_REQUEST['section'] ); |
|
719
|
|
|
|
|
720
|
|
|
// Output. |
|
721
|
|
|
return $current_section; |
|
722
|
|
|
} |
|
723
|
|
|
|
|
724
|
|
|
/** |
|
725
|
|
|
* Get current setting page. |
|
726
|
|
|
* |
|
727
|
|
|
* @since 1.8 |
|
728
|
|
|
* @return string |
|
729
|
|
|
*/ |
|
730
|
|
|
function give_get_current_setting_page() { |
|
731
|
|
|
// Get current page. |
|
732
|
|
|
$setting_page = ! empty( $_GET['page'] ) ? urldecode( $_GET['page'] ) : ''; |
|
733
|
|
|
|
|
734
|
|
|
// Output. |
|
735
|
|
|
return $setting_page; |
|
736
|
|
|
} |
|
737
|
|
|
|
|
738
|
|
|
/** |
|
739
|
|
|
* Set value for Form content --> Display content field setting. |
|
740
|
|
|
* |
|
741
|
|
|
* Backward compatibility: set value by _give_content_option form meta field value if _give_display_content is not set |
|
742
|
|
|
* yet. |
|
743
|
|
|
* |
|
744
|
|
|
* @since 1.8 |
|
745
|
|
|
* |
|
746
|
|
|
* @param mixed $field_value Field Value. |
|
747
|
|
|
* @param array $field Field args. |
|
748
|
|
|
* @param int $postid Form/Post ID. |
|
749
|
|
|
* |
|
750
|
|
|
* @return string |
|
751
|
|
|
*/ |
|
752
|
|
|
function _give_display_content_field_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
753
|
|
|
$show_content = get_post_meta( $postid, '_give_content_option', true ); |
|
754
|
|
|
|
|
755
|
|
|
if ( |
|
756
|
|
|
! get_post_meta( $postid, '_give_display_content', true ) |
|
757
|
|
|
&& $show_content |
|
758
|
|
|
&& ( 'none' !== $show_content ) |
|
759
|
|
|
) { |
|
760
|
|
|
$field_value = 'enabled'; |
|
761
|
|
|
} |
|
762
|
|
|
|
|
763
|
|
|
return $field_value; |
|
764
|
|
|
} |
|
765
|
|
|
|
|
766
|
|
|
add_filter( '_give_display_content_field_value', '_give_display_content_field_value', 10, 3 ); |
|
767
|
|
|
|
|
768
|
|
|
|
|
769
|
|
|
/** |
|
770
|
|
|
* Set value for Form content --> Content placement field setting. |
|
771
|
|
|
* |
|
772
|
|
|
* Backward compatibility: set value by _give_content_option form meta field value if _give_content_placement is not |
|
773
|
|
|
* set yet. |
|
774
|
|
|
* |
|
775
|
|
|
* @since 1.8 |
|
776
|
|
|
* |
|
777
|
|
|
* @param mixed $field_value Field Value. |
|
778
|
|
|
* @param array $field Field args. |
|
779
|
|
|
* @param int $postid Form/Post ID. |
|
780
|
|
|
* |
|
781
|
|
|
* @return string |
|
782
|
|
|
*/ |
|
783
|
|
|
function _give_content_placement_field_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
784
|
|
|
$show_content = get_post_meta( $postid, '_give_content_option', true ); |
|
785
|
|
|
|
|
786
|
|
|
if ( |
|
787
|
|
|
! get_post_meta( $postid, '_give_content_placement', true ) |
|
788
|
|
|
&& ( 'none' !== $show_content ) |
|
789
|
|
|
) { |
|
790
|
|
|
$field_value = $show_content; |
|
791
|
|
|
} |
|
792
|
|
|
|
|
793
|
|
|
return $field_value; |
|
794
|
|
|
} |
|
795
|
|
|
|
|
796
|
|
|
add_filter( '_give_content_placement_field_value', '_give_content_placement_field_value', 10, 3 ); |
|
797
|
|
|
|
|
798
|
|
|
|
|
799
|
|
|
/** |
|
800
|
|
|
* Set value for Terms and Conditions --> Terms and Conditions field setting. |
|
801
|
|
|
* |
|
802
|
|
|
* Backward compatibility: set value by _give_terms_option form meta field value if it's value is none. |
|
803
|
|
|
* |
|
804
|
|
|
* @since 1.8 |
|
805
|
|
|
* |
|
806
|
|
|
* @param mixed $field_value Field Value. |
|
807
|
|
|
* @param array $field Field args. |
|
808
|
|
|
* @param int $postid Form/Post ID. |
|
809
|
|
|
* |
|
810
|
|
|
* @return string |
|
811
|
|
|
*/ |
|
812
|
|
|
function _give_terms_option_field_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
813
|
|
|
$term_option = get_post_meta( $postid, '_give_terms_option', true ); |
|
814
|
|
|
|
|
815
|
|
|
if ( in_array( $term_option, array( 'none', 'yes' ) ) ) { |
|
816
|
|
|
$field_value = ( 'yes' === $term_option ? 'enabled' : 'disabled' ); |
|
817
|
|
|
} |
|
818
|
|
|
|
|
819
|
|
|
return $field_value; |
|
820
|
|
|
} |
|
821
|
|
|
|
|
822
|
|
|
add_filter( '_give_terms_option_field_value', '_give_terms_option_field_value', 10, 3 ); |
|
823
|
|
|
|
|
824
|
|
|
|
|
825
|
|
|
/** |
|
826
|
|
|
* Set value for Form Display --> Offline Donation --> Billing Fields. |
|
827
|
|
|
* |
|
828
|
|
|
* Backward compatibility: set value by _give_offline_donation_enable_billing_fields_single form meta field value if |
|
829
|
|
|
* it's value is on. |
|
830
|
|
|
* |
|
831
|
|
|
* @since 1.8 |
|
832
|
|
|
* |
|
833
|
|
|
* @param mixed $field_value Field Value. |
|
834
|
|
|
* @param array $field Field args. |
|
835
|
|
|
* @param int $postid Form/Post ID. |
|
836
|
|
|
* |
|
837
|
|
|
* @return string |
|
838
|
|
|
*/ |
|
839
|
|
|
function _give_offline_donation_enable_billing_fields_single_field_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
840
|
|
|
$offline_donation = get_post_meta( $postid, '_give_offline_donation_enable_billing_fields_single', true ); |
|
841
|
|
|
|
|
842
|
|
|
if ( 'on' === $offline_donation ) { |
|
843
|
|
|
$field_value = 'enabled'; |
|
844
|
|
|
} |
|
845
|
|
|
|
|
846
|
|
|
return $field_value; |
|
847
|
|
|
} |
|
848
|
|
|
|
|
849
|
|
|
add_filter( '_give_offline_donation_enable_billing_fields_single_field_value', '_give_offline_donation_enable_billing_fields_single_field_value', 10, 3 ); |
|
850
|
|
|
|
|
851
|
|
|
|
|
852
|
|
|
/** |
|
853
|
|
|
* Set value for Donation Options --> Custom Amount. |
|
854
|
|
|
* |
|
855
|
|
|
* Backward compatibility: set value by _give_custom_amount form meta field value if it's value is yes or no. |
|
856
|
|
|
* |
|
857
|
|
|
* @since 1.8 |
|
858
|
|
|
* |
|
859
|
|
|
* @param mixed $field_value Field Value. |
|
860
|
|
|
* @param array $field Field args. |
|
861
|
|
|
* @param int $postid Form/Post ID. |
|
862
|
|
|
* |
|
863
|
|
|
* @return string |
|
864
|
|
|
*/ |
|
865
|
|
|
function _give_custom_amount_field_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
866
|
|
|
$custom_amount = get_post_meta( $postid, '_give_custom_amount', true ); |
|
867
|
|
|
|
|
868
|
|
|
if ( in_array( $custom_amount, array( 'yes', 'no' ) ) ) { |
|
869
|
|
|
$field_value = ( 'yes' === $custom_amount ? 'enabled' : 'disabled' ); |
|
870
|
|
|
} |
|
871
|
|
|
|
|
872
|
|
|
return $field_value; |
|
873
|
|
|
} |
|
874
|
|
|
|
|
875
|
|
|
add_filter( '_give_custom_amount_field_value', '_give_custom_amount_field_value', 10, 3 ); |
|
876
|
|
|
|
|
877
|
|
|
|
|
878
|
|
|
/** |
|
879
|
|
|
* Set value for Donation Goal --> Donation Goal. |
|
880
|
|
|
* |
|
881
|
|
|
* Backward compatibility: set value by _give_goal_option form meta field value if it's value is yes or no. |
|
882
|
|
|
* |
|
883
|
|
|
* @since 1.8 |
|
884
|
|
|
* |
|
885
|
|
|
* @param mixed $field_value Field Value. |
|
886
|
|
|
* @param array $field Field args. |
|
887
|
|
|
* @param int $postid Form/Post ID. |
|
888
|
|
|
* |
|
889
|
|
|
* @return string |
|
890
|
|
|
*/ |
|
891
|
|
|
function _give_goal_option_field_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
892
|
|
|
$goal_option = get_post_meta( $postid, '_give_goal_option', true ); |
|
893
|
|
|
|
|
894
|
|
|
if ( in_array( $goal_option, array( 'yes', 'no' ) ) ) { |
|
895
|
|
|
$field_value = ( 'yes' === $goal_option ? 'enabled' : 'disabled' ); |
|
896
|
|
|
} |
|
897
|
|
|
|
|
898
|
|
|
return $field_value; |
|
899
|
|
|
} |
|
900
|
|
|
|
|
901
|
|
|
add_filter( '_give_goal_option_field_value', '_give_goal_option_field_value', 10, 3 ); |
|
902
|
|
|
|
|
903
|
|
|
/** |
|
904
|
|
|
* Set value for Donation Goal --> close Form. |
|
905
|
|
|
* |
|
906
|
|
|
* Backward compatibility: set value by _give_close_form_when_goal_achieved form meta field value if it's value is yes |
|
907
|
|
|
* or no. |
|
908
|
|
|
* |
|
909
|
|
|
* @since 1.8 |
|
910
|
|
|
* |
|
911
|
|
|
* @param mixed $field_value Field Value. |
|
912
|
|
|
* @param array $field Field args. |
|
913
|
|
|
* @param int $postid Form/Post ID. |
|
914
|
|
|
* |
|
915
|
|
|
* @return string |
|
916
|
|
|
*/ |
|
917
|
|
|
function _give_close_form_when_goal_achieved_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
918
|
|
|
$close_form = get_post_meta( $postid, '_give_close_form_when_goal_achieved', true ); |
|
919
|
|
|
|
|
920
|
|
|
if ( in_array( $close_form, array( 'yes', 'no' ) ) ) { |
|
921
|
|
|
$field_value = ( 'yes' === $close_form ? 'enabled' : 'disabled' ); |
|
922
|
|
|
} |
|
923
|
|
|
|
|
924
|
|
|
return $field_value; |
|
925
|
|
|
} |
|
926
|
|
|
|
|
927
|
|
|
add_filter( '_give_close_form_when_goal_achieved_field_value', '_give_close_form_when_goal_achieved_value', 10, 3 ); |
|
928
|
|
|
|
|
929
|
|
|
|
|
930
|
|
|
/** |
|
931
|
|
|
* Set value for Form display --> Guest Donation. |
|
932
|
|
|
* |
|
933
|
|
|
* Backward compatibility: set value by _give_logged_in_only form meta field value if it's value is yes or no. |
|
934
|
|
|
* |
|
935
|
|
|
* @since 1.8 |
|
936
|
|
|
* |
|
937
|
|
|
* @param mixed $field_value Field Value. |
|
938
|
|
|
* @param array $field Field args. |
|
939
|
|
|
* @param int $postid Form/Post ID. |
|
940
|
|
|
* |
|
941
|
|
|
* @return string |
|
942
|
|
|
*/ |
|
943
|
|
|
function _give_logged_in_only_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
944
|
|
|
$guest_donation = get_post_meta( $postid, '_give_logged_in_only', true ); |
|
945
|
|
|
|
|
946
|
|
|
if ( in_array( $guest_donation, array( 'yes', 'no' ) ) ) { |
|
947
|
|
|
$field_value = ( 'yes' === $guest_donation ? 'enabled' : 'disabled' ); |
|
948
|
|
|
} |
|
949
|
|
|
|
|
950
|
|
|
return $field_value; |
|
951
|
|
|
} |
|
952
|
|
|
|
|
953
|
|
|
add_filter( '_give_logged_in_only_field_value', '_give_logged_in_only_value', 10, 3 ); |
|
954
|
|
|
|
|
955
|
|
|
/** |
|
956
|
|
|
* Set value for Offline Donations --> Offline Donations. |
|
957
|
|
|
* |
|
958
|
|
|
* Backward compatibility: set value by _give_customize_offline_donations form meta field value if it's value is yes |
|
959
|
|
|
* or no. |
|
960
|
|
|
* |
|
961
|
|
|
* @since 1.8 |
|
962
|
|
|
* |
|
963
|
|
|
* @param mixed $field_value Field Value. |
|
964
|
|
|
* @param array $field Field args. |
|
965
|
|
|
* @param int $postid Form/Post ID. |
|
966
|
|
|
* |
|
967
|
|
|
* @return string |
|
968
|
|
|
*/ |
|
969
|
|
|
function _give_customize_offline_donations_value( $field_value, $field, $postid ) { |
|
|
|
|
|
|
970
|
|
|
$customize_offline_text = get_post_meta( $postid, '_give_customize_offline_donations', true ); |
|
971
|
|
|
|
|
972
|
|
|
if ( in_array( $customize_offline_text, array( 'yes', 'no' ) ) ) { |
|
973
|
|
|
$field_value = ( 'yes' === $customize_offline_text ? 'enabled' : 'disabled' ); |
|
974
|
|
|
} |
|
975
|
|
|
|
|
976
|
|
|
return $field_value; |
|
977
|
|
|
} |
|
978
|
|
|
|
|
979
|
|
|
add_filter( '_give_customize_offline_donations_field_value', '_give_customize_offline_donations_value', 10, 3 ); |
|
980
|
|
|
|
|
981
|
|
|
|
|
982
|
|
|
/** |
|
983
|
|
|
* Set repeater field id for multi donation form. |
|
984
|
|
|
* |
|
985
|
|
|
* @since 1.8 |
|
986
|
|
|
* |
|
987
|
|
|
* @param int $field_id |
|
988
|
|
|
* @param array $field |
|
989
|
|
|
* @param array $fields |
|
990
|
|
|
* @param bool $default |
|
991
|
|
|
* |
|
992
|
|
|
* @return mixed |
|
993
|
|
|
*/ |
|
994
|
|
|
function _give_set_multi_level_repeater_field_id( $field_id, $field, $fields, $default ) { |
|
|
|
|
|
|
995
|
|
|
$row_placeholder = false !== $default ? $default : '{{row-count-placeholder}}'; |
|
996
|
|
|
$field_id = "{$fields['id']}[{$row_placeholder}][{$field['id']}][level_id]"; |
|
997
|
|
|
|
|
998
|
|
|
return $field_id; |
|
999
|
|
|
} |
|
1000
|
|
|
|
|
1001
|
|
|
add_filter( 'give_get_repeater_field__give_id_name', '_give_set_multi_level_repeater_field_id', 10, 4 ); |
|
1002
|
|
|
|
|
1003
|
|
|
/** |
|
1004
|
|
|
* Set repeater field value for multi donation form. |
|
1005
|
|
|
* |
|
1006
|
|
|
* @since 1.8 |
|
1007
|
|
|
* |
|
1008
|
|
|
* @param string $field_value |
|
1009
|
|
|
* @param array $field |
|
1010
|
|
|
* @param array $field_group |
|
1011
|
|
|
* @param array $fields |
|
1012
|
|
|
* |
|
1013
|
|
|
* @return mixed |
|
1014
|
|
|
*/ |
|
1015
|
|
|
function _give_set_multi_level_repeater_field_value( $field_value, $field, $field_group, $fields ) { |
|
|
|
|
|
|
1016
|
|
|
$field_value = $field_group[ $field['id'] ]['level_id']; |
|
1017
|
|
|
|
|
1018
|
|
|
return $field_value; |
|
1019
|
|
|
} |
|
1020
|
|
|
|
|
1021
|
|
|
add_filter( 'give_get_repeater_field__give_id_value', '_give_set_multi_level_repeater_field_value', 10, 4 ); |
|
1022
|
|
|
|
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.