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