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