PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.4
GiveWP – Donation Plugin and Fundraising Platform v2.7.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / forms / class-metabox-form-data.php
give / includes / admin / forms Last commit date
class-give-form-duplicator.php 6 years ago class-metabox-form-data.php 5 years ago dashboard-columns.php 6 years ago metabox.php 6 years ago
class-metabox-form-data.php
1462 lines
1 <?php
2 /**
3 * Donation Form Data
4 *
5 * Displays the form data box, tabbed, with several panels.
6 *
7 * @package Give
8 * @subpackage Classes/Give_MetaBox_Form_Data
9 * @copyright Copyright (c) 2016, GiveWP
10 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
11 * @since 1.8
12 */
13
14 use Give\Form\Template;
15 use Give\FormAPI\Fields;
16 use Give\FormAPI\Section;
17 use Give\Helpers\Form\Template as FormTemplateUtils;
18
19 /**
20 * Give_Meta_Box_Form_Data Class.
21 */
22 class Give_MetaBox_Form_Data {
23
24 /**
25 * Meta box settings.
26 *
27 * @since 1.8
28 * @var array
29 */
30 private $settings = [];
31
32 /**
33 * Metabox ID.
34 *
35 * @since 1.8
36 * @var string
37 */
38 private $metabox_id;
39
40 /**
41 * Metabox Label.
42 *
43 * @since 1.8
44 * @var string
45 */
46 private $metabox_label;
47
48
49 /**
50 * Give_MetaBox_Form_Data constructor.
51 */
52 function __construct() {
53 $this->metabox_id = 'give-metabox-form-data';
54 $this->metabox_label = __( 'Donation Form Options', 'give' );
55
56 // Setup.
57 add_action( 'admin_init', [ $this, 'setup' ] );
58
59 // Add metabox.
60 add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ], 10 );
61
62 // Save form meta.
63 add_action( 'save_post_give_forms', [ $this, 'save' ], 10, 2 );
64
65 add_action( 'give_save__give_form_template', [ $this, 'save_form_template_settings' ], 10, 3 );
66
67 // cmb2 old setting loaders.
68 // add_filter( 'give_metabox_form_data_settings', array( $this, 'cmb2_metabox_settings' ) );
69 // Add offline donations options.
70 add_filter( 'give_metabox_form_data_settings', [ $this, 'add_offline_donations_setting_tab' ], 0, 1 );
71
72 // Maintain active tab query parameter after save.
73 add_filter( 'redirect_post_location', [ $this, 'maintain_active_tab' ], 10, 2 );
74 }
75
76 /**
77 * Setup metabox related data.
78 *
79 * @since 1.8
80 *
81 * @return void
82 */
83 function setup() {
84 $this->settings = $this->get_settings();
85 }
86
87
88 /**
89 * Get metabox settings
90 *
91 * @since 1.8
92 *
93 * @return array
94 */
95 function get_settings() {
96 $post_id = give_get_admin_post_id();
97 $price_placeholder = give_format_decimal( '1.00', false, false );
98
99 // Start with an underscore to hide fields from custom fields list
100 $prefix = '_give_';
101
102 $settings = [
103 /**
104 * Theme Options
105 */
106 'form_template_options' => apply_filters(
107 'give_form_template_options',
108 [
109 'id' => 'form_template_options',
110 'title' => __( 'Form Template', 'give' ),
111 'icon-html' => '<i class="fas fa-palette"></i>',
112 'fields' => [
113 [
114 'id' => $prefix . 'form_template',
115 'name' => 'form_template',
116 'type' => 'hidden',
117 'default' => '',
118 ],
119 ],
120 ]
121 ),
122
123 /**
124 * Repeatable Field Groups
125 */
126 'form_field_options' => apply_filters(
127 'give_forms_field_options',
128 [
129 'id' => 'form_field_options',
130 'title' => __( 'Donation Options', 'give' ),
131 'icon-html' => '<i class="fas fa-heart"></i>',
132 'fields' => apply_filters(
133 'give_forms_donation_form_metabox_fields',
134 [
135 // Donation Option.
136 [
137 'name' => __( 'Donation Option', 'give' ),
138 'description' => __( 'Do you want this form to have one set donation price or multiple levels (for example, $10, $20, $50)?', 'give' ),
139 'id' => $prefix . 'price_option',
140 'type' => 'radio_inline',
141 'default' => 'multi',
142 'options' => apply_filters(
143 'give_forms_price_options',
144 [
145 'multi' => __( 'Multi-level Donation', 'give' ),
146 'set' => __( 'Set Donation', 'give' ),
147 ]
148 ),
149 ],
150 [
151 'name' => __( 'Set Donation', 'give' ),
152 'description' => __( 'This is the set donation amount for this form. If you have a "Custom Amount Minimum" set, make sure it is less than this amount.', 'give' ),
153 'id' => $prefix . 'set_price',
154 'type' => 'text_small',
155 'data_type' => 'price',
156 'attributes' => [
157 'placeholder' => $price_placeholder,
158 'class' => 'give-money-field',
159 ],
160 'wrapper_class' => 'give-hidden',
161 ],
162 // Custom Amount.
163 [
164 'name' => __( 'Custom Amount', 'give' ),
165 'description' => __( 'Do you want the user to be able to input their own donation amount?', 'give' ),
166 'id' => $prefix . 'custom_amount',
167 'type' => 'radio_inline',
168 'default' => 'enabled',
169 'options' => [
170 'enabled' => __( 'Enabled', 'give' ),
171 'disabled' => __( 'Disabled', 'give' ),
172 ],
173 ],
174 [
175 'name' => __( 'Donation Limit', 'give' ),
176 'description' => __( 'Set the minimum and maximum amount for all gateways.', 'give' ),
177 'id' => $prefix . 'custom_amount_range',
178 'type' => 'donation_limit',
179 'wrapper_class' => 'give-hidden',
180 'data_type' => 'price',
181 'attributes' => [
182 'placeholder' => $price_placeholder,
183 'class' => 'give-money-field',
184 ],
185 'options' => [
186 'display_label' => __( 'Donation Limits: ', 'give' ),
187 'minimum' => give_format_decimal( '1.00', false, false ),
188 'maximum' => give_format_decimal( '999999.99', false, false ),
189 ],
190 ],
191 [
192 'name' => __( 'Custom Amount Text', 'give' ),
193 'description' => __( 'This text appears as a label below the custom amount field for set donation forms. For multi-level forms the text will appear as its own level (button, radio, or select option).', 'give' ),
194 'id' => $prefix . 'custom_amount_text',
195 'type' => 'text_medium',
196 'default' => __( 'Custom Amount', 'give' ),
197 'attributes' => [
198 'rows' => 3,
199 ],
200 'wrapper_class' => 'give-hidden',
201 ],
202 // Donation Levels.
203 [
204 'id' => $prefix . 'donation_levels',
205 'type' => 'group',
206 'options' => [
207 'add_button' => __( 'Add Level', 'give' ),
208 'header_title' => __( 'Donation Level', 'give' ),
209 'remove_button' => '<span class="dashicons dashicons-no"></span>',
210 ],
211 'default' => [
212 [
213 '_give_id' =>
214 [
215 'level_id' => 0,
216 ],
217 '_give_amount' => '10.000000',
218 ],
219 [
220 '_give_id' =>
221 [
222 'level_id' => 1,
223 ],
224 '_give_amount' => '25.000000',
225 ],
226 [
227 '_give_id' =>
228 [
229 'level_id' => 2,
230 ],
231 '_give_amount' => '50.000000',
232 ],
233 [
234 '_give_id' =>
235 [
236 'level_id' => 3,
237 ],
238 '_give_amount' => '100.000000',
239 '_give_default' => 'default',
240 ],
241 [
242 '_give_id' =>
243 [
244 'level_id' => 5,
245 ],
246 '_give_amount' => '250.000000',
247 ],
248 ],
249 'wrapper_class' => 'give-hidden',
250 // Fields array works the same, except id's only need to be unique for this group.
251 // Prefix is not needed.
252 'fields' => apply_filters(
253 'give_donation_levels_table_row',
254 [
255 [
256 'name' => __( 'ID', 'give' ),
257 'id' => $prefix . 'id',
258 'type' => 'levels_id',
259 ],
260 [
261 'name' => __( 'Amount', 'give' ),
262 'id' => $prefix . 'amount',
263 'type' => 'text_small',
264 'data_type' => 'price',
265 'attributes' => [
266 'placeholder' => $price_placeholder,
267 'class' => 'give-money-field',
268 ],
269 ],
270 [
271 'name' => __( 'Text', 'give' ),
272 'id' => $prefix . 'text',
273 'type' => 'text',
274 'attributes' => [
275 'placeholder' => __( 'Donation Level', 'give' ),
276 'class' => 'give-multilevel-text-field',
277 ],
278 ],
279 [
280 'name' => __( 'Default', 'give' ),
281 'id' => $prefix . 'default',
282 'type' => 'give_default_radio_inline',
283 ],
284 ]
285 ),
286 ],
287 [
288 'name' => 'donation_options_docs',
289 'type' => 'docs_link',
290 'url' => 'http://docs.givewp.com/form-donation-options',
291 'title' => __( 'Donation Options', 'give' ),
292 ],
293 ],
294 $post_id
295 ),
296 ]
297 ),
298
299 /**
300 * Display Options
301 */
302 'form_display_options' => apply_filters(
303 'give_form_display_options',
304 [
305 'id' => 'form_display_options',
306 'title' => __( 'Form Fields', 'give' ),
307 'icon-html' => '<i class="fas fa-stream"></i>',
308 'fields' => apply_filters(
309 'give_forms_display_options_metabox_fields',
310 [
311 [
312 'name' => __( 'Default Gateway', 'give' ),
313 'desc' => __( 'By default, the gateway for this form will inherit the global default gateway (set under GiveWP > Settings > Payment Gateways). This option allows you to customize the default gateway for this form only.', 'give' ),
314 'id' => $prefix . 'default_gateway',
315 'type' => 'default_gateway',
316 ],
317 [
318 'name' => __( 'Name Title Prefix', 'give' ),
319 'desc' => __( 'Do you want to add a name title prefix dropdown field before the donor\'s first name field? This will display a dropdown with options such as Mrs, Miss, Ms, Sir, and Dr for donor to choose from.', 'give' ),
320 'id' => $prefix . 'name_title_prefix',
321 'type' => 'radio_inline',
322 'options' => [
323 'global' => __( 'Global Option', 'give' ),
324 'required' => __( 'Required', 'give' ),
325 'optional' => __( 'Optional', 'give' ),
326 'disabled' => __( 'Disabled', 'give' ),
327 ],
328 'default' => 'global',
329 ],
330 [
331 'name' => __( 'Title Prefixes', 'give' ),
332 'desc' => __( 'Add or remove salutations from the dropdown using the field above.', 'give' ),
333 'id' => $prefix . 'title_prefixes',
334 'type' => 'chosen',
335 'data_type' => 'multiselect',
336 'allow-custom-values' => true,
337 'style' => 'width: 100%',
338 'wrapper_class' => 'give-hidden give-title-prefixes-wrap',
339 'options' => give_get_default_title_prefixes(),
340 ],
341 [
342 'name' => __( 'Company Donations', 'give' ),
343 'desc' => __( 'Do you want a Company field to appear after First Name and Last Name?', 'give' ),
344 'id' => $prefix . 'company_field',
345 'type' => 'radio_inline',
346 'default' => 'global',
347 'options' => [
348 'global' => __( 'Global Option', 'give' ),
349 'required' => __( 'Required', 'give' ),
350 'optional' => __( 'Optional', 'give' ),
351 'disabled' => __( 'Disabled', 'give' ),
352
353 ],
354 ],
355 [
356 'name' => __( 'Anonymous Donations', 'give' ),
357 'desc' => __( 'Do you want to provide donors the ability mark themselves anonymous while giving? This will prevent their information from appearing publicly on your website but you will still receive their information for your records in the admin panel.', 'give' ),
358 'id' => "{$prefix}anonymous_donation",
359 'type' => 'radio_inline',
360 'default' => 'global',
361 'options' => [
362 'global' => __( 'Global Option', 'give' ),
363 'enabled' => __( 'Enabled', 'give' ),
364 'disabled' => __( 'Disabled', 'give' ),
365 ],
366 ],
367 [
368 'name' => __( 'Donor Comments', 'give' ),
369 'desc' => __( 'Do you want to provide donors the ability to add a comment to their donation? The comment will display publicly on the donor wall if they do not select to give anonymously.', 'give' ),
370 'id' => "{$prefix}donor_comment",
371 'type' => 'radio_inline',
372 'default' => 'global',
373 'options' => [
374 'global' => __( 'Global Option', 'give' ),
375 'enabled' => __( 'Enabled', 'give' ),
376 'disabled' => __( 'Disabled', 'give' ),
377 ],
378 ],
379 [
380 'name' => __( 'Guest Donations', 'give' ),
381 'desc' => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ),
382 'id' => $prefix . 'logged_in_only',
383 'type' => 'radio_inline',
384 'default' => 'enabled',
385 'options' => [
386 'enabled' => __( 'Enabled', 'give' ),
387 'disabled' => __( 'Disabled', 'give' ),
388 ],
389 ],
390 [
391 'name' => __( 'Registration', 'give' ),
392 'desc' => __( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ),
393 'id' => $prefix . 'show_register_form',
394 'type' => 'radio',
395 'options' => [
396 'none' => __( 'None', 'give' ),
397 'registration' => __( 'Registration', 'give' ),
398 'login' => __( 'Login', 'give' ),
399 'both' => __( 'Registration + Login', 'give' ),
400 ],
401 'default' => 'none',
402 ],
403 [
404 'name' => 'form_display_docs',
405 'type' => 'docs_link',
406 'url' => 'http://docs.givewp.com/form-display-options',
407 'title' => __( 'Form Display', 'give' ),
408 ],
409 ],
410 $post_id
411 ),
412 ]
413 ),
414
415 /**
416 * Donation Goals
417 */
418 'donation_goal_options' => apply_filters(
419 'give_donation_goal_options',
420 [
421 'id' => 'donation_goal_options',
422 'title' => __( 'Donation Goal', 'give' ),
423 'icon-html' => '<i class="fas fa-bullseye"></i>',
424 'fields' => apply_filters(
425 'give_forms_donation_goal_metabox_fields',
426 [
427 // Goals
428 [
429 'name' => __( 'Donation Goal', 'give' ),
430 'description' => __( 'Do you want to set a donation goal for this form?', 'give' ),
431 'id' => $prefix . 'goal_option',
432 'type' => 'radio_inline',
433 'default' => 'disabled',
434 'options' => [
435 'enabled' => __( 'Enabled', 'give' ),
436 'disabled' => __( 'Disabled', 'give' ),
437 ],
438 ],
439
440 [
441 'name' => __( 'Goal Format', 'give' ),
442 'description' => __( 'Do you want to display the total amount raised based on your monetary goal or a percentage? For instance, "$500 of $1,000 raised" or "50% funded" or "1 of 5 donations". You can also display a donor-based goal, such as "100 of 1,000 donors have given".', 'give' ),
443 'id' => $prefix . 'goal_format',
444 'type' => 'donation_form_goal',
445 'default' => 'amount',
446 'options' => [
447 'amount' => __( 'Amount Raised', 'give' ),
448 'percentage' => __( 'Percentage Raised', 'give' ),
449 'donation' => __( 'Number of Donations', 'give' ),
450 'donors' => __( 'Number of Donors', 'give' ),
451 ],
452 ],
453
454 [
455 'name' => __( 'Goal Amount', 'give' ),
456 'description' => __( 'This is the monetary goal amount you want to reach for this form.', 'give' ),
457 'id' => $prefix . 'set_goal',
458 'type' => 'text_small',
459 'data_type' => 'price',
460 'attributes' => [
461 'placeholder' => $price_placeholder,
462 'class' => 'give-money-field',
463 ],
464 'wrapper_class' => 'give-hidden',
465 ],
466 [
467 'id' => $prefix . 'number_of_donation_goal',
468 'name' => __( 'Donation Goal', 'give' ),
469 'desc' => __( 'Set the total number of donations as a goal.', 'give' ),
470 'type' => 'number',
471 'default' => 1,
472 'attributes' => [
473 'placeholder' => 1,
474 ],
475 ],
476 [
477 'id' => $prefix . 'number_of_donor_goal',
478 'name' => __( 'Donor Goal', 'give' ),
479 'desc' => __( 'Set the total number of donors as a goal.', 'give' ),
480 'type' => 'number',
481 'default' => 1,
482 'attributes' => [
483 'placeholder' => 1,
484 ],
485 ],
486 [
487 'name' => __( 'Progress Bar Color', 'give' ),
488 'desc' => __( 'Customize the color of the goal progress bar.', 'give' ),
489 'id' => $prefix . 'goal_color',
490 'type' => 'colorpicker',
491 'default' => '#2bc253',
492 'wrapper_class' => 'give-hidden',
493 ],
494
495 [
496 'name' => __( 'Close Form', 'give' ),
497 'desc' => __( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ),
498 'id' => $prefix . 'close_form_when_goal_achieved',
499 'type' => 'radio_inline',
500 'default' => 'disabled',
501 'options' => [
502 'enabled' => __( 'Enabled', 'give' ),
503 'disabled' => __( 'Disabled', 'give' ),
504 ],
505 'wrapper_class' => 'give-hidden',
506 ],
507 [
508 'name' => __( 'Goal Achieved Message', 'give' ),
509 'desc' => __( 'Do you want to display a custom message when the goal is closed?', 'give' ),
510 'id' => $prefix . 'form_goal_achieved_message',
511 'type' => 'wysiwyg',
512 'default' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ),
513 'wrapper_class' => 'give-hidden',
514 ],
515 [
516 'name' => 'donation_goal_docs',
517 'type' => 'docs_link',
518 'url' => 'http://docs.givewp.com/form-donation-goal',
519 'title' => __( 'Donation Goal', 'give' ),
520 ],
521 ],
522 $post_id
523 ),
524 ]
525 ),
526
527 /**
528 * Terms & Conditions
529 */
530 'form_terms_options' => apply_filters(
531 'give_forms_terms_options',
532 [
533 'id' => 'form_terms_options',
534 'title' => __( 'Terms & Conditions', 'give' ),
535 'icon-html' => '<i class="far fa-check-square"></i>',
536 'fields' => apply_filters(
537 'give_forms_terms_options_metabox_fields',
538 [
539 // Donation Option
540 [
541 'name' => __( 'Terms and Conditions', 'give' ),
542 'description' => __( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ),
543 'id' => $prefix . 'terms_option',
544 'type' => 'radio_inline',
545 'options' => apply_filters(
546 'give_forms_content_options_select',
547 [
548 'global' => __( 'Global Option', 'give' ),
549 'enabled' => __( 'Customize', 'give' ),
550 'disabled' => __( 'Disable', 'give' ),
551 ]
552 ),
553 'default' => 'global',
554 ],
555 [
556 'id' => $prefix . 'agree_label',
557 'name' => __( 'Agreement Label', 'give' ),
558 'desc' => __( 'The label shown next to the agree to terms check box. Add your own to customize or leave blank to use the default text placeholder.', 'give' ),
559 'type' => 'textarea',
560 'attributes' => [
561 'placeholder' => __( 'Agree to Terms?', 'give' ),
562 'rows' => 1,
563 ],
564 'wrapper_class' => 'give-hidden',
565 ],
566 [
567 'id' => $prefix . 'agree_text',
568 'name' => __( 'Agreement Text', 'give' ),
569 'desc' => __( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ),
570 'default' => give_get_option( 'agreement_text' ),
571 'type' => 'wysiwyg',
572 'wrapper_class' => 'give-hidden',
573 ],
574 [
575 'name' => 'terms_docs',
576 'type' => 'docs_link',
577 'url' => 'http://docs.givewp.com/form-terms',
578 'title' => __( 'Terms and Conditions', 'give' ),
579 ],
580 ],
581 $post_id
582 ),
583 ]
584 ),
585 ];
586
587 /**
588 * Filter the metabox tabbed panel settings.
589 */
590 $settings = apply_filters( 'give_metabox_form_data_settings', $settings, $post_id );
591
592 // Output.
593 return $settings;
594 }
595
596 /**
597 * Add metabox.
598 *
599 * @since 1.8
600 *
601 * @return void
602 */
603 public function add_meta_box() {
604 add_meta_box(
605 $this->get_metabox_ID(),
606 $this->get_metabox_label(),
607 [ $this, 'output' ],
608 [ 'give_forms' ],
609 'normal',
610 'high'
611 );
612
613 // Show Goal Metabox only if goal is enabled.
614 if ( give_is_setting_enabled( give_get_meta( give_get_admin_post_id(), '_give_goal_option', true ) ) ) {
615 add_meta_box(
616 'give-form-goal-stats',
617 __( 'Goal Statistics', 'give' ),
618 [ $this, 'output_goal' ],
619 [ 'give_forms' ],
620 'side',
621 'low'
622 );
623 }
624
625 }
626
627
628 /**
629 * Enqueue scripts.
630 *
631 * @since 1.8
632 *
633 * @return void
634 */
635 function enqueue_script() {
636 global $post;
637
638 if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
639
640 }
641 }
642
643 /**
644 * Get metabox id.
645 *
646 * @since 1.8
647 *
648 * @return string
649 */
650 function get_metabox_ID() {
651 return $this->metabox_id;
652 }
653
654 /**
655 * Get metabox label.
656 *
657 * @since 1.8
658 *
659 * @return string
660 */
661 function get_metabox_label() {
662 return $this->metabox_label;
663 }
664
665
666 /**
667 * Get metabox tabs.
668 *
669 * @since 1.8
670 *
671 * @return array
672 */
673 public function get_tabs() {
674 $tabs = [];
675
676 if ( ! empty( $this->settings ) ) {
677 foreach ( $this->settings as $setting ) {
678 if ( ! isset( $setting['id'] ) || ! isset( $setting['title'] ) ) {
679 continue;
680 }
681 $tab = [
682 'id' => $setting['id'],
683 'label' => $setting['title'],
684 'icon-html' => ( ! empty( $setting['icon-html'] ) ? $setting['icon-html'] : '' ),
685 ];
686
687 if ( $this->has_sub_tab( $setting ) ) {
688 if ( empty( $setting['sub-fields'] ) ) {
689 $tab = [];
690 } else {
691 foreach ( $setting['sub-fields'] as $sub_fields ) {
692 $tab['sub-fields'][] = [
693 'id' => $sub_fields['id'],
694 'label' => $sub_fields['title'],
695 'icon-html' => ( ! empty( $sub_fields['icon-html'] ) ? $sub_fields['icon-html'] : '' ),
696 ];
697 }
698 }
699 }
700
701 if ( ! empty( $tab ) ) {
702 $tabs[] = $tab;
703 }
704 }
705 }
706
707 return $tabs;
708 }
709
710 /**
711 * Output metabox settings.
712 *
713 * @since 1.8
714 *
715 * @return void
716 */
717 public function output() {
718 // Bailout.
719 if ( $form_data_tabs = $this->get_tabs() ) :
720 Template\LegacyFormSettingCompatibility::migrateExistingFormSettings();
721
722 $active_tab = ! empty( $_GET['give_tab'] ) ? give_clean( $_GET['give_tab'] ) : 'form_template_options';
723 wp_nonce_field( 'give_save_form_meta', 'give_form_meta_nonce' );
724
725 $upsell_html = $this->upsell_html();
726 $added_upsells_notice = false;
727 ?>
728 <input id="give_form_active_tab" type="hidden" name="give_form_active_tab">
729 <div class="give-metabox-panel-wrap">
730 <ul class="give-form-data-tabs give-metabox-tabs">
731 <?php foreach ( $form_data_tabs as $index => $form_data_tab ) : ?>
732 <?php
733 // Determine if current tab is active.
734 $is_active = $active_tab === $form_data_tab['id'] ? true : false;
735 ?>
736 <li class="<?php echo "{$form_data_tab['id']}_tab" . ( $is_active ? ' active' : '' ) . ( $this->has_sub_tab( $form_data_tab ) ? ' has-sub-fields' : '' ); ?>">
737 <a href="#<?php echo $form_data_tab['id']; ?>"
738 data-tab-id="<?php echo $form_data_tab['id']; ?>">
739 <?php if ( ! empty( $form_data_tab['icon-html'] ) ) : ?>
740 <?php echo $form_data_tab['icon-html']; ?>
741 <?php else : ?>
742 <i class="fas fa-angle-right"></i>
743 <?php endif; ?>
744 <span class="give-label"><?php echo $form_data_tab['label']; ?></span>
745 </a>
746 <?php if ( $this->has_sub_tab( $form_data_tab ) ) : ?>
747 <ul class="give-metabox-sub-tabs give-hidden">
748 <?php foreach ( $form_data_tab['sub-fields'] as $sub_tab ) : ?>
749 <li class="<?php echo "{$sub_tab['id']}_tab"; ?>">
750 <a href="#<?php echo $sub_tab['id']; ?>"
751 data-tab-id="<?php echo $sub_tab['id']; ?>">
752 <?php if ( ! empty( $sub_tab['icon-html'] ) ) : ?>
753 <?php echo $sub_tab['icon-html']; ?>
754 <?php else : ?>
755 <i class="fas fa-angle-right"></i>
756 <?php endif; ?>
757 <span class="give-label"><?php echo $sub_tab['label']; ?></span>
758 </a>
759 </li>
760 <?php endforeach; ?>
761 </ul>
762 <?php endif; ?>
763 </li>
764 <?php endforeach; ?>
765 </ul>
766
767 <?php foreach ( $this->settings as $setting ) : ?>
768 <?php do_action( "give_before_{$setting['id']}_settings" ); ?>
769 <?php
770 // Determine if current panel is active.
771 $is_active = $active_tab === $setting['id'];
772 ?>
773 <div id="<?php echo $setting['id']; ?>"
774 class="panel give_options_panel<?php echo( $is_active ? ' active' : '' ); ?>">
775 <?php
776 if ( ! $added_upsells_notice ) {
777 echo $upsell_html;
778 $added_upsells_notice = true;
779 }
780 ?>
781 <?php if ( ! empty( $setting['fields'] ) ) : ?>
782 <?php foreach ( $setting['fields'] as $field ) : ?>
783 <?php give_render_field( $field ); ?>
784 <?php endforeach; ?>
785 <?php endif; ?>
786 <?php do_action( "give_post_{$setting['id']}_settings" ); ?>
787 </div>
788 <?php do_action( "give_after_{$setting['id']}_settings" ); ?>
789
790
791 <?php if ( $this->has_sub_tab( $setting ) ) : ?>
792 <?php if ( ! empty( $setting['sub-fields'] ) ) : ?>
793 <?php foreach ( $setting['sub-fields'] as $index => $sub_fields ) : ?>
794 <div id="<?php echo $sub_fields['id']; ?>" class="panel give_options_panel give-hidden">
795 <?php if ( ! empty( $sub_fields['fields'] ) ) : ?>
796 <?php foreach ( $sub_fields['fields'] as $sub_field ) : ?>
797 <?php give_render_field( $sub_field ); ?>
798 <?php endforeach; ?>
799 <?php endif; ?>
800 </div>
801 <?php endforeach; ?>
802 <?php endif; ?>
803 <?php endif; ?>
804 <?php endforeach; ?>
805 </div>
806 <?php
807 endif; // End if().
808 }
809
810
811 /**
812 * Gt upsells html
813 *
814 * @return string
815 * @since 2.6.0
816 */
817 private function upsell_html() {
818 if ( Give_License::get_plugin_by_slug( 'give-recurring' ) ) {
819 return '';
820 }
821
822 $addon_link_url = esc_url( 'https://go.givewp.com/addons-recurring-inlinelink' );
823 $addon_button_url = esc_url( 'https://go.givewp.com/addons-recurring-button' );
824
825 return sprintf(
826 '
827 <div class="give-upsell-notice">
828 <span class="icon dashicons dashicons-update-alt"></span>
829 <span class="description">%1$s</span>
830 <a class="view-addon-link button" href="%2$s" target="_blank">%3$s</a>
831 </div>
832 ',
833 sprintf(
834 __( 'Activate the <a href="%1$s" title="%2$s" target="_blank">Recurring Donations add-on</a> and provide your donors with flexible subscription giving options.', 'give' ),
835 $addon_link_url,
836 __( 'Click to view the Recurring Donations add-on', 'give' )
837 ),
838 $addon_button_url,
839 __( 'View Add-on', 'give' )
840 );
841 }
842
843 /**
844 * Output Goal meta-box settings.
845 *
846 * @param object $post Post Object.
847 *
848 * @access public
849 * @since 2.1.0
850 *
851 * @return void
852 */
853 public function output_goal( $post ) {
854
855 echo give_admin_form_goal_stats( $post->ID );
856
857 }
858
859 /**
860 * Check if setting field has sub tabs/fields
861 *
862 * @param array $field_setting Field Settings.
863 *
864 * @since 1.8
865 *
866 * @return bool
867 */
868 private function has_sub_tab( $field_setting ) {
869 $has_sub_tab = false;
870 if ( array_key_exists( 'sub-fields', $field_setting ) ) {
871 $has_sub_tab = true;
872 }
873
874 return $has_sub_tab;
875 }
876
877 /**
878 * CMB2 settings loader.
879 *
880 * @since 1.8
881 *
882 * @return array
883 */
884 function cmb2_metabox_settings() {
885 $all_cmb2_settings = apply_filters( 'cmb2_meta_boxes', [] );
886 $give_forms_settings = $all_cmb2_settings;
887
888 // Filter settings: Use only give forms related settings.
889 foreach ( $all_cmb2_settings as $index => $setting ) {
890 if ( ! in_array( 'give_forms', $setting['object_types'] ) ) {
891 unset( $give_forms_settings[ $index ] );
892 }
893 }
894
895 return $give_forms_settings;
896
897 }
898
899 /**
900 * Check if we're saving, the trigger an action based on the post type.
901 *
902 * @param int $post_id Post ID.
903 * @param int|object $post Post Object.
904 *
905 * @since 1.8
906 *
907 * @return void
908 */
909 public function save( $post_id, $post ) {
910
911 // $post_id and $post are required.
912 if ( empty( $post_id ) || empty( $post ) ) {
913 return;
914 }
915
916 // Don't save meta boxes for revisions or autosaves.
917 if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
918 return;
919 }
920
921 // Check the nonce.
922 if ( empty( $_POST['give_form_meta_nonce'] ) || ! wp_verify_nonce( $_POST['give_form_meta_nonce'], 'give_save_form_meta' ) ) {
923 return;
924 }
925
926 // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
927 if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
928 return;
929 }
930
931 // Check user has permission to edit.
932 if ( ! current_user_can( 'edit_post', $post_id ) ) {
933 return;
934 }
935
936 // Fire action before saving form meta.
937 do_action( 'give_pre_process_give_forms_meta', $post_id, $post );
938
939 /**
940 * Filter the meta key to save.
941 * Third party addon developer can remove there meta keys from this array to handle saving data on there own.
942 */
943 $form_meta_keys = apply_filters( 'give_process_form_meta_keys', $this->get_meta_keys_from_settings() );
944
945 // Save form meta data.
946 if ( ! empty( $form_meta_keys ) ) {
947 foreach ( $form_meta_keys as $form_meta_key ) {
948
949 // Set default value for checkbox fields.
950 if (
951 ! isset( $_POST[ $form_meta_key ] ) &&
952 in_array( $this->get_field_type( $form_meta_key ), [ 'checkbox', 'chosen' ] )
953 ) {
954 $_POST[ $form_meta_key ] = '';
955 }
956
957 if ( isset( $_POST[ $form_meta_key ] ) ) {
958 $setting_field = $this->get_setting_field( $form_meta_key );
959 if ( ! empty( $setting_field['type'] ) ) {
960 switch ( $setting_field['type'] ) {
961 case 'textarea':
962 case 'wysiwyg':
963 $form_meta_value = wp_kses_post( $_POST[ $form_meta_key ] );
964 break;
965
966 case 'donation_limit':
967 $form_meta_value = $_POST[ $form_meta_key ];
968 break;
969
970 case 'group':
971 $form_meta_value = [];
972
973 foreach ( $_POST[ $form_meta_key ] as $index => $group ) {
974
975 // Do not save template input field values.
976 if ( '{{row-count-placeholder}}' === $index ) {
977 continue;
978 }
979
980 $group_meta_value = [];
981 foreach ( $group as $field_id => $field_value ) {
982 switch ( $this->get_field_type( $field_id, $form_meta_key ) ) {
983 case 'wysiwyg':
984 $group_meta_value[ $field_id ] = wp_kses_post( $field_value );
985 break;
986
987 default:
988 $group_meta_value[ $field_id ] = give_clean( $field_value );
989 }
990 }
991
992 if ( ! empty( $group_meta_value ) ) {
993 $form_meta_value[ $index ] = $group_meta_value;
994 }
995 }
996
997 // Arrange repeater field keys in order.
998 $form_meta_value = array_values( $form_meta_value );
999 break;
1000
1001 default:
1002 $form_meta_value = give_clean( $_POST[ $form_meta_key ] );
1003 }// End switch().
1004
1005 /**
1006 * Filter the form meta value before saving
1007 *
1008 * @since 1.8.9
1009 */
1010 $form_meta_value = apply_filters(
1011 'give_pre_save_form_meta_value',
1012 $this->sanitize_form_meta( $form_meta_value, $setting_field ),
1013 $form_meta_key,
1014 $this,
1015 $post_id
1016 );
1017
1018 // Range slider.
1019 if ( 'donation_limit' === $setting_field['type'] ) {
1020
1021 // Sanitize amount for db.
1022 $form_meta_value = array_map( 'give_sanitize_amount_for_db', $form_meta_value );
1023
1024 // Store it to form meta.
1025 give_update_meta( $post_id, $form_meta_key . '_minimum', $form_meta_value['minimum'] );
1026 give_update_meta( $post_id, $form_meta_key . '_maximum', $form_meta_value['maximum'] );
1027 } else {
1028 // Save data.
1029 give_update_meta( $post_id, $form_meta_key, $form_meta_value );
1030 }
1031
1032 // Verify and delete form meta based on the form status.
1033 give_set_form_closed_status( $post_id );
1034
1035 // Fire after saving form meta key.
1036 do_action( "give_save_{$form_meta_key}", $form_meta_key, $form_meta_value, $post_id, $post );
1037 }// End if().
1038 }// End if().
1039 }// End foreach().
1040 }// End if().
1041
1042 // Update the goal progress for donation form.
1043 give_update_goal_progress( $post_id );
1044
1045 // Fire action after saving form meta.
1046 do_action( 'give_post_process_give_forms_meta', $post_id, $post );
1047 }
1048
1049
1050 /**
1051 * Save form template setting handler
1052 *
1053 * @param string $meta_key
1054 * @param string $new_template
1055 * @param int $formID
1056 */
1057 public function save_form_template_settings( $meta_key, $new_template, $formID ) {
1058 // Save setting for new template only if it is not empty.
1059 if ( ! $new_template ) {
1060 return;
1061 }
1062
1063 $options = $_POST[ $new_template ];
1064
1065 // Exit
1066 if ( empty( $options ) ) {
1067 return;
1068 }
1069
1070 /* @var Template $template */
1071 $template = Give()->templates->getTemplate( $new_template );
1072
1073 // If selected theme is not registered then do not save it's options.
1074 if ( null === $template ) {
1075 return;
1076 }
1077
1078 /* @var Template\Options $templateOptions */
1079 $templateOptions = $template->getOptions();
1080 $saveOptions = FormTemplateUtils::getOptions( $formID );
1081
1082 /* @var Section $group */
1083 foreach ( $templateOptions->sections as $group ) {
1084 /* @var Fields $field */
1085 foreach ( $group->fields as $field ) {
1086 if ( ! isset( $options[ $group->id ][ $field->id ] ) ) {
1087 continue;
1088 }
1089
1090 // Initialize $value for every field to prevent value type conflict.
1091 $value = null;
1092
1093 switch ( $field->type ) {
1094 case 'textarea':
1095 case 'wysiwyg':
1096 $value = wp_kses_post( $options[ $group->id ][ $field->id ] );
1097 break;
1098
1099 case 'donation_limit':
1100 $value = $options[ $group->id ][ $field->id ];
1101 break;
1102
1103 case 'group':
1104 /* @var \Give\FormAPI\Form\Group $field */
1105 foreach ( $options[ $group->id ][ $field->id ] as $index => $subFields ) {
1106
1107 // Do not save template input field values.
1108 if ( '{{row-count-placeholder}}' === $index ) {
1109 continue;
1110 }
1111
1112 $group_of_values = [];
1113
1114 foreach ( $subFields as $field_id => $field_value ) {
1115 switch ( $field->getFieldArguments( $field_id )['type'] ) {
1116 case 'wysiwyg':
1117 $group_of_values[ $field_id ] = wp_kses_post( $field_value );
1118 break;
1119
1120 default:
1121 $group_of_values[ $field_id ] = give_clean( $field_value );
1122 }
1123 }
1124
1125 if ( ! empty( $group_of_values ) ) {
1126 $value[ $index ] = $group_of_values;
1127 }
1128 }
1129
1130 // Arrange repeater field keys in order.
1131 $value = $value ? array_values( $value ) : [];
1132 break;
1133
1134 default:
1135 $value = give_clean( $options[ $group->id ][ $field->id ] );
1136 }// End switch().
1137
1138 $saveOptions[ $group->id ][ $field->id ] = $value;
1139 }
1140 }
1141
1142 FormTemplateUtils::saveOptions( $formID, $saveOptions );
1143 }
1144
1145
1146 /**
1147 * Get field ID.
1148 *
1149 * @param array $field Array of Fields.
1150 *
1151 * @since 1.8
1152 *
1153 * @return string
1154 */
1155 private function get_field_id( $field ) {
1156 $field_id = '';
1157
1158 if ( array_key_exists( 'id', $field ) ) {
1159 $field_id = $field['id'];
1160
1161 }
1162
1163 return $field_id;
1164 }
1165
1166 /**
1167 * Get fields ID.
1168 *
1169 * @param array $setting Array of settings.
1170 *
1171 * @since 1.8
1172 *
1173 * @return array
1174 */
1175 private function get_fields_id( $setting ) {
1176 $meta_keys = [];
1177
1178 if (
1179 ! empty( $setting )
1180 && array_key_exists( 'fields', $setting )
1181 && ! empty( $setting['fields'] )
1182 ) {
1183 foreach ( $setting['fields'] as $field ) {
1184 if ( $field_id = $this->get_field_id( $field ) ) {
1185 $meta_keys[] = $field_id;
1186 }
1187 }
1188 }
1189
1190 return $meta_keys;
1191 }
1192
1193 /**
1194 * Get sub fields ID.
1195 *
1196 * @param array $setting Array of settings.
1197 *
1198 * @since 1.8
1199 *
1200 * @return array
1201 */
1202 private function get_sub_fields_id( $setting ) {
1203 $meta_keys = [];
1204
1205 if ( $this->has_sub_tab( $setting ) && ! empty( $setting['sub-fields'] ) ) {
1206 foreach ( $setting['sub-fields'] as $fields ) {
1207 if ( ! empty( $fields['fields'] ) ) {
1208 foreach ( $fields['fields'] as $field ) {
1209 if ( $field_id = $this->get_field_id( $field ) ) {
1210 $meta_keys[] = $field_id;
1211 }
1212 }
1213 }
1214 }
1215 }
1216
1217 return $meta_keys;
1218 }
1219
1220
1221 /**
1222 * Get all setting field ids.
1223 *
1224 * @since 1.8
1225 *
1226 * @return array
1227 */
1228 private function get_meta_keys_from_settings() {
1229 $meta_keys = [];
1230
1231 foreach ( $this->settings as $setting ) {
1232 $meta_key = $this->get_fields_id( $setting );
1233
1234 if ( $this->has_sub_tab( $setting ) ) {
1235 $meta_key = array_merge( $meta_key, $this->get_sub_fields_id( $setting ) );
1236 }
1237
1238 $meta_keys = array_merge( $meta_keys, $meta_key );
1239 }
1240
1241 return $meta_keys;
1242 }
1243
1244
1245 /**
1246 * Get field type.
1247 *
1248 * @param string $field_id Field ID.
1249 * @param string $group_id Field Group ID.
1250 *
1251 * @since 1.8
1252 *
1253 * @return string
1254 */
1255 function get_field_type( $field_id, $group_id = '' ) {
1256 $field = $this->get_setting_field( $field_id, $group_id );
1257
1258 $type = array_key_exists( 'type', $field )
1259 ? $field['type']
1260 : '';
1261
1262 return $type;
1263 }
1264
1265
1266 /**
1267 * Get Field
1268 *
1269 * @param array $setting Settings array.
1270 * @param string $field_id Field ID.
1271 *
1272 * @since 1.8
1273 *
1274 * @return array
1275 */
1276 private function get_field( $setting, $field_id ) {
1277 $setting_field = [];
1278
1279 if ( ! empty( $setting['fields'] ) ) {
1280 foreach ( $setting['fields'] as $field ) {
1281 if ( array_key_exists( 'id', $field ) && $field['id'] === $field_id ) {
1282 $setting_field = $field;
1283 break;
1284 }
1285 }
1286 }
1287
1288 return $setting_field;
1289 }
1290
1291 /**
1292 * Get Sub Field
1293 *
1294 * @param array $setting Settings array.
1295 * @param string $field_id Field ID.
1296 *
1297 * @since 1.8
1298 *
1299 * @return array
1300 */
1301 private function get_sub_field( $setting, $field_id ) {
1302 $setting_field = [];
1303
1304 if ( ! empty( $setting['sub-fields'] ) ) {
1305 foreach ( $setting['sub-fields'] as $fields ) {
1306 if ( $field = $this->get_field( $fields, $field_id ) ) {
1307 $setting_field = $field;
1308 break;
1309 }
1310 }
1311 }
1312
1313 return $setting_field;
1314 }
1315
1316 /**
1317 * Get setting field.
1318 *
1319 * @param string $field_id Field ID.
1320 * @param string $group_id Get sub field from group.
1321 *
1322 * @since 1.8
1323 *
1324 * @return array
1325 */
1326 function get_setting_field( $field_id, $group_id = '' ) {
1327 $setting_field = [];
1328
1329 $_field_id = $field_id;
1330 $field_id = empty( $group_id ) ? $field_id : $group_id;
1331
1332 if ( ! empty( $this->settings ) ) {
1333 foreach ( $this->settings as $setting ) {
1334 if (
1335 ( $this->has_sub_tab( $setting ) && ( $setting_field = $this->get_sub_field( $setting, $field_id ) ) )
1336 || ( $setting_field = $this->get_field( $setting, $field_id ) )
1337 ) {
1338 break;
1339 }
1340 }
1341 }
1342
1343 // Get field from group.
1344 if ( ! empty( $group_id ) ) {
1345 foreach ( $setting_field['fields'] as $field ) {
1346 if ( array_key_exists( 'id', $field ) && $field['id'] === $_field_id ) {
1347 $setting_field = $field;
1348 }
1349 }
1350 }
1351
1352 return $setting_field;
1353 }
1354
1355
1356 /**
1357 * Add offline donations setting tab to donation form options metabox.
1358 *
1359 * @param array $settings List of form settings.
1360 *
1361 * @since 1.8
1362 *
1363 * @return mixed
1364 */
1365 function add_offline_donations_setting_tab( $settings ) {
1366 if ( give_is_gateway_active( 'offline' ) ) {
1367 $settings['offline_donations_options'] = apply_filters(
1368 'give_forms_offline_donations_options',
1369 [
1370 'id' => 'offline_donations_options',
1371 'title' => __( 'Offline Donations', 'give' ),
1372 'icon-html' => '<i class="fas fa-wallet"></i>',
1373 'fields' => apply_filters( 'give_forms_offline_donations_metabox_fields', [] ),
1374 ]
1375 );
1376 }
1377
1378 return $settings;
1379 }
1380
1381
1382 /**
1383 * Sanitize form meta values before saving.
1384 *
1385 * @param mixed $meta_value Meta Value for sanitizing before saving.
1386 * @param array $setting_field Setting Field.
1387 *
1388 * @since 1.8.9
1389 * @access public
1390 *
1391 * @return mixed
1392 */
1393 function sanitize_form_meta( $meta_value, $setting_field ) {
1394 switch ( $setting_field['type'] ) {
1395 case 'group':
1396 if ( ! empty( $setting_field['fields'] ) ) {
1397 foreach ( $setting_field['fields'] as $field ) {
1398 if ( empty( $field['data_type'] ) || 'price' !== $field['data_type'] ) {
1399 continue;
1400 }
1401
1402 foreach ( $meta_value as $index => $meta_data ) {
1403 if ( ! isset( $meta_value[ $index ][ $field['id'] ] ) ) {
1404 continue;
1405 }
1406
1407 $meta_value[ $index ][ $field['id'] ] = ! empty( $meta_value[ $index ][ $field['id'] ] ) ?
1408 give_sanitize_amount_for_db( $meta_value[ $index ][ $field['id'] ] ) :
1409 ( ( '_give_amount' === $field['id'] && empty( $field_value ) ) ?
1410 give_sanitize_amount_for_db( '1.00' ) :
1411 0 );
1412 }
1413 }
1414 }
1415 break;
1416
1417 default:
1418 if ( ! empty( $setting_field['data_type'] ) && 'price' === $setting_field['data_type'] ) {
1419 $meta_value = $meta_value ?
1420 give_sanitize_amount_for_db( $meta_value ) :
1421 ( in_array(
1422 $setting_field['id'],
1423 [
1424 '_give_set_price',
1425 '_give_custom_amount_minimum',
1426 '_give_set_goal',
1427 ]
1428 ) ?
1429 give_sanitize_amount_for_db( '1.00' ) :
1430 0 );
1431 }
1432 }
1433
1434 return $meta_value;
1435 }
1436
1437 /**
1438 * Maintain the active tab after save.
1439 *
1440 * @param string $location The destination URL.
1441 * @param int $post_id The post ID.
1442 *
1443 * @since 1.8.13
1444 * @access public
1445 *
1446 * @return string The URL after redirect.
1447 */
1448 public function maintain_active_tab( $location, $post_id ) {
1449 if (
1450 'give_forms' === get_post_type( $post_id ) &&
1451 ! empty( $_POST['give_form_active_tab'] )
1452 ) {
1453 $location = add_query_arg( 'give_tab', give_clean( $_POST['give_form_active_tab'] ), $location );
1454 }
1455
1456 return $location;
1457 }
1458 }
1459
1460 new Give_MetaBox_Form_Data();
1461
1462