PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.0
GiveWP – Donation Plugin and Fundraising Platform v2.1.0
4.16.3 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-metabox-form-data.php 8 years ago dashboard-columns.php 8 years ago metabox.php 8 years ago
class-metabox-form-data.php
1277 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' => 1.00,
167 'maximum' => 999999.99,
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' => __( 'Company Donations', 'give' ),
284 'desc' => __( 'Do you want a Company field to appear after First Name and Last Name?', 'give' ),
285 'id' => $prefix . 'company_field',
286 'type' => 'radio_inline',
287 'default' => 'global',
288 'options' => array(
289 'global' => __( 'Global Option', 'give' ),
290 'required' => __( 'Required', 'give' ),
291 'optional' => __( 'Optional', 'give' ),
292 'disabled' => __( 'Disabled', 'give' ),
293
294 ),
295 ),
296 array(
297 'name' => __( 'Guest Donations', 'give' ),
298 'desc' => __( 'Do you want to allow non-logged-in users to make donations?', 'give' ),
299 'id' => $prefix . 'logged_in_only',
300 'type' => 'radio_inline',
301 'default' => 'enabled',
302 'options' => array(
303 'enabled' => __( 'Enabled', 'give' ),
304 'disabled' => __( 'Disabled', 'give' ),
305 ),
306 ),
307 array(
308 'name' => __( 'Registration', 'give' ),
309 'desc' => __( 'Display the registration and login forms in the payment section for non-logged-in users.', 'give' ),
310 'id' => $prefix . 'show_register_form',
311 'type' => 'radio',
312 'options' => array(
313 'none' => __( 'None', 'give' ),
314 'registration' => __( 'Registration', 'give' ),
315 'login' => __( 'Login', 'give' ),
316 'both' => __( 'Registration + Login', 'give' ),
317 ),
318 'default' => 'none',
319 ),
320 array(
321 'name' => __( 'Floating Labels', 'give' ),
322 /* translators: %s: forms http://docs.givewp.com/form-floating-labels */
323 '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' ) ),
324 'id' => $prefix . 'form_floating_labels',
325 'type' => 'radio_inline',
326 'options' => array(
327 'global' => __( 'Global Option', 'give' ),
328 'enabled' => __( 'Enabled', 'give' ),
329 'disabled' => __( 'Disabled', 'give' ),
330 ),
331 'default' => 'global',
332 ),
333 array(
334 'name' => 'form_display_docs',
335 'type' => 'docs_link',
336 'url' => 'http://docs.givewp.com/form-display-options',
337 'title' => __( 'Form Display', 'give' ),
338 ),
339 ),
340 $post_id
341 ),
342 )
343 ),
344
345 /**
346 * Donation Goals
347 */
348 'donation_goal_options' => apply_filters( 'give_donation_goal_options', array(
349 'id' => 'donation_goal_options',
350 'title' => __( 'Donation Goal', 'give' ),
351 'icon-html' => '<span class="give-icon give-icon-target"></span>',
352 'fields' => apply_filters( 'give_forms_donation_goal_metabox_fields', array(
353 // Goals
354 array(
355 'name' => __( 'Donation Goal', 'give' ),
356 'description' => __( 'Do you want to set a donation goal for this form?', 'give' ),
357 'id' => $prefix . 'goal_option',
358 'type' => 'radio_inline',
359 'default' => 'disabled',
360 'options' => array(
361 'enabled' => __( 'Enabled', 'give' ),
362 'disabled' => __( 'Disabled', 'give' ),
363 ),
364 ),
365
366 array(
367 'name' => __( 'Goal Format', 'give' ),
368 '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' ),
369 'id' => $prefix . 'goal_format',
370 'type' => 'radio',
371 'default' => 'amount',
372 'options' => array(
373 'amount' => __( 'Amount Raised', 'give' ),
374 'percentage' => __( 'Percentage Raised', 'give' ),
375 'donation' => __( 'Number of Donations', 'give' ),
376 'donors' => __( 'Number of Donors', 'give' ),
377 ),
378 ),
379
380 array(
381 'name' => __( 'Goal Amount', 'give' ),
382 'description' => __( 'This is the monetary goal amount you want to reach for this form.', 'give' ),
383 'id' => $prefix . 'set_goal',
384 'type' => 'text_small',
385 'data_type' => 'price',
386 'attributes' => array(
387 'placeholder' => $price_placeholder,
388 'class' => 'give-money-field',
389 ),
390 'wrapper_class' => 'give-hidden',
391 ),
392 array(
393 'id' => $prefix . 'number_of_donation_goal',
394 'name' => __( 'Donation Goal', 'give' ),
395 'desc' => __( 'Set the total number of donations as a goal.', 'give' ),
396 'type' => 'number',
397 'default' => 1,
398 'attributes' => array(
399 'placeholder' => 1,
400 ),
401 ),
402 array(
403 'id' => $prefix . 'number_of_donor_goal',
404 'name' => __( 'Donor Goal', 'give' ),
405 'desc' => __( 'Set the total number of donors as a goal.', 'give' ),
406 'type' => 'number',
407 'default' => 1,
408 'attributes' => array(
409 'placeholder' => 1,
410 ),
411 ),
412 array(
413 'name' => __( 'Progress Bar Color', 'give' ),
414 'desc' => __( 'Customize the color of the goal progress bar.', 'give' ),
415 'id' => $prefix . 'goal_color',
416 'type' => 'colorpicker',
417 'default' => '#2bc253',
418 'wrapper_class' => 'give-hidden',
419 ),
420
421 array(
422 'name' => __( 'Close Form', 'give' ),
423 'desc' => __( 'Do you want to close the donation forms and stop accepting donations once this goal has been met?', 'give' ),
424 'id' => $prefix . 'close_form_when_goal_achieved',
425 'type' => 'radio_inline',
426 'default' => 'disabled',
427 'options' => array(
428 'enabled' => __( 'Enabled', 'give' ),
429 'disabled' => __( 'Disabled', 'give' ),
430 ),
431 'wrapper_class' => 'give-hidden',
432 ),
433 array(
434 'name' => __( 'Goal Achieved Message', 'give' ),
435 'desc' => __( 'Do you want to display a custom message when the goal is closed?', 'give' ),
436 'id' => $prefix . 'form_goal_achieved_message',
437 'type' => 'wysiwyg',
438 'default' => __( 'Thank you to all our donors, we have met our fundraising goal.', 'give' ),
439 'wrapper_class' => 'give-hidden',
440 ),
441 array(
442 'name' => 'donation_goal_docs',
443 'type' => 'docs_link',
444 'url' => 'http://docs.givewp.com/form-donation-goal',
445 'title' => __( 'Donation Goal', 'give' ),
446 ),
447 ),
448 $post_id
449 ),
450 ) ),
451
452 /**
453 * Content Field
454 */
455 'form_content_options' => apply_filters( 'give_forms_content_options', array(
456 'id' => 'form_content_options',
457 'title' => __( 'Form Content', 'give' ),
458 'icon-html' => '<span class="give-icon give-icon-edit"></span>',
459 'fields' => apply_filters( 'give_forms_content_options_metabox_fields', array(
460
461 // Donation content.
462 array(
463 'name' => __( 'Display Content', 'give' ),
464 'description' => __( 'Do you want to add custom content to this form?', 'give' ),
465 'id' => $prefix . 'display_content',
466 'type' => 'radio_inline',
467 'options' => array(
468 'enabled' => __( 'Enabled', 'give' ),
469 'disabled' => __( 'Disabled', 'give' ),
470 ),
471 'default' => 'disabled',
472 ),
473
474 // Content placement.
475 array(
476 'name' => __( 'Content Placement', 'give' ),
477 'description' => __( 'This option controls where the content appears within the donation form.', 'give' ),
478 'id' => $prefix . 'content_placement',
479 'type' => 'radio_inline',
480 'options' => apply_filters( 'give_forms_content_options_select', array(
481 'give_pre_form' => __( 'Above fields', 'give' ),
482 'give_post_form' => __( 'Below fields', 'give' ),
483 )
484 ),
485 'default' => 'give_pre_form',
486 'wrapper_class' => 'give-hidden',
487 ),
488 array(
489 'name' => __( 'Content', 'give' ),
490 'description' => __( 'This content will display on the single give form page.', 'give' ),
491 'id' => $prefix . 'form_content',
492 'type' => 'wysiwyg',
493 'wrapper_class' => 'give-hidden',
494 ),
495 array(
496 'name' => 'form_content_docs',
497 'type' => 'docs_link',
498 'url' => 'http://docs.givewp.com/form-content',
499 'title' => __( 'Form Content', 'give' ),
500 ),
501 ),
502 $post_id
503 ),
504 ) ),
505
506 /**
507 * Terms & Conditions
508 */
509 'form_terms_options' => apply_filters( 'give_forms_terms_options', array(
510 'id' => 'form_terms_options',
511 'title' => __( 'Terms & Conditions', 'give' ),
512 'icon-html' => '<span class="give-icon give-icon-checklist"></span>',
513 'fields' => apply_filters( 'give_forms_terms_options_metabox_fields', array(
514 // Donation Option
515 array(
516 'name' => __( 'Terms and Conditions', 'give' ),
517 'description' => __( 'Do you want to require the donor to accept terms prior to being able to complete their donation?', 'give' ),
518 'id' => $prefix . 'terms_option',
519 'type' => 'radio_inline',
520 'options' => apply_filters( 'give_forms_content_options_select', array(
521 'global' => __( 'Global Option', 'give' ),
522 'enabled' => __( 'Customize', 'give' ),
523 'disabled' => __( 'Disable', 'give' ),
524 )
525 ),
526 'default' => 'global',
527 ),
528 array(
529 'id' => $prefix . 'agree_label',
530 'name' => __( 'Agreement Label', 'give' ),
531 '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' ),
532 'type' => 'text',
533 'size' => 'regular',
534 'attributes' => array(
535 'placeholder' => __( 'Agree to Terms?', 'give' ),
536 ),
537 'wrapper_class' => 'give-hidden',
538 ),
539 array(
540 'id' => $prefix . 'agree_text',
541 'name' => __( 'Agreement Text', 'give' ),
542 'desc' => __( 'This is the actual text which the user will have to agree to in order to make a donation.', 'give' ),
543 'default' => give_get_option( 'agreement_text' ),
544 'type' => 'wysiwyg',
545 'wrapper_class' => 'give-hidden',
546 ),
547 array(
548 'name' => 'terms_docs',
549 'type' => 'docs_link',
550 'url' => 'http://docs.givewp.com/form-terms',
551 'title' => __( 'Terms and Conditions', 'give' ),
552 ),
553 ),
554 $post_id
555 ),
556 ) ),
557 );
558
559 /**
560 * Filter the metabox tabbed panel settings.
561 */
562 $settings = apply_filters( 'give_metabox_form_data_settings', $settings, $post_id );
563
564 // Output.
565 return $settings;
566 }
567
568 /**
569 * Add metabox.
570 *
571 * @since 1.8
572 *
573 * @return void
574 */
575 public function add_meta_box() {
576 add_meta_box(
577 $this->get_metabox_ID(),
578 $this->get_metabox_label(),
579 array( $this, 'output' ),
580 array( 'give_forms' ),
581 'normal',
582 'high'
583 );
584
585 // Show Goal Metabox only if goal is enabled.
586 if ( give_is_setting_enabled( give_get_meta( give_get_admin_post_id(), '_give_goal_option', true ) ) ) {
587 add_meta_box(
588 'give-form-goal-stats',
589 __( 'Goal Statistics', 'give' ),
590 array( $this, 'output_goal' ),
591 array( 'give_forms' ),
592 'side',
593 'low'
594 );
595 }
596
597 }
598
599
600 /**
601 * Enqueue scripts.
602 *
603 * @since 1.8
604 *
605 * @return void
606 */
607 function enqueue_script() {
608 global $post;
609
610 if ( is_object( $post ) && 'give_forms' === $post->post_type ) {
611
612 }
613 }
614
615 /**
616 * Get metabox id.
617 *
618 * @since 1.8
619 *
620 * @return string
621 */
622 function get_metabox_ID() {
623 return $this->metabox_id;
624 }
625
626 /**
627 * Get metabox label.
628 *
629 * @since 1.8
630 *
631 * @return string
632 */
633 function get_metabox_label() {
634 return $this->metabox_label;
635 }
636
637
638 /**
639 * Get metabox tabs.
640 *
641 * @since 1.8
642 *
643 * @return array
644 */
645 public function get_tabs() {
646 $tabs = array();
647
648 if ( ! empty( $this->settings ) ) {
649 foreach ( $this->settings as $setting ) {
650 if ( ! isset( $setting['id'] ) || ! isset( $setting['title'] ) ) {
651 continue;
652 }
653 $tab = array(
654 'id' => $setting['id'],
655 'label' => $setting['title'],
656 'icon-html' => ( ! empty( $setting['icon-html'] ) ? $setting['icon-html'] : '' ),
657 );
658
659 if ( $this->has_sub_tab( $setting ) ) {
660 if ( empty( $setting['sub-fields'] ) ) {
661 $tab = array();
662 } else {
663 foreach ( $setting['sub-fields'] as $sub_fields ) {
664 $tab['sub-fields'][] = array(
665 'id' => $sub_fields['id'],
666 'label' => $sub_fields['title'],
667 'icon-html' => ( ! empty( $sub_fields['icon-html'] ) ? $sub_fields['icon-html'] : '' ),
668 );
669 }
670 }
671 }
672
673 if ( ! empty( $tab ) ) {
674 $tabs[] = $tab;
675 }
676 }
677 }
678
679 return $tabs;
680 }
681
682 /**
683 * Output metabox settings.
684 *
685 * @since 1.8
686 *
687 * @return void
688 */
689 public function output() {
690 // Bailout.
691 if ( $form_data_tabs = $this->get_tabs() ) :
692 $active_tab = ! empty( $_GET['give_tab'] ) ? give_clean( $_GET['give_tab'] ) : 'form_field_options';
693 wp_nonce_field( 'give_save_form_meta', 'give_form_meta_nonce' );
694 ?>
695 <input id="give_form_active_tab" type="hidden" name="give_form_active_tab">
696 <div class="give-metabox-panel-wrap">
697 <ul class="give-form-data-tabs give-metabox-tabs">
698 <?php foreach ( $form_data_tabs as $index => $form_data_tab ) : ?>
699 <?php
700 // Determine if current tab is active.
701 $is_active = $active_tab === $form_data_tab['id'] ? true : false;
702 ?>
703 <li class="<?php echo "{$form_data_tab['id']}_tab" . ( $is_active ? ' active' : '' ) . ( $this->has_sub_tab( $form_data_tab ) ? ' has-sub-fields' : '' ); ?>">
704 <a href="#<?php echo $form_data_tab['id']; ?>" data-tab-id="<?php echo $form_data_tab['id']; ?>">
705 <?php if ( ! empty( $form_data_tab['icon-html'] ) ) : ?>
706 <?php echo $form_data_tab['icon-html']; ?>
707 <?php else : ?>
708 <span class="give-icon give-icon-default"></span>
709 <?php endif; ?>
710 <span class="give-label"><?php echo $form_data_tab['label']; ?></span>
711 </a>
712 <?php if ( $this->has_sub_tab( $form_data_tab ) ) : ?>
713 <ul class="give-metabox-sub-tabs give-hidden">
714 <?php foreach ( $form_data_tab['sub-fields'] as $sub_tab ) : ?>
715 <li class="<?php echo "{$sub_tab['id']}_tab"; ?>">
716 <a href="#<?php echo $sub_tab['id']; ?>" data-tab-id="<?php echo $sub_tab['id']; ?>">
717 <?php if ( ! empty( $sub_tab['icon-html'] ) ) : ?>
718 <?php echo $sub_tab['icon-html']; ?>
719 <?php else : ?>
720 <span class="give-icon give-icon-default"></span>
721 <?php endif; ?>
722 <span class="give-label"><?php echo $sub_tab['label']; ?></span>
723 </a>
724 </li>
725 <?php endforeach; ?>
726 </ul>
727 <?php endif; ?>
728 </li>
729 <?php endforeach; ?>
730 </ul>
731
732 <?php foreach ( $this->settings as $setting ) : ?>
733 <?php do_action( "give_before_{$setting['id']}_settings" ); ?>
734 <?php
735 // Determine if current panel is active.
736 $is_active = $active_tab === $setting['id'] ? true : false;
737 ?>
738 <div id="<?php echo $setting['id']; ?>" class="panel give_options_panel<?php echo( $is_active ? ' active' : '' ); ?>">
739 <?php if ( ! empty( $setting['fields'] ) ) : ?>
740 <?php foreach ( $setting['fields'] as $field ) : ?>
741 <?php give_render_field( $field ); ?>
742 <?php endforeach; ?>
743 <?php endif; ?>
744 </div>
745 <?php do_action( "give_after_{$setting['id']}_settings" ); ?>
746
747
748 <?php if ( $this->has_sub_tab( $setting ) ) : ?>
749 <?php if ( ! empty( $setting['sub-fields'] ) ) : ?>
750 <?php foreach ( $setting['sub-fields'] as $index => $sub_fields ) : ?>
751 <div id="<?php echo $sub_fields['id']; ?>" class="panel give_options_panel give-hidden">
752 <?php if ( ! empty( $sub_fields['fields'] ) ) : ?>
753 <?php foreach ( $sub_fields['fields'] as $sub_field ) : ?>
754 <?php give_render_field( $sub_field ); ?>
755 <?php endforeach; ?>
756 <?php endif; ?>
757 </div>
758 <?php endforeach; ?>
759 <?php endif; ?>
760 <?php endif; ?>
761 <?php endforeach; ?>
762 </div>
763 <?php
764 endif; // End if().
765 }
766
767 /**
768 * Output Goal meta-box settings.
769 *
770 * @param object $post Post Object.
771 *
772 * @access public
773 * @since 2.1.0
774 *
775 * @return void
776 */
777 public function output_goal( $post ) {
778
779 echo give_admin_form_goal_stats( $post->ID );
780
781 }
782
783 /**
784 * Check if setting field has sub tabs/fields
785 *
786 * @param array $field_setting Field Settings.
787 *
788 * @since 1.8
789 *
790 * @return bool
791 */
792 private function has_sub_tab( $field_setting ) {
793 $has_sub_tab = false;
794 if ( array_key_exists( 'sub-fields', $field_setting ) ) {
795 $has_sub_tab = true;
796 }
797
798 return $has_sub_tab;
799 }
800
801 /**
802 * CMB2 settings loader.
803 *
804 * @since 1.8
805 *
806 * @return array
807 */
808 function cmb2_metabox_settings() {
809 $all_cmb2_settings = apply_filters( 'cmb2_meta_boxes', array() );
810 $give_forms_settings = $all_cmb2_settings;
811
812 // Filter settings: Use only give forms related settings.
813 foreach ( $all_cmb2_settings as $index => $setting ) {
814 if ( ! in_array( 'give_forms', $setting['object_types'] ) ) {
815 unset( $give_forms_settings[ $index ] );
816 }
817 }
818
819 return $give_forms_settings;
820
821 }
822
823 /**
824 * Check if we're saving, the trigger an action based on the post type.
825 *
826 * @param int $post_id Post ID.
827 * @param int|object $post Post Object.
828 *
829 * @since 1.8
830 *
831 * @return void
832 */
833 public function save( $post_id, $post ) {
834
835 // $post_id and $post are required.
836 if ( empty( $post_id ) || empty( $post ) ) {
837 return;
838 }
839
840 // Don't save meta boxes for revisions or autosaves.
841 if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
842 return;
843 }
844
845 // Check the nonce.
846 if ( empty( $_POST['give_form_meta_nonce'] ) || ! wp_verify_nonce( $_POST['give_form_meta_nonce'], 'give_save_form_meta' ) ) {
847 return;
848 }
849
850 // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
851 if ( empty( $_POST['post_ID'] ) || $_POST['post_ID'] != $post_id ) {
852 return;
853 }
854
855 // Check user has permission to edit.
856 if ( ! current_user_can( 'edit_post', $post_id ) ) {
857 return;
858 }
859
860 // Fire action before saving form meta.
861 do_action( 'give_pre_process_give_forms_meta', $post_id, $post );
862
863 /**
864 * Filter the meta key to save.
865 * Third party addon developer can remove there meta keys from this array to handle saving data on there own.
866 */
867 $form_meta_keys = apply_filters( 'give_process_form_meta_keys', $this->get_meta_keys_from_settings() );
868
869 // Save form meta data.
870 if ( ! empty( $form_meta_keys ) ) {
871 foreach ( $form_meta_keys as $form_meta_key ) {
872
873 // Set default value for checkbox fields.
874 if (
875 ! isset( $_POST[ $form_meta_key ] )
876 && ( 'checkbox' === $this->get_field_type( $form_meta_key ) )
877 ) {
878 $_POST[ $form_meta_key ] = '';
879 }
880
881 if ( isset( $_POST[ $form_meta_key ] ) ) {
882 $setting_field = $this->get_setting_field( $form_meta_key );
883 if ( ! empty( $setting_field['type'] ) ) {
884 switch ( $setting_field['type'] ) {
885 case 'textarea':
886 case 'wysiwyg':
887 $form_meta_value = wp_kses_post( $_POST[ $form_meta_key ] );
888 break;
889
890 case 'donation_limit' :
891 $form_meta_value = $_POST[ $form_meta_key ];
892 break;
893
894 case 'group':
895 $form_meta_value = array();
896
897 foreach ( $_POST[ $form_meta_key ] as $index => $group ) {
898
899 // Do not save template input field values.
900 if ( '{{row-count-placeholder}}' === $index ) {
901 continue;
902 }
903
904 $group_meta_value = array();
905 foreach ( $group as $field_id => $field_value ) {
906 switch ( $this->get_field_type( $field_id, $form_meta_key ) ) {
907 case 'wysiwyg':
908 $group_meta_value[ $field_id ] = wp_kses_post( $field_value );
909 break;
910
911 default:
912 $group_meta_value[ $field_id ] = give_clean( $field_value );
913 }
914 }
915
916 if ( ! empty( $group_meta_value ) ) {
917 $form_meta_value[ $index ] = $group_meta_value;
918 }
919 }
920
921 // Arrange repeater field keys in order.
922 $form_meta_value = array_values( $form_meta_value );
923 break;
924
925 default:
926 $form_meta_value = give_clean( $_POST[ $form_meta_key ] );
927 }// End switch().
928
929 /**
930 * Filter the form meta value before saving
931 *
932 * @since 1.8.9
933 */
934 $form_meta_value = apply_filters(
935 'give_pre_save_form_meta_value',
936 $this->sanitize_form_meta( $form_meta_value, $setting_field ),
937 $form_meta_key,
938 $this,
939 $post_id
940 );
941
942 // Range slider.
943 if ( 'donation_limit' === $setting_field['type'] ) {
944
945 // Sanitize amount for db.
946 $form_meta_value = array_map( 'give_sanitize_amount_for_db', $form_meta_value );
947
948 // Store it to form meta.
949 give_update_meta( $post_id, $form_meta_key . '_minimum', $form_meta_value['minimum'] );
950 give_update_meta( $post_id, $form_meta_key . '_maximum', $form_meta_value['maximum'] );
951 } else {
952 // Save data.
953 give_update_meta( $post_id, $form_meta_key, $form_meta_value );
954 }
955
956 // Verify and delete form meta based on the form status.
957 give_set_form_closed_status( $post_id );
958
959 // Fire after saving form meta key.
960 do_action( "give_save_{$form_meta_key}", $form_meta_key, $form_meta_value, $post_id, $post );
961 }// End if().
962 }// End if().
963 }// End foreach().
964 }// End if().
965
966 // Fire action after saving form meta.
967 do_action( 'give_post_process_give_forms_meta', $post_id, $post );
968 }
969
970
971 /**
972 * Get field ID.
973 *
974 * @param array $field Array of Fields.
975 *
976 * @since 1.8
977 *
978 * @return string
979 */
980 private function get_field_id( $field ) {
981 $field_id = '';
982
983 if ( array_key_exists( 'id', $field ) ) {
984 $field_id = $field['id'];
985
986 }
987
988 return $field_id;
989 }
990
991 /**
992 * Get fields ID.
993 *
994 * @param array $setting Array of settings.
995 *
996 * @since 1.8
997 *
998 * @return array
999 */
1000 private function get_fields_id( $setting ) {
1001 $meta_keys = array();
1002
1003 if (
1004 ! empty( $setting )
1005 && array_key_exists( 'fields', $setting )
1006 && ! empty( $setting['fields'] )
1007 ) {
1008 foreach ( $setting['fields'] as $field ) {
1009 if ( $field_id = $this->get_field_id( $field ) ) {
1010 $meta_keys[] = $field_id;
1011 }
1012 }
1013 }
1014
1015 return $meta_keys;
1016 }
1017
1018 /**
1019 * Get sub fields ID.
1020 *
1021 * @param array $setting Array of settings.
1022 *
1023 * @since 1.8
1024 *
1025 * @return array
1026 */
1027 private function get_sub_fields_id( $setting ) {
1028 $meta_keys = array();
1029
1030 if ( $this->has_sub_tab( $setting ) && ! empty( $setting['sub-fields'] ) ) {
1031 foreach ( $setting['sub-fields'] as $fields ) {
1032 if ( ! empty( $fields['fields'] ) ) {
1033 foreach ( $fields['fields'] as $field ) {
1034 if ( $field_id = $this->get_field_id( $field ) ) {
1035 $meta_keys[] = $field_id;
1036 }
1037 }
1038 }
1039 }
1040 }
1041
1042 return $meta_keys;
1043 }
1044
1045
1046 /**
1047 * Get all setting field ids.
1048 *
1049 * @since 1.8
1050 *
1051 * @return array
1052 */
1053 private function get_meta_keys_from_settings() {
1054 $meta_keys = array();
1055
1056 foreach ( $this->settings as $setting ) {
1057 $meta_key = $this->get_fields_id( $setting );
1058
1059 if ( $this->has_sub_tab( $setting ) ) {
1060 $meta_key = array_merge( $meta_key, $this->get_sub_fields_id( $setting ) );
1061 }
1062
1063 $meta_keys = array_merge( $meta_keys, $meta_key );
1064 }
1065
1066 return $meta_keys;
1067 }
1068
1069
1070 /**
1071 * Get field type.
1072 *
1073 * @param string $field_id Field ID.
1074 * @param string $group_id Field Group ID.
1075 *
1076 * @since 1.8
1077 *
1078 * @return string
1079 */
1080 function get_field_type( $field_id, $group_id = '' ) {
1081 $field = $this->get_setting_field( $field_id, $group_id );
1082
1083 $type = array_key_exists( 'type', $field )
1084 ? $field['type']
1085 : '';
1086
1087 return $type;
1088 }
1089
1090
1091 /**
1092 * Get Field
1093 *
1094 * @param array $setting Settings array.
1095 * @param string $field_id Field ID.
1096 *
1097 * @since 1.8
1098 *
1099 * @return array
1100 */
1101 private function get_field( $setting, $field_id ) {
1102 $setting_field = array();
1103
1104 if ( ! empty( $setting['fields'] ) ) {
1105 foreach ( $setting['fields'] as $field ) {
1106 if ( array_key_exists( 'id', $field ) && $field['id'] === $field_id ) {
1107 $setting_field = $field;
1108 break;
1109 }
1110 }
1111 }
1112
1113 return $setting_field;
1114 }
1115
1116 /**
1117 * Get Sub Field
1118 *
1119 * @param array $setting Settings array.
1120 * @param string $field_id Field ID.
1121 *
1122 * @since 1.8
1123 *
1124 * @return array
1125 */
1126 private function get_sub_field( $setting, $field_id ) {
1127 $setting_field = array();
1128
1129 if ( ! empty( $setting['sub-fields'] ) ) {
1130 foreach ( $setting['sub-fields'] as $fields ) {
1131 if ( $field = $this->get_field( $fields, $field_id ) ) {
1132 $setting_field = $field;
1133 break;
1134 }
1135 }
1136 }
1137
1138 return $setting_field;
1139 }
1140
1141 /**
1142 * Get setting field.
1143 *
1144 * @param string $field_id Field ID.
1145 * @param string $group_id Get sub field from group.
1146 *
1147 * @since 1.8
1148 *
1149 * @return array
1150 */
1151 function get_setting_field( $field_id, $group_id = '' ) {
1152 $setting_field = array();
1153
1154 $_field_id = $field_id;
1155 $field_id = empty( $group_id ) ? $field_id : $group_id;
1156
1157 if ( ! empty( $this->settings ) ) {
1158 foreach ( $this->settings as $setting ) {
1159 if (
1160 ( $this->has_sub_tab( $setting ) && ( $setting_field = $this->get_sub_field( $setting, $field_id ) ) )
1161 || ( $setting_field = $this->get_field( $setting, $field_id ) )
1162 ) {
1163 break;
1164 }
1165 }
1166 }
1167
1168 // Get field from group.
1169 if ( ! empty( $group_id ) ) {
1170 foreach ( $setting_field['fields'] as $field ) {
1171 if ( array_key_exists( 'id', $field ) && $field['id'] === $_field_id ) {
1172 $setting_field = $field;
1173 }
1174 }
1175 }
1176
1177 return $setting_field;
1178 }
1179
1180
1181 /**
1182 * Add offline donations setting tab to donation form options metabox.
1183 *
1184 * @param array $settings List of form settings.
1185 *
1186 * @since 1.8
1187 *
1188 * @return mixed
1189 */
1190 function add_offline_donations_setting_tab( $settings ) {
1191 if ( give_is_gateway_active( 'offline' ) ) {
1192 $settings['offline_donations_options'] = apply_filters( 'give_forms_offline_donations_options', array(
1193 'id' => 'offline_donations_options',
1194 'title' => __( 'Offline Donations', 'give' ),
1195 'icon-html' => '<span class="give-icon give-icon-purse"></span>',
1196 'fields' => apply_filters( 'give_forms_offline_donations_metabox_fields', array() ),
1197 ) );
1198 }
1199
1200 return $settings;
1201 }
1202
1203
1204 /**
1205 * Sanitize form meta values before saving.
1206 *
1207 * @param mixed $meta_value Meta Value for sanitizing before saving.
1208 * @param array $setting_field Setting Field.
1209 *
1210 * @since 1.8.9
1211 * @access public
1212 *
1213 * @return mixed
1214 */
1215 function sanitize_form_meta( $meta_value, $setting_field ) {
1216 switch ( $setting_field['type'] ) {
1217 case 'group':
1218 if ( ! empty( $setting_field['fields'] ) ) {
1219 foreach ( $setting_field['fields'] as $field ) {
1220 if ( empty( $field['data_type'] ) || 'price' !== $field['data_type'] ) {
1221 continue;
1222 }
1223
1224 foreach ( $meta_value as $index => $meta_data ) {
1225 if ( ! isset( $meta_value[ $index ][ $field['id'] ] ) ) {
1226 continue;
1227 }
1228
1229 $meta_value[ $index ][ $field['id'] ] = ! empty( $meta_value[ $index ][ $field['id'] ] ) ?
1230 give_sanitize_amount_for_db( $meta_value[ $index ][ $field['id'] ] ) :
1231 ( ( '_give_amount' === $field['id'] && empty( $field_value ) ) ?
1232 give_sanitize_amount_for_db( '1.00' ) :
1233 0 );
1234 }
1235 }
1236 }
1237 break;
1238
1239 default:
1240 if ( ! empty( $setting_field['data_type'] ) && 'price' === $setting_field['data_type'] ) {
1241 $meta_value = $meta_value ?
1242 give_sanitize_amount_for_db( $meta_value ) :
1243 ( in_array( $setting_field['id'], array( '_give_set_price', '_give_custom_amount_minimum', '_give_set_goal' ) ) ?
1244 give_sanitize_amount_for_db( '1.00' ) :
1245 0 );
1246 }
1247 }
1248
1249 return $meta_value;
1250 }
1251
1252 /**
1253 * Maintain the active tab after save.
1254 *
1255 * @param string $location The destination URL.
1256 * @param int $post_id The post ID.
1257 *
1258 * @since 1.8.13
1259 * @access public
1260 *
1261 * @return string The URL after redirect.
1262 */
1263 public function maintain_active_tab( $location, $post_id ) {
1264 if (
1265 'give_forms' === get_post_type( $post_id ) &&
1266 ! empty( $_POST['give_form_active_tab'] )
1267 ) {
1268 $location = add_query_arg( 'give_tab', give_clean( $_POST['give_form_active_tab'] ), $location );
1269 }
1270
1271 return $location;
1272 }
1273 }
1274
1275 new Give_MetaBox_Form_Data();
1276
1277