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