PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.2
GiveWP – Donation Plugin and Fundraising Platform v2.7.2
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 6 years ago dashboard-columns.php 6 years ago metabox.php 6 years ago
class-metabox-form-data.php
1461 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 'style' => 'width: 100%',
337 'wrapper_class' => 'give-hidden give-title-prefixes-wrap',
338 'options' => give_get_default_title_prefixes(),
339 ],
340 [
341 'name' => __( 'Company Donations', 'give' ),
342 'desc' => __( 'Do you want a Company field to appear after First Name and Last Name?', 'give' ),
343 'id' => $prefix . 'company_field',
344 'type' => 'radio_inline',
345 'default' => 'global',
346 'options' => [
347 'global' => __( 'Global Option', 'give' ),
348 'required' => __( 'Required', 'give' ),
349 'optional' => __( 'Optional', 'give' ),
350 'disabled' => __( 'Disabled', 'give' ),
351
352 ],
353 ],
354 [
355 'name' => __( 'Anonymous Donations', 'give' ),
356 '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' ),
357 'id' => "{$prefix}anonymous_donation",
358 'type' => 'radio_inline',
359 'default' => 'global',
360 'options' => [
361 'global' => __( 'Global Option', 'give' ),
362 'enabled' => __( 'Enabled', 'give' ),
363 'disabled' => __( 'Disabled', 'give' ),
364 ],
365 ],
366 [
367 'name' => __( 'Donor Comments', 'give' ),
368 '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' ),
369 'id' => "{$prefix}donor_comment",
370 'type' => 'radio_inline',
371 'default' => 'global',
372 'options' => [
373 'global' => __( 'Global Option', 'give' ),
374 'enabled' => __( 'Enabled', 'give' ),
375 'disabled' => __( 'Disabled', 'give' ),
376 ],
377 ],
378 [
379 'name' => __( 'Guest Donations', 'give' ),
380 'desc' => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ),
381 'id' => $prefix . 'logged_in_only',
382 'type' => 'radio_inline',
383 'default' => 'enabled',
384 'options' => [
385 'enabled' => __( 'Enabled', 'give' ),
386 'disabled' => __( 'Disabled', 'give' ),
387 ],
388 ],
389 [
390 'name' => __( 'Registration', 'give' ),
391 'desc' => __( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ),
392 'id' => $prefix . 'show_register_form',
393 'type' => 'radio',
394 'options' => [
395 'none' => __( 'None', 'give' ),
396 'registration' => __( 'Registration', 'give' ),
397 'login' => __( 'Login', 'give' ),
398 'both' => __( 'Registration + Login', 'give' ),
399 ],
400 'default' => 'none',
401 ],
402 [
403 'name' => 'form_display_docs',
404 'type' => 'docs_link',
405 'url' => 'http://docs.givewp.com/form-display-options',
406 'title' => __( 'Form Display', 'give' ),
407 ],
408 ],
409 $post_id
410 ),
411 ]
412 ),
413
414 /**
415 * Donation Goals
416 */
417 'donation_goal_options' => apply_filters(
418 'give_donation_goal_options',
419 [
420 'id' => 'donation_goal_options',
421 'title' => __( 'Donation Goal', 'give' ),
422 'icon-html' => '<i class="fas fa-bullseye"></i>',
423 'fields' => apply_filters(
424 'give_forms_donation_goal_metabox_fields',
425 [
426 // Goals
427 [
428 'name' => __( 'Donation Goal', 'give' ),
429 'description' => __( 'Do you want to set a donation goal for this form?', 'give' ),
430 'id' => $prefix . 'goal_option',
431 'type' => 'radio_inline',
432 'default' => 'disabled',
433 'options' => [
434 'enabled' => __( 'Enabled', 'give' ),
435 'disabled' => __( 'Disabled', 'give' ),
436 ],
437 ],
438
439 [
440 'name' => __( 'Goal Format', 'give' ),
441 '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' ),
442 'id' => $prefix . 'goal_format',
443 'type' => 'donation_form_goal',
444 'default' => 'amount',
445 'options' => [
446 'amount' => __( 'Amount Raised', 'give' ),
447 'percentage' => __( 'Percentage Raised', 'give' ),
448 'donation' => __( 'Number of Donations', 'give' ),
449 'donors' => __( 'Number of Donors', 'give' ),
450 ],
451 ],
452
453 [
454 'name' => __( 'Goal Amount', 'give' ),
455 'description' => __( 'This is the monetary goal amount you want to reach for this form.', 'give' ),
456 'id' => $prefix . 'set_goal',
457 'type' => 'text_small',
458 'data_type' => 'price',
459 'attributes' => [
460 'placeholder' => $price_placeholder,
461 'class' => 'give-money-field',
462 ],
463 'wrapper_class' => 'give-hidden',
464 ],
465 [
466 'id' => $prefix . 'number_of_donation_goal',
467 'name' => __( 'Donation Goal', 'give' ),
468 'desc' => __( 'Set the total number of donations as a goal.', 'give' ),
469 'type' => 'number',
470 'default' => 1,
471 'attributes' => [
472 'placeholder' => 1,
473 ],
474 ],
475 [
476 'id' => $prefix . 'number_of_donor_goal',
477 'name' => __( 'Donor Goal', 'give' ),
478 'desc' => __( 'Set the total number of donors as a goal.', 'give' ),
479 'type' => 'number',
480 'default' => 1,
481 'attributes' => [
482 'placeholder' => 1,
483 ],
484 ],
485 [
486 'name' => __( 'Progress Bar Color', 'give' ),
487 'desc' => __( 'Customize the color of the goal progress bar.', 'give' ),
488 'id' => $prefix . 'goal_color',
489 'type' => 'colorpicker',
490 'default' => '#2bc253',
491 'wrapper_class' => 'give-hidden',
492 ],
493
494 [
495 'name' => __( 'Close Form', 'give' ),
496 'desc' => __( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ),
497 'id' => $prefix . 'close_form_when_goal_achieved',
498 'type' => 'radio_inline',
499 'default' => 'disabled',
500 'options' => [
501 'enabled' => __( 'Enabled', 'give' ),
502 'disabled' => __( 'Disabled', 'give' ),
503 ],
504 'wrapper_class' => 'give-hidden',
505 ],
506 [
507 'name' => __( 'Goal Achieved Message', 'give' ),
508 'desc' => __( 'Do you want to display a custom message when the goal is closed?', 'give' ),
509 'id' => $prefix . 'form_goal_achieved_message',
510 'type' => 'wysiwyg',
511 'default' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ),
512 'wrapper_class' => 'give-hidden',
513 ],
514 [
515 'name' => 'donation_goal_docs',
516 'type' => 'docs_link',
517 'url' => 'http://docs.givewp.com/form-donation-goal',
518 'title' => __( 'Donation Goal', 'give' ),
519 ],
520 ],
521 $post_id
522 ),
523 ]
524 ),
525
526 /**
527 * Terms & Conditions
528 */
529 'form_terms_options' => apply_filters(
530 'give_forms_terms_options',
531 [
532 'id' => 'form_terms_options',
533 'title' => __( 'Terms & Conditions', 'give' ),
534 'icon-html' => '<i class="far fa-check-square"></i>',
535 'fields' => apply_filters(
536 'give_forms_terms_options_metabox_fields',
537 [
538 // Donation Option
539 [
540 'name' => __( 'Terms and Conditions', 'give' ),
541 'description' => __( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ),
542 'id' => $prefix . 'terms_option',
543 'type' => 'radio_inline',
544 'options' => apply_filters(
545 'give_forms_content_options_select',
546 [
547 'global' => __( 'Global Option', 'give' ),
548 'enabled' => __( 'Customize', 'give' ),
549 'disabled' => __( 'Disable', 'give' ),
550 ]
551 ),
552 'default' => 'global',
553 ],
554 [
555 'id' => $prefix . 'agree_label',
556 'name' => __( 'Agreement Label', 'give' ),
557 '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' ),
558 'type' => 'textarea',
559 'attributes' => [
560 'placeholder' => __( 'Agree to Terms?', 'give' ),
561 'rows' => 1,
562 ],
563 'wrapper_class' => 'give-hidden',
564 ],
565 [
566 'id' => $prefix . 'agree_text',
567 'name' => __( 'Agreement Text', 'give' ),
568 'desc' => __( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ),
569 'default' => give_get_option( 'agreement_text' ),
570 'type' => 'wysiwyg',
571 'wrapper_class' => 'give-hidden',
572 ],
573 [
574 'name' => 'terms_docs',
575 'type' => 'docs_link',
576 'url' => 'http://docs.givewp.com/form-terms',
577 'title' => __( 'Terms and Conditions', 'give' ),
578 ],
579 ],
580 $post_id
581 ),
582 ]
583 ),
584 ];
585
586 /**
587 * Filter the metabox tabbed panel settings.
588 */
589 $settings = apply_filters( 'give_metabox_form_data_settings', $settings, $post_id );
590
591 // Output.
592 return $settings;
593 }
594
595 /**
596 * Add metabox.
597 *
598 * @since 1.8
599 *
600 * @return void
601 */
602 public function add_meta_box() {
603 add_meta_box(
604 $this->get_metabox_ID(),
605 $this->get_metabox_label(),
606 [ $this, 'output' ],
607 [ 'give_forms' ],
608 'normal',
609 'high'
610 );
611
612 // Show Goal Metabox only if goal is enabled.
613 if ( give_is_setting_enabled( give_get_meta( give_get_admin_post_id(), '_give_goal_option', true ) ) ) {
614 add_meta_box(
615 'give-form-goal-stats',
616 __( 'Goal Statistics', 'give' ),
617 [ $this, 'output_goal' ],
618 [ 'give_forms' ],
619 'side',
620 'low'
621 );
622 }
623
624 }
625
626
627 /**
628 * Enqueue scripts.
629 *
630 * @since 1.8
631 *
632 * @return void
633 */
634 function enqueue_script() {
635 global $post;
636
637 if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
638
639 }
640 }
641
642 /**
643 * Get metabox id.
644 *
645 * @since 1.8
646 *
647 * @return string
648 */
649 function get_metabox_ID() {
650 return $this->metabox_id;
651 }
652
653 /**
654 * Get metabox label.
655 *
656 * @since 1.8
657 *
658 * @return string
659 */
660 function get_metabox_label() {
661 return $this->metabox_label;
662 }
663
664
665 /**
666 * Get metabox tabs.
667 *
668 * @since 1.8
669 *
670 * @return array
671 */
672 public function get_tabs() {
673 $tabs = [];
674
675 if ( ! empty( $this->settings ) ) {
676 foreach ( $this->settings as $setting ) {
677 if ( ! isset( $setting['id'] ) || ! isset( $setting['title'] ) ) {
678 continue;
679 }
680 $tab = [
681 'id' => $setting['id'],
682 'label' => $setting['title'],
683 'icon-html' => ( ! empty( $setting['icon-html'] ) ? $setting['icon-html'] : '' ),
684 ];
685
686 if ( $this->has_sub_tab( $setting ) ) {
687 if ( empty( $setting['sub-fields'] ) ) {
688 $tab = [];
689 } else {
690 foreach ( $setting['sub-fields'] as $sub_fields ) {
691 $tab['sub-fields'][] = [
692 'id' => $sub_fields['id'],
693 'label' => $sub_fields['title'],
694 'icon-html' => ( ! empty( $sub_fields['icon-html'] ) ? $sub_fields['icon-html'] : '' ),
695 ];
696 }
697 }
698 }
699
700 if ( ! empty( $tab ) ) {
701 $tabs[] = $tab;
702 }
703 }
704 }
705
706 return $tabs;
707 }
708
709 /**
710 * Output metabox settings.
711 *
712 * @since 1.8
713 *
714 * @return void
715 */
716 public function output() {
717 // Bailout.
718 if ( $form_data_tabs = $this->get_tabs() ) :
719 Template\LegacyFormSettingCompatibility::migrateExistingFormSettings();
720
721 $active_tab = ! empty( $_GET['give_tab'] ) ? give_clean( $_GET['give_tab'] ) : 'form_template_options';
722 wp_nonce_field( 'give_save_form_meta', 'give_form_meta_nonce' );
723
724 $upsell_html = $this->upsell_html();
725 $added_upsells_notice = false;
726 ?>
727 <input id="give_form_active_tab" type="hidden" name="give_form_active_tab">
728 <div class="give-metabox-panel-wrap">
729 <ul class="give-form-data-tabs give-metabox-tabs">
730 <?php foreach ( $form_data_tabs as $index => $form_data_tab ) : ?>
731 <?php
732 // Determine if current tab is active.
733 $is_active = $active_tab === $form_data_tab['id'] ? true : false;
734 ?>
735 <li class="<?php echo "{$form_data_tab['id']}_tab" . ( $is_active ? ' active' : '' ) . ( $this->has_sub_tab( $form_data_tab ) ? ' has-sub-fields' : '' ); ?>">
736 <a href="#<?php echo $form_data_tab['id']; ?>"
737 data-tab-id="<?php echo $form_data_tab['id']; ?>">
738 <?php if ( ! empty( $form_data_tab['icon-html'] ) ) : ?>
739 <?php echo $form_data_tab['icon-html']; ?>
740 <?php else : ?>
741 <i class="fas fa-angle-right"></i>
742 <?php endif; ?>
743 <span class="give-label"><?php echo $form_data_tab['label']; ?></span>
744 </a>
745 <?php if ( $this->has_sub_tab( $form_data_tab ) ) : ?>
746 <ul class="give-metabox-sub-tabs give-hidden">
747 <?php foreach ( $form_data_tab['sub-fields'] as $sub_tab ) : ?>
748 <li class="<?php echo "{$sub_tab['id']}_tab"; ?>">
749 <a href="#<?php echo $sub_tab['id']; ?>"
750 data-tab-id="<?php echo $sub_tab['id']; ?>">
751 <?php if ( ! empty( $sub_tab['icon-html'] ) ) : ?>
752 <?php echo $sub_tab['icon-html']; ?>
753 <?php else : ?>
754 <i class="fas fa-angle-right"></i>
755 <?php endif; ?>
756 <span class="give-label"><?php echo $sub_tab['label']; ?></span>
757 </a>
758 </li>
759 <?php endforeach; ?>
760 </ul>
761 <?php endif; ?>
762 </li>
763 <?php endforeach; ?>
764 </ul>
765
766 <?php foreach ( $this->settings as $setting ) : ?>
767 <?php do_action( "give_before_{$setting['id']}_settings" ); ?>
768 <?php
769 // Determine if current panel is active.
770 $is_active = $active_tab === $setting['id'];
771 ?>
772 <div id="<?php echo $setting['id']; ?>"
773 class="panel give_options_panel<?php echo( $is_active ? ' active' : '' ); ?>">
774 <?php
775 if ( ! $added_upsells_notice ) {
776 echo $upsell_html;
777 $added_upsells_notice = true;
778 }
779 ?>
780 <?php if ( ! empty( $setting['fields'] ) ) : ?>
781 <?php foreach ( $setting['fields'] as $field ) : ?>
782 <?php give_render_field( $field ); ?>
783 <?php endforeach; ?>
784 <?php endif; ?>
785 <?php do_action( "give_post_{$setting['id']}_settings" ); ?>
786 </div>
787 <?php do_action( "give_after_{$setting['id']}_settings" ); ?>
788
789
790 <?php if ( $this->has_sub_tab( $setting ) ) : ?>
791 <?php if ( ! empty( $setting['sub-fields'] ) ) : ?>
792 <?php foreach ( $setting['sub-fields'] as $index => $sub_fields ) : ?>
793 <div id="<?php echo $sub_fields['id']; ?>" class="panel give_options_panel give-hidden">
794 <?php if ( ! empty( $sub_fields['fields'] ) ) : ?>
795 <?php foreach ( $sub_fields['fields'] as $sub_field ) : ?>
796 <?php give_render_field( $sub_field ); ?>
797 <?php endforeach; ?>
798 <?php endif; ?>
799 </div>
800 <?php endforeach; ?>
801 <?php endif; ?>
802 <?php endif; ?>
803 <?php endforeach; ?>
804 </div>
805 <?php
806 endif; // End if().
807 }
808
809
810 /**
811 * Gt upsells html
812 *
813 * @return string
814 * @since 2.6.0
815 */
816 private function upsell_html() {
817 if ( Give_License::get_plugin_by_slug( 'give-recurring' ) ) {
818 return '';
819 }
820
821 $addon_link_url = esc_url( 'https://go.givewp.com/addons-recurring-inlinelink' );
822 $addon_button_url = esc_url( 'https://go.givewp.com/addons-recurring-button' );
823
824 return sprintf(
825 '
826 <div class="give-upsell-notice">
827 <span class="icon dashicons dashicons-update-alt"></span>
828 <span class="description">%1$s</span>
829 <a class="view-addon-link button" href="%2$s" target="_blank">%3$s</a>
830 </div>
831 ',
832 sprintf(
833 __( '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' ),
834 $addon_link_url,
835 __( 'Click to view the Recurring Donations add-on', 'give' )
836 ),
837 $addon_button_url,
838 __( 'View Add-on', 'give' )
839 );
840 }
841
842 /**
843 * Output Goal meta-box settings.
844 *
845 * @param object $post Post Object.
846 *
847 * @access public
848 * @since 2.1.0
849 *
850 * @return void
851 */
852 public function output_goal( $post ) {
853
854 echo give_admin_form_goal_stats( $post->ID );
855
856 }
857
858 /**
859 * Check if setting field has sub tabs/fields
860 *
861 * @param array $field_setting Field Settings.
862 *
863 * @since 1.8
864 *
865 * @return bool
866 */
867 private function has_sub_tab( $field_setting ) {
868 $has_sub_tab = false;
869 if ( array_key_exists( 'sub-fields', $field_setting ) ) {
870 $has_sub_tab = true;
871 }
872
873 return $has_sub_tab;
874 }
875
876 /**
877 * CMB2 settings loader.
878 *
879 * @since 1.8
880 *
881 * @return array
882 */
883 function cmb2_metabox_settings() {
884 $all_cmb2_settings = apply_filters( 'cmb2_meta_boxes', [] );
885 $give_forms_settings = $all_cmb2_settings;
886
887 // Filter settings: Use only give forms related settings.
888 foreach ( $all_cmb2_settings as $index => $setting ) {
889 if ( ! in_array( 'give_forms', $setting['object_types'] ) ) {
890 unset( $give_forms_settings[ $index ] );
891 }
892 }
893
894 return $give_forms_settings;
895
896 }
897
898 /**
899 * Check if we're saving, the trigger an action based on the post type.
900 *
901 * @param int $post_id Post ID.
902 * @param int|object $post Post Object.
903 *
904 * @since 1.8
905 *
906 * @return void
907 */
908 public function save( $post_id, $post ) {
909
910 // $post_id and $post are required.
911 if ( empty( $post_id ) || empty( $post ) ) {
912 return;
913 }
914
915 // Don't save meta boxes for revisions or autosaves.
916 if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
917 return;
918 }
919
920 // Check the nonce.
921 if ( empty( $_POST['give_form_meta_nonce'] ) || ! wp_verify_nonce( $_POST['give_form_meta_nonce'], 'give_save_form_meta' ) ) {
922 return;
923 }
924
925 // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
926 if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
927 return;
928 }
929
930 // Check user has permission to edit.
931 if ( ! current_user_can( 'edit_post', $post_id ) ) {
932 return;
933 }
934
935 // Fire action before saving form meta.
936 do_action( 'give_pre_process_give_forms_meta', $post_id, $post );
937
938 /**
939 * Filter the meta key to save.
940 * Third party addon developer can remove there meta keys from this array to handle saving data on there own.
941 */
942 $form_meta_keys = apply_filters( 'give_process_form_meta_keys', $this->get_meta_keys_from_settings() );
943
944 // Save form meta data.
945 if ( ! empty( $form_meta_keys ) ) {
946 foreach ( $form_meta_keys as $form_meta_key ) {
947
948 // Set default value for checkbox fields.
949 if (
950 ! isset( $_POST[ $form_meta_key ] ) &&
951 in_array( $this->get_field_type( $form_meta_key ), [ 'checkbox', 'chosen' ] )
952 ) {
953 $_POST[ $form_meta_key ] = '';
954 }
955
956 if ( isset( $_POST[ $form_meta_key ] ) ) {
957 $setting_field = $this->get_setting_field( $form_meta_key );
958 if ( ! empty( $setting_field['type'] ) ) {
959 switch ( $setting_field['type'] ) {
960 case 'textarea':
961 case 'wysiwyg':
962 $form_meta_value = wp_kses_post( $_POST[ $form_meta_key ] );
963 break;
964
965 case 'donation_limit':
966 $form_meta_value = $_POST[ $form_meta_key ];
967 break;
968
969 case 'group':
970 $form_meta_value = [];
971
972 foreach ( $_POST[ $form_meta_key ] as $index => $group ) {
973
974 // Do not save template input field values.
975 if ( '{{row-count-placeholder}}' === $index ) {
976 continue;
977 }
978
979 $group_meta_value = [];
980 foreach ( $group as $field_id => $field_value ) {
981 switch ( $this->get_field_type( $field_id, $form_meta_key ) ) {
982 case 'wysiwyg':
983 $group_meta_value[ $field_id ] = wp_kses_post( $field_value );
984 break;
985
986 default:
987 $group_meta_value[ $field_id ] = give_clean( $field_value );
988 }
989 }
990
991 if ( ! empty( $group_meta_value ) ) {
992 $form_meta_value[ $index ] = $group_meta_value;
993 }
994 }
995
996 // Arrange repeater field keys in order.
997 $form_meta_value = array_values( $form_meta_value );
998 break;
999
1000 default:
1001 $form_meta_value = give_clean( $_POST[ $form_meta_key ] );
1002 }// End switch().
1003
1004 /**
1005 * Filter the form meta value before saving
1006 *
1007 * @since 1.8.9
1008 */
1009 $form_meta_value = apply_filters(
1010 'give_pre_save_form_meta_value',
1011 $this->sanitize_form_meta( $form_meta_value, $setting_field ),
1012 $form_meta_key,
1013 $this,
1014 $post_id
1015 );
1016
1017 // Range slider.
1018 if ( 'donation_limit' === $setting_field['type'] ) {
1019
1020 // Sanitize amount for db.
1021 $form_meta_value = array_map( 'give_sanitize_amount_for_db', $form_meta_value );
1022
1023 // Store it to form meta.
1024 give_update_meta( $post_id, $form_meta_key . '_minimum', $form_meta_value['minimum'] );
1025 give_update_meta( $post_id, $form_meta_key . '_maximum', $form_meta_value['maximum'] );
1026 } else {
1027 // Save data.
1028 give_update_meta( $post_id, $form_meta_key, $form_meta_value );
1029 }
1030
1031 // Verify and delete form meta based on the form status.
1032 give_set_form_closed_status( $post_id );
1033
1034 // Fire after saving form meta key.
1035 do_action( "give_save_{$form_meta_key}", $form_meta_key, $form_meta_value, $post_id, $post );
1036 }// End if().
1037 }// End if().
1038 }// End foreach().
1039 }// End if().
1040
1041 // Update the goal progress for donation form.
1042 give_update_goal_progress( $post_id );
1043
1044 // Fire action after saving form meta.
1045 do_action( 'give_post_process_give_forms_meta', $post_id, $post );
1046 }
1047
1048
1049 /**
1050 * Save form template setting handler
1051 *
1052 * @param string $meta_key
1053 * @param string $new_template
1054 * @param int $formID
1055 */
1056 public function save_form_template_settings( $meta_key, $new_template, $formID ) {
1057 // Save setting for new template only if it is not empty.
1058 if ( ! $new_template ) {
1059 return;
1060 }
1061
1062 $options = $_POST[ $new_template ];
1063
1064 // Exit
1065 if ( empty( $options ) ) {
1066 return;
1067 }
1068
1069 /* @var Template $template */
1070 $template = Give()->templates->getTemplate( $new_template );
1071
1072 // If selected theme is not registered then do not save it's options.
1073 if ( null === $template ) {
1074 return;
1075 }
1076
1077 /* @var Template\Options $templateOptions */
1078 $templateOptions = $template->getOptions();
1079 $saveOptions = FormTemplateUtils::getOptions( $formID );
1080
1081 /* @var Section $group */
1082 foreach ( $templateOptions->sections as $group ) {
1083 /* @var Fields $field */
1084 foreach ( $group->fields as $field ) {
1085 if ( ! isset( $options[ $group->id ][ $field->id ] ) ) {
1086 continue;
1087 }
1088
1089 // Initialize $value for every field to prevent value type conflict.
1090 $value = null;
1091
1092 switch ( $field->type ) {
1093 case 'textarea':
1094 case 'wysiwyg':
1095 $value = wp_kses_post( $options[ $group->id ][ $field->id ] );
1096 break;
1097
1098 case 'donation_limit':
1099 $value = $options[ $group->id ][ $field->id ];
1100 break;
1101
1102 case 'group':
1103 /* @var \Give\FormAPI\Form\Group $field */
1104 foreach ( $options[ $group->id ][ $field->id ] as $index => $subFields ) {
1105
1106 // Do not save template input field values.
1107 if ( '{{row-count-placeholder}}' === $index ) {
1108 continue;
1109 }
1110
1111 $group_of_values = [];
1112
1113 foreach ( $subFields as $field_id => $field_value ) {
1114 switch ( $field->getFieldArguments( $field_id )['type'] ) {
1115 case 'wysiwyg':
1116 $group_of_values[ $field_id ] = wp_kses_post( $field_value );
1117 break;
1118
1119 default:
1120 $group_of_values[ $field_id ] = give_clean( $field_value );
1121 }
1122 }
1123
1124 if ( ! empty( $group_of_values ) ) {
1125 $value[ $index ] = $group_of_values;
1126 }
1127 }
1128
1129 // Arrange repeater field keys in order.
1130 $value = $value ? array_values( $value ) : [];
1131 break;
1132
1133 default:
1134 $value = give_clean( $options[ $group->id ][ $field->id ] );
1135 }// End switch().
1136
1137 $saveOptions[ $group->id ][ $field->id ] = $value;
1138 }
1139 }
1140
1141 FormTemplateUtils::saveOptions( $formID, $saveOptions );
1142 }
1143
1144
1145 /**
1146 * Get field ID.
1147 *
1148 * @param array $field Array of Fields.
1149 *
1150 * @since 1.8
1151 *
1152 * @return string
1153 */
1154 private function get_field_id( $field ) {
1155 $field_id = '';
1156
1157 if ( array_key_exists( 'id', $field ) ) {
1158 $field_id = $field['id'];
1159
1160 }
1161
1162 return $field_id;
1163 }
1164
1165 /**
1166 * Get fields ID.
1167 *
1168 * @param array $setting Array of settings.
1169 *
1170 * @since 1.8
1171 *
1172 * @return array
1173 */
1174 private function get_fields_id( $setting ) {
1175 $meta_keys = [];
1176
1177 if (
1178 ! empty( $setting )
1179 && array_key_exists( 'fields', $setting )
1180 && ! empty( $setting['fields'] )
1181 ) {
1182 foreach ( $setting['fields'] as $field ) {
1183 if ( $field_id = $this->get_field_id( $field ) ) {
1184 $meta_keys[] = $field_id;
1185 }
1186 }
1187 }
1188
1189 return $meta_keys;
1190 }
1191
1192 /**
1193 * Get sub fields ID.
1194 *
1195 * @param array $setting Array of settings.
1196 *
1197 * @since 1.8
1198 *
1199 * @return array
1200 */
1201 private function get_sub_fields_id( $setting ) {
1202 $meta_keys = [];
1203
1204 if ( $this->has_sub_tab( $setting ) && ! empty( $setting['sub-fields'] ) ) {
1205 foreach ( $setting['sub-fields'] as $fields ) {
1206 if ( ! empty( $fields['fields'] ) ) {
1207 foreach ( $fields['fields'] as $field ) {
1208 if ( $field_id = $this->get_field_id( $field ) ) {
1209 $meta_keys[] = $field_id;
1210 }
1211 }
1212 }
1213 }
1214 }
1215
1216 return $meta_keys;
1217 }
1218
1219
1220 /**
1221 * Get all setting field ids.
1222 *
1223 * @since 1.8
1224 *
1225 * @return array
1226 */
1227 private function get_meta_keys_from_settings() {
1228 $meta_keys = [];
1229
1230 foreach ( $this->settings as $setting ) {
1231 $meta_key = $this->get_fields_id( $setting );
1232
1233 if ( $this->has_sub_tab( $setting ) ) {
1234 $meta_key = array_merge( $meta_key, $this->get_sub_fields_id( $setting ) );
1235 }
1236
1237 $meta_keys = array_merge( $meta_keys, $meta_key );
1238 }
1239
1240 return $meta_keys;
1241 }
1242
1243
1244 /**
1245 * Get field type.
1246 *
1247 * @param string $field_id Field ID.
1248 * @param string $group_id Field Group ID.
1249 *
1250 * @since 1.8
1251 *
1252 * @return string
1253 */
1254 function get_field_type( $field_id, $group_id = '' ) {
1255 $field = $this->get_setting_field( $field_id, $group_id );
1256
1257 $type = array_key_exists( 'type', $field )
1258 ? $field['type']
1259 : '';
1260
1261 return $type;
1262 }
1263
1264
1265 /**
1266 * Get Field
1267 *
1268 * @param array $setting Settings array.
1269 * @param string $field_id Field ID.
1270 *
1271 * @since 1.8
1272 *
1273 * @return array
1274 */
1275 private function get_field( $setting, $field_id ) {
1276 $setting_field = [];
1277
1278 if ( ! empty( $setting['fields'] ) ) {
1279 foreach ( $setting['fields'] as $field ) {
1280 if ( array_key_exists( 'id', $field ) && $field['id'] === $field_id ) {
1281 $setting_field = $field;
1282 break;
1283 }
1284 }
1285 }
1286
1287 return $setting_field;
1288 }
1289
1290 /**
1291 * Get Sub Field
1292 *
1293 * @param array $setting Settings array.
1294 * @param string $field_id Field ID.
1295 *
1296 * @since 1.8
1297 *
1298 * @return array
1299 */
1300 private function get_sub_field( $setting, $field_id ) {
1301 $setting_field = [];
1302
1303 if ( ! empty( $setting['sub-fields'] ) ) {
1304 foreach ( $setting['sub-fields'] as $fields ) {
1305 if ( $field = $this->get_field( $fields, $field_id ) ) {
1306 $setting_field = $field;
1307 break;
1308 }
1309 }
1310 }
1311
1312 return $setting_field;
1313 }
1314
1315 /**
1316 * Get setting field.
1317 *
1318 * @param string $field_id Field ID.
1319 * @param string $group_id Get sub field from group.
1320 *
1321 * @since 1.8
1322 *
1323 * @return array
1324 */
1325 function get_setting_field( $field_id, $group_id = '' ) {
1326 $setting_field = [];
1327
1328 $_field_id = $field_id;
1329 $field_id = empty( $group_id ) ? $field_id : $group_id;
1330
1331 if ( ! empty( $this->settings ) ) {
1332 foreach ( $this->settings as $setting ) {
1333 if (
1334 ( $this->has_sub_tab( $setting ) && ( $setting_field = $this->get_sub_field( $setting, $field_id ) ) )
1335 || ( $setting_field = $this->get_field( $setting, $field_id ) )
1336 ) {
1337 break;
1338 }
1339 }
1340 }
1341
1342 // Get field from group.
1343 if ( ! empty( $group_id ) ) {
1344 foreach ( $setting_field['fields'] as $field ) {
1345 if ( array_key_exists( 'id', $field ) && $field['id'] === $_field_id ) {
1346 $setting_field = $field;
1347 }
1348 }
1349 }
1350
1351 return $setting_field;
1352 }
1353
1354
1355 /**
1356 * Add offline donations setting tab to donation form options metabox.
1357 *
1358 * @param array $settings List of form settings.
1359 *
1360 * @since 1.8
1361 *
1362 * @return mixed
1363 */
1364 function add_offline_donations_setting_tab( $settings ) {
1365 if ( give_is_gateway_active( 'offline' ) ) {
1366 $settings['offline_donations_options'] = apply_filters(
1367 'give_forms_offline_donations_options',
1368 [
1369 'id' => 'offline_donations_options',
1370 'title' => __( 'Offline Donations', 'give' ),
1371 'icon-html' => '<i class="fas fa-wallet"></i>',
1372 'fields' => apply_filters( 'give_forms_offline_donations_metabox_fields', [] ),
1373 ]
1374 );
1375 }
1376
1377 return $settings;
1378 }
1379
1380
1381 /**
1382 * Sanitize form meta values before saving.
1383 *
1384 * @param mixed $meta_value Meta Value for sanitizing before saving.
1385 * @param array $setting_field Setting Field.
1386 *
1387 * @since 1.8.9
1388 * @access public
1389 *
1390 * @return mixed
1391 */
1392 function sanitize_form_meta( $meta_value, $setting_field ) {
1393 switch ( $setting_field['type'] ) {
1394 case 'group':
1395 if ( ! empty( $setting_field['fields'] ) ) {
1396 foreach ( $setting_field['fields'] as $field ) {
1397 if ( empty( $field['data_type'] ) || 'price' !== $field['data_type'] ) {
1398 continue;
1399 }
1400
1401 foreach ( $meta_value as $index => $meta_data ) {
1402 if ( ! isset( $meta_value[ $index ][ $field['id'] ] ) ) {
1403 continue;
1404 }
1405
1406 $meta_value[ $index ][ $field['id'] ] = ! empty( $meta_value[ $index ][ $field['id'] ] ) ?
1407 give_sanitize_amount_for_db( $meta_value[ $index ][ $field['id'] ] ) :
1408 ( ( '_give_amount' === $field['id'] && empty( $field_value ) ) ?
1409 give_sanitize_amount_for_db( '1.00' ) :
1410 0 );
1411 }
1412 }
1413 }
1414 break;
1415
1416 default:
1417 if ( ! empty( $setting_field['data_type'] ) && 'price' === $setting_field['data_type'] ) {
1418 $meta_value = $meta_value ?
1419 give_sanitize_amount_for_db( $meta_value ) :
1420 ( in_array(
1421 $setting_field['id'],
1422 [
1423 '_give_set_price',
1424 '_give_custom_amount_minimum',
1425 '_give_set_goal',
1426 ]
1427 ) ?
1428 give_sanitize_amount_for_db( '1.00' ) :
1429 0 );
1430 }
1431 }
1432
1433 return $meta_value;
1434 }
1435
1436 /**
1437 * Maintain the active tab after save.
1438 *
1439 * @param string $location The destination URL.
1440 * @param int $post_id The post ID.
1441 *
1442 * @since 1.8.13
1443 * @access public
1444 *
1445 * @return string The URL after redirect.
1446 */
1447 public function maintain_active_tab( $location, $post_id ) {
1448 if (
1449 'give_forms' === get_post_type( $post_id ) &&
1450 ! empty( $_POST['give_form_active_tab'] )
1451 ) {
1452 $location = add_query_arg( 'give_tab', give_clean( $_POST['give_form_active_tab'] ), $location );
1453 }
1454
1455 return $location;
1456 }
1457 }
1458
1459 new Give_MetaBox_Form_Data();
1460
1461