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