PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.2
GiveWP – Donation Plugin and Fundraising Platform v2.1.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 / forms / template.php
give / includes / forms Last commit date
functions.php 8 years ago template.php 8 years ago widget.php 8 years ago
template.php
2117 lines
1 <?php
2 /**
3 * Give Form Template
4 *
5 * @package Give
6 * @subpackage Forms
7 * @copyright Copyright (c) 2016, WordImpress
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 /**
18 * Get Donation Form.
19 *
20 * @param array $args An array of form arguments.
21 *
22 * @since 1.0
23 *
24 * @return string Donation form.
25 */
26 function give_get_donation_form( $args = array() ) {
27
28 global $post;
29
30 $form_id = is_object( $post ) ? $post->ID : 0;
31
32 if ( isset( $args['id'] ) ) {
33 $form_id = $args['id'];
34 }
35
36 $defaults = apply_filters( 'give_form_args_defaults', array(
37 'form_id' => $form_id,
38 ) );
39
40 $args = wp_parse_args( $args, $defaults );
41
42 $form = new Give_Donate_Form( $args['form_id'] );
43
44 //bail if no form ID.
45 if ( empty( $form->ID ) ) {
46 return false;
47 }
48
49 $payment_mode = give_get_chosen_gateway( $form->ID );
50
51 $form_action = add_query_arg( apply_filters( 'give_form_action_args', array(
52 'payment-mode' => $payment_mode,
53 ) ),
54 give_get_current_page_url()
55 );
56
57 //Sanity Check: Donation form not published or user doesn't have permission to view drafts.
58 if (
59 ( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) )
60 || ( 'trash' === $form->post_status )
61 ) {
62 return false;
63 }
64
65 //Get the form wrap CSS classes.
66 $form_wrap_classes = $form->get_form_wrap_classes( $args );
67
68 //Get the <form> tag wrap CSS classes.
69 $form_classes = $form->get_form_classes( $args );
70
71 ob_start();
72
73 /**
74 * Fires while outputting donation form, before the form wrapper div.
75 *
76 * @since 1.0
77 *
78 * @param int $form_id The form ID.
79 * @param array $args An array of form arguments.
80 */
81 do_action( 'give_pre_form_output', $form->ID, $args, $form );
82
83 ?>
84 <div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>">
85
86 <?php if ( $form->is_close_donation_form() ) {
87
88 $form_title = ! is_singular( 'give_forms' ) ? apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' ) : '';
89
90 // Get Goal thank you message.
91 $goal_achieved_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true );
92 $goal_achieved_message = ! empty( $goal_achieved_message ) ? $form_title . apply_filters( 'the_content', $goal_achieved_message ) : '';
93
94 // Print thank you message.
95 echo apply_filters( 'give_goal_closed_output', $goal_achieved_message, $form->ID, $form );
96
97 } else {
98 /**
99 * Show form title:
100 * 1. if show_title params set to true
101 * 2. if admin set form display_style to button
102 */
103 $form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form_id ) . '</h2>' );
104 if (
105 (
106 ( isset( $args['show_title'] ) && $args['show_title'] == true )
107 || ( 'button' === get_post_meta( $form_id, '_give_payment_display', true ) )
108 )
109 && ! doing_action( 'give_single_form_summary' )
110 ) {
111 echo $form_title;
112 }
113
114 /**
115 * Fires while outputting donation form, before the form.
116 *
117 * @since 1.0
118 *
119 * @param int $form_id The form ID.
120 * @param array $args An array of form arguments.
121 * @param Give_Donate_Form $form Form object.
122 */
123 do_action( 'give_pre_form', $form->ID, $args, $form );
124
125 // Set form html tags.
126 $form_html_tags = array(
127 'id' => "give-form-{$form_id}",
128 'class' => $form_classes,
129 'action' => esc_url_raw( $form_action ),
130 );
131
132 /**
133 * Filter the form html tags.
134 *
135 * @since 1.8.17
136 *
137 * @param array $form_html_tags Array of form html tags.
138 * @param Give_Donate_Form $form Form object.
139 */
140 $form_html_tags = apply_filters( 'give_form_html_tags', (array) $form_html_tags, $form );
141 ?>
142 <form <?php echo give_get_attribute_str( $form_html_tags ); ?> method="post">
143
144 <!-- The following field is for robots only, invisible to humans: -->
145 <span class="give-hidden" style="display: none !important;">
146 <label for="give-form-honeypot-<?php echo $form_id; ?>"></label>
147 <input id="give-form-honeypot-<?php echo $form_id; ?>" type="text" name="give-honeypot"
148 class="give-honeypot give-hidden"/>
149 </span>
150
151 <?php
152 /**
153 * Fires while outputting donation form, before all other fields.
154 *
155 * @since 1.0
156 *
157 * @param int $form_id The form ID.
158 * @param array $args An array of form arguments.
159 * @param Give_Donate_Form $form Form object.
160 */
161 do_action( 'give_donation_form_top', $form->ID, $args, $form );
162
163 /**
164 * Fires while outputting donation form, for payment gateway fields.
165 *
166 * @since 1.7
167 *
168 * @param int $form_id The form ID.
169 * @param array $args An array of form arguments.
170 * @param Give_Donate_Form $form Form object.
171 */
172 do_action( 'give_payment_mode_select', $form->ID, $args, $form );
173
174 /**
175 * Fires while outputting donation form, after all other fields.
176 *
177 * @since 1.0
178 *
179 * @param int $form_id The form ID.
180 * @param array $args An array of form arguments.
181 * @param Give_Donate_Form $form Form object.
182 */
183 do_action( 'give_donation_form_bottom', $form->ID, $args, $form );
184
185 ?>
186 </form>
187
188 <?php
189 /**
190 * Fires while outputting donation form, after the form.
191 *
192 * @since 1.0
193 *
194 * @param int $form_id The form ID.
195 * @param array $args An array of form arguments.
196 * @param Give_Donate_Form $form Form object.
197 */
198 do_action( 'give_post_form', $form->ID, $args, $form );
199
200 }
201 ?>
202
203 </div><!--end #give-form-<?php echo absint( $form->ID ); ?>-->
204 <?php
205
206 /**
207 * Fires while outputting donation form, after the form wrapper div.
208 *
209 * @since 1.0
210 *
211 * @param int $form_id The form ID.
212 * @param array $args An array of form arguments.
213 */
214 do_action( 'give_post_form_output', $form->ID, $args );
215
216 $final_output = ob_get_clean();
217
218 echo apply_filters( 'give_donate_form', $final_output, $args );
219 }
220
221 /**
222 * Give Show Donation Form.
223 *
224 * Renders the Donation Form, hooks are provided to add to the checkout form.
225 * The default Donation Form rendered displays a list of the enabled payment
226 * gateways, a user registration form (if enable) and a credit card info form
227 * if credit cards are enabled.
228 *
229 * @since 1.0
230 *
231 * @param int $form_id The form ID.
232 *
233 * @return string
234 */
235 function give_show_purchase_form( $form_id ) {
236
237 $payment_mode = give_get_chosen_gateway( $form_id );
238
239 if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) {
240 $form_id = $_POST['give_form_id'];
241 }
242
243 /**
244 * Fire before donation form render.
245 *
246 * @since 1.7
247 */
248 do_action( 'give_payment_fields_top', $form_id );
249
250 if ( give_can_checkout() && isset( $form_id ) ) {
251
252 /**
253 * Fires while displaying donation form, before registration login.
254 *
255 * @since 1.7
256 */
257 do_action( 'give_donation_form_before_register_login', $form_id );
258
259 /**
260 * Fire when register/login form fields render.
261 *
262 * @since 1.7
263 */
264 do_action( 'give_donation_form_register_login_fields', $form_id );
265
266 /**
267 * Fire when credit card form fields render.
268 *
269 * @since 1.7
270 */
271 do_action( 'give_donation_form_before_cc_form', $form_id );
272
273 // Load the credit card form and allow gateways to load their own if they wish.
274 if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) {
275 /**
276 * Fires while displaying donation form, credit card form fields for a given gateway.
277 *
278 * @since 1.0
279 *
280 * @param int $form_id The form ID.
281 */
282 do_action( "give_{$payment_mode}_cc_form", $form_id );
283 } else {
284 /**
285 * Fires while displaying donation form, credit card form fields.
286 *
287 * @since 1.0
288 *
289 * @param int $form_id The form ID.
290 */
291 do_action( 'give_cc_form', $form_id );
292 }
293
294 /**
295 * Fire after credit card form fields render.
296 *
297 * @since 1.7
298 */
299 do_action( 'give_donation_form_after_cc_form', $form_id );
300
301 } else {
302 /**
303 * Fire if user can not donate.
304 *
305 * @since 1.7
306 */
307 do_action( 'give_donation_form_no_access', $form_id );
308
309 }
310
311 /**
312 * Fire after donation form rendered.
313 *
314 * @since 1.7
315 */
316 do_action( 'give_payment_fields_bottom', $form_id );
317 }
318
319 add_action( 'give_donation_form', 'give_show_purchase_form' );
320
321 /**
322 * Give Show Login/Register Form Fields.
323 *
324 * @since 1.4.1
325 *
326 * @param int $form_id The form ID.
327 *
328 * @return void
329 */
330 function give_show_register_login_fields( $form_id ) {
331
332 $show_register_form = give_show_login_register_option( $form_id );
333
334 if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
335 ?>
336 <div id="give-checkout-login-register-<?php echo $form_id; ?>">
337 <?php
338 /**
339 * Fire if user registration form render.
340 *
341 * @since 1.7
342 */
343 do_action( 'give_donation_form_register_fields', $form_id );
344 ?>
345 </div>
346 <?php
347 elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
348 ?>
349 <div id="give-checkout-login-register-<?php echo $form_id; ?>">
350 <?php
351 /**
352 * Fire if user login form render.
353 *
354 * @since 1.7
355 */
356 do_action( 'give_donation_form_login_fields', $form_id );
357 ?>
358 </div>
359 <?php
360 endif;
361
362 if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) {
363 /**
364 * Fire when user info render.
365 *
366 * @since 1.7
367 */
368 do_action( 'give_donation_form_after_user_info', $form_id );
369 }
370 }
371
372 add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
373
374 /**
375 * Donation Amount Field.
376 *
377 * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount
378 * enabled the field will output as a customizable input.
379 *
380 * @since 1.0
381 *
382 * @param int $form_id The form ID.
383 * @param array $args An array of form arguments.
384 *
385 * @return void
386 */
387 function give_output_donation_amount_top( $form_id = 0, $args = array() ) {
388
389 $give_options = give_get_settings();
390 $variable_pricing = give_has_variable_prices( $form_id );
391 $allow_custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
392 $currency_position = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
393 $symbol = give_currency_symbol( give_get_currency( $form_id, $args ) );
394 $currency_output = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
395 $default_amount = give_format_amount( give_get_default_form_amount( $form_id ), array( 'sanitize' => false, 'currency' => give_get_currency( $form_id ) ) );
396 $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true );
397
398 /**
399 * Fires while displaying donation form, before donation level fields.
400 *
401 * @since 1.0
402 *
403 * @param int $form_id The form ID.
404 * @param array $args An array of form arguments.
405 */
406 do_action( 'give_before_donation_levels', $form_id, $args );
407
408 //Set Price, No Custom Amount Allowed means hidden price field
409 if ( ! give_is_setting_enabled( $allow_custom_amount ) ) {
410 ?>
411 <label class="give-hidden" for="give-amount-hidden"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
412 <input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
413 value="<?php echo $default_amount; ?>" required aria-required="true"/>
414 <div class="set-price give-donation-amount form-row-wide">
415 <?php if ( $currency_position == 'before' ) {
416 echo $currency_output;
417 } ?>
418 <span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span>
419 <?php if ( $currency_position == 'after' ) {
420 echo $currency_output;
421 } ?>
422 </div>
423 <?php
424 } else {
425 //Custom Amount Allowed.
426 ?>
427 <div class="give-total-wrap">
428 <div class="give-donation-amount form-row-wide">
429 <?php if ( $currency_position == 'before' ) {
430 echo $currency_output;
431 } ?>
432 <label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
433 <input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel"
434 placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off">
435 <?php if ( $currency_position == 'after' ) {
436 echo $currency_output;
437 } ?>
438 </div>
439 </div>
440 <?php }
441
442 /**
443 * Fires while displaying donation form, after donation amounf field(s).
444 *
445 * @since 1.0
446 *
447 * @param int $form_id The form ID.
448 * @param array $args An array of form arguments.
449 */
450 do_action( 'give_after_donation_amount', $form_id, $args );
451
452 //Custom Amount Text
453 if ( ! $variable_pricing && give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) { ?>
454 <p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p>
455 <?php }
456
457 //Output Variable Pricing Levels.
458 if ( $variable_pricing ) {
459 give_output_levels( $form_id );
460 }
461
462 /**
463 * Fires while displaying donation form, after donation level fields.
464 *
465 * @since 1.0
466 *
467 * @param int $form_id The form ID.
468 * @param array $args An array of form arguments.
469 */
470 do_action( 'give_after_donation_levels', $form_id, $args );
471 }
472
473 add_action( 'give_donation_form_top', 'give_output_donation_amount_top', 10, 2 );
474
475 /**
476 * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons.
477 *
478 * @since 1.0
479 *
480 * @param int $form_id The form ID.
481 *
482 * @return string Donation levels.
483 */
484 function give_output_levels( $form_id ) {
485
486 //Get variable pricing.
487 $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
488 $display_style = give_get_meta( $form_id, '_give_display_style', true );
489 $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
490 $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true );
491
492 if ( empty( $custom_amount_text ) ) {
493 $custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
494 }
495
496 $output = '';
497
498 switch ( $display_style ) {
499 case 'buttons':
500
501 $output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
502
503 foreach ( $prices as $price ) {
504 $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ), $form_id, $price );
505 $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $price['_give_id']['level_id'] . ' ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'give-default-level' : '' ), $form_id, $price );
506
507 $output .= '<li>';
508 $output .= '<button type="button" data-price-id="' . $price['_give_id']['level_id'] . '" class=" ' . $level_classes . '" value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">';
509 $output .= $level_text;
510 $output .= '</button>';
511 $output .= '</li>';
512
513 }
514
515 //Custom Amount.
516 if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
517 $output .= '<li>';
518 $output .= '<button type="button" data-price-id="custom" class="give-donation-level-btn give-btn give-btn-level-custom" value="custom">';
519 $output .= $custom_amount_text;
520 $output .= '</button>';
521 $output .= '</li>';
522 }
523
524 $output .= '</ul>';
525
526 break;
527
528 case 'radios':
529
530 $output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
531
532 foreach ( $prices as $price ) {
533 $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ), $form_id, $price );
534 $level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $price['_give_id']['level_id'] . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price );
535
536 $output .= '<li>';
537 $output .= '<input type="radio" data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" name="give-radio-donation-level" id="give-radio-level-' . $price['_give_id']['level_id'] . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'checked="checked"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">';
538 $output .= '<label for="give-radio-level-' . $price['_give_id']['level_id'] . '">' . $level_text . '</label>';
539 $output .= '</li>';
540
541 }
542
543 //Custom Amount.
544 if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
545 $output .= '<li>';
546 $output .= '<input type="radio" data-price-id="custom" class="give-radio-input give-radio-input-level give-radio-level-custom" name="give-radio-donation-level" id="give-radio-level-custom" value="custom">';
547 $output .= '<label for="give-radio-level-custom">' . $custom_amount_text . '</label>';
548 $output .= '</li>';
549 }
550
551 $output .= '</ul>';
552
553 break;
554
555 case 'dropdown':
556
557 $output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
558 $output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
559
560 //first loop through prices.
561 foreach ( $prices as $price ) {
562 $level_text = apply_filters( 'give_form_level_text', ! empty( $price['_give_text'] ) ? $price['_give_text'] : give_currency_filter( give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) ), $form_id, $price );
563 $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-' . $price['_give_id']['level_id'] . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price );
564
565 $output .= '<option data-price-id="' . $price['_give_id']['level_id'] . '" class="' . $level_classes . '" ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'selected="selected"' : '' ) . ' value="' . give_format_amount( $price['_give_amount'], array( 'sanitize' => false ) ) . '">';
566 $output .= $level_text;
567 $output .= '</option>';
568
569 }
570
571 //Custom Amount.
572 if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
573 $output .= '<option data-price-id="custom" class="give-donation-level-custom" value="custom">' . $custom_amount_text . '</option>';
574 }
575
576 $output .= '</select>';
577
578 break;
579 }
580
581 echo apply_filters( 'give_form_level_output', $output, $form_id );
582 }
583
584 /**
585 * Display Reveal & Lightbox Button.
586 *
587 * Outputs a button to reveal form fields.
588 *
589 * @since 1.0
590 *
591 * @param int $form_id The form ID.
592 * @param array $args An array of form arguments.
593 *
594 * @return string Checkout button.
595 */
596 function give_display_checkout_button( $form_id, $args ) {
597
598 $display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
599 ? $args['display_style']
600 : give_get_meta( $form_id, '_give_payment_display', true );
601
602 if ( 'button' === $display_option ) {
603 $display_option = 'modal';
604 } elseif ( $display_option === 'onpage' ) {
605 return '';
606 }
607
608 $display_label_field = give_get_meta( $form_id, '_give_reveal_label', true );
609 $display_label = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
610
611 $output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
612
613 echo apply_filters( 'give_display_checkout_button', $output );
614 }
615
616 add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
617
618 /**
619 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
620 *
621 * @since 1.0
622 *
623 * @param int $form_id The form ID.
624 *
625 * @see For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
626 *
627 * @return void
628 */
629 function give_user_info_fields( $form_id ) {
630 // Get user info.
631 $give_user_info = _give_get_prefill_form_field_values( $form_id );
632
633 /**
634 * Fire before user personal information fields
635 *
636 * @since 1.7
637 */
638 do_action( 'give_donation_form_before_personal_info', $form_id );
639 ?>
640 <fieldset id="give_checkout_user_info">
641 <legend><?php echo apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ); ?></legend>
642 <p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive">
643 <label class="give-label" for="give-first">
644 <?php _e( 'First Name', 'give' ); ?>
645 <?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
646 <span class="give-required-indicator">*</span>
647 <?php endif ?>
648 <?php echo Give()->tooltips->render_help( __( 'We will use this to personalize your account experience.', 'give' ) ); ?>
649 </label>
650 <input
651 class="give-input required"
652 type="text"
653 name="give_first"
654 placeholder="<?php _e( 'First Name', 'give' ); ?>"
655 id="give-first"
656 value="<?php echo isset( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : ''; ?>"
657 <?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
658 />
659 </p>
660
661 <p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive">
662 <label class="give-label" for="give-last">
663 <?php _e( 'Last Name', 'give' ); ?>
664 <?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
665 <span class="give-required-indicator">*</span>
666 <?php endif ?>
667 <?php echo Give()->tooltips->render_help( __( 'We will use this as well to personalize your account experience.', 'give' ) ); ?>
668 </label>
669
670 <input
671 class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>"
672 type="text"
673 name="give_last"
674 id="give-last"
675 placeholder="<?php _e( 'Last Name', 'give' ); ?>"
676 value="<?php echo isset( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : ''; ?>"
677 <?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
678 />
679 </p>
680
681 <?php if ( give_is_company_field_enabled( $form_id ) ) : ?>
682 <?php $give_company = give_field_is_required( 'give_company_name', $form_id ); ?>
683 <p id="give-company-wrap" class="form-row form-row-wide">
684 <label class="give-label" for="give-company">
685 <?php _e( 'Company Name', 'give' ); ?>
686 <?php if ( $give_company ) : ?>
687 <span class="give-required-indicator">*</span>
688 <?php endif; ?>
689 <?php echo Give()->tooltips->render_help( __( 'Donate on behalf of Company', 'give' ) ); ?>
690 </label>
691
692 <input
693 class="give-input<?php echo( $give_company ? ' required' : '' ); ?>"
694 type="text"
695 name="give_company_name"
696 placeholder="<?php _e( 'Company Name', 'give' ); ?>"
697 id="give-company"
698 value="<?php echo isset( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : ''; ?>"
699 <?php echo( $give_company ? ' required aria-required="true" ' : '' ); ?>
700 />
701
702 </p>
703 <?php endif ?>
704
705 <?php
706 /**
707 * Fire before user email field
708 *
709 * @since 1.7
710 */
711 do_action( 'give_donation_form_before_email', $form_id );
712 ?>
713 <p id="give-email-wrap" class="form-row form-row-wide">
714 <label class="give-label" for="give-email">
715 <?php _e( 'Email Address', 'give' ); ?>
716 <?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
717 <span class="give-required-indicator">*</span>
718 <?php } ?>
719 <?php echo Give()->tooltips->render_help( __( 'We will send the donation receipt to this address.', 'give' ) ); ?>
720 </label>
721
722 <input
723 class="give-input required"
724 type="email"
725 name="give_email"
726 placeholder="<?php _e( 'Email Address', 'give' ); ?>"
727 id="give-email"
728 value="<?php echo isset( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : ''; ?>"
729 <?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
730 />
731
732 </p>
733 <?php
734 /**
735 * Fire after user email field
736 *
737 * @since 1.7
738 */
739 do_action( 'give_donation_form_after_email', $form_id );
740
741 /**
742 * Fire after personal email field
743 *
744 * @since 1.7
745 */
746 do_action( 'give_donation_form_user_info', $form_id );
747 ?>
748 </fieldset>
749 <?php
750 /**
751 * Fire after user personal information fields
752 *
753 * @since 1.7
754 */
755 do_action( 'give_donation_form_after_personal_info', $form_id );
756 }
757
758 add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
759 add_action( 'give_register_fields_before', 'give_user_info_fields' );
760
761 /**
762 * Renders the credit card info form.
763 *
764 * @since 1.0
765 *
766 * @param int $form_id The form ID.
767 *
768 * @return void
769 */
770 function give_get_cc_form( $form_id ) {
771
772 ob_start();
773
774 /**
775 * Fires while rendering credit card info form, before the fields.
776 *
777 * @since 1.0
778 *
779 * @param int $form_id The form ID.
780 */
781 do_action( 'give_before_cc_fields', $form_id );
782 ?>
783 <fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate">
784 <legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
785 <?php if ( is_ssl() ) : ?>
786 <div id="give_secure_site_wrapper-<?php echo $form_id ?>">
787 <span class="give-icon padlock"></span>
788 <span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
789 </div>
790 <?php endif; ?>
791 <p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive">
792 <label for="card_number-<?php echo $form_id ?>" class="give-label">
793 <?php _e( 'Card Number', 'give' ); ?>
794 <span class="give-required-indicator">*</span>
795 <?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?>
796 <span class="card-type"></span>
797 </label>
798
799 <input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>"
800 class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>"
801 required aria-required="true"/>
802 </p>
803
804 <p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third form-row-responsive">
805 <label for="card_cvc-<?php echo $form_id ?>" class="give-label">
806 <?php _e( 'CVC', 'give' ); ?>
807 <span class="give-required-indicator">*</span>
808 <?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?>
809 </label>
810
811 <input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>"
812 class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>"
813 required aria-required="true"/>
814 </p>
815
816 <p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive">
817 <label for="card_name-<?php echo $form_id ?>" class="give-label">
818 <?php _e( 'Name on the Card', 'give' ); ?>
819 <span class="give-required-indicator">*</span>
820 <?php echo Give()->tooltips->render_help( __( 'The name printed on the front of your credit card.', 'give' ) ); ?>
821 </label>
822
823 <input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>"
824 class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>"
825 required aria-required="true"/>
826 </p>
827 <?php
828 /**
829 * Fires while rendering credit card info form, before expiration fields.
830 *
831 * @since 1.0
832 *
833 * @param int $form_id The form ID.
834 */
835 do_action( 'give_before_cc_expiration' );
836 ?>
837 <p class="card-expiration form-row form-row-one-third form-row-responsive">
838 <label for="card_expiry-<?php echo $form_id ?>" class="give-label">
839 <?php _e( 'Expiration', 'give' ); ?>
840 <span class="give-required-indicator">*</span>
841 <?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?>
842 </label>
843
844 <input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month" class="card-expiry-month"/>
845 <input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year" class="card-expiry-year"/>
846
847 <input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id ?>" class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>" required aria-required="true"/>
848 </p>
849 <?php
850 /**
851 * Fires while rendering credit card info form, after expiration fields.
852 *
853 * @since 1.0
854 *
855 * @param int $form_id The form ID.
856 */
857 do_action( 'give_after_cc_expiration', $form_id );
858 ?>
859 </fieldset>
860 <?php
861 /**
862 * Fires while rendering credit card info form, before the fields.
863 *
864 * @since 1.0
865 *
866 * @param int $form_id The form ID.
867 */
868 do_action( 'give_after_cc_fields', $form_id );
869
870 echo ob_get_clean();
871 }
872
873 add_action( 'give_cc_form', 'give_get_cc_form' );
874
875 /**
876 * Outputs the default credit card address fields.
877 *
878 * @since 1.0
879 *
880 * @param int $form_id The form ID.
881 *
882 * @return void
883 */
884 function give_default_cc_address_fields( $form_id ) {
885 // Get user info.
886 $give_user_info = _give_get_prefill_form_field_values( $form_id );
887
888 $logged_in = is_user_logged_in();
889
890 if ( $logged_in ) {
891 $user_address = give_get_donor_address( get_current_user_id() );
892 }
893
894 ob_start();
895 ?>
896 <fieldset id="give_cc_address" class="cc-address">
897 <legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
898 <?php
899 /**
900 * Fires while rendering credit card billing form, before address fields.
901 *
902 * @since 1.0
903 *
904 * @param int $form_id The form ID.
905 */
906 do_action( 'give_cc_billing_top' );
907
908 // For Country.
909 $selected_country = give_get_country();
910 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
911 $selected_country = $give_user_info['billing_country'];
912 }
913 $countries = give_get_country_list();
914
915 // For state
916 $selected_state = '';
917 if ( $selected_country === give_get_country() ) {
918 // Get defalut selected state by admin.
919 $selected_state = give_get_state();
920 }
921 // Get the last payment made by user states.
922 if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
923 $selected_state = $give_user_info['card_state'];
924 }
925 // Get the country code
926 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
927 $selected_country = $give_user_info['billing_country'];
928 }
929 $label = __( 'State', 'give' );
930 $states_label = give_get_states_label();
931 // Check if $country code exists in the array key for states label.
932 if ( array_key_exists( $selected_country, $states_label ) ) {
933 $label = $states_label[ $selected_country ];
934 }
935 $states = give_get_states( $selected_country );
936 // Get the country list that do not have any states init.
937 $no_states_country = give_no_states_country_list();
938 // Get the country list that does not require states.
939 $states_not_required_country_list = give_states_not_required_country_list();
940 ?>
941 <p id="give-card-country-wrap" class="form-row form-row-wide">
942 <label for="billing_country" class="give-label">
943 <?php esc_html_e( 'Country', 'give' ); ?>
944 <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
945 <span class="give-required-indicator">*</span>
946 <?php endif; ?>
947 <span class="give-tooltip give-icon give-icon-question"
948 data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
949 </label>
950
951 <select
952 name="billing_country"
953 id="billing_country"
954 class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
955 <?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
956 >
957 <?php
958 foreach ( $countries as $country_code => $country ) {
959 echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
960 }
961 ?>
962 </select>
963 </p>
964
965 <p id="give-card-address-wrap" class="form-row form-row-wide">
966 <label for="card_address" class="give-label">
967 <?php _e( 'Address 1', 'give' ); ?>
968 <?php
969 if ( give_field_is_required( 'card_address', $form_id ) ) : ?>
970 <span class="give-required-indicator">*</span>
971 <?php endif; ?>
972 <?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?>
973 </label>
974
975 <input
976 type="text"
977 id="card_address"
978 name="card_address"
979 class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
980 placeholder="<?php _e( 'Address line 1', 'give' ); ?>"
981 value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
982 <?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
983 />
984 </p>
985
986 <p id="give-card-address-2-wrap" class="form-row form-row-wide">
987 <label for="card_address_2" class="give-label">
988 <?php _e( 'Address 2', 'give' ); ?>
989 <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
990 <span class="give-required-indicator">*</span>
991 <?php endif; ?>
992 <?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?>
993 </label>
994
995 <input
996 type="text"
997 id="card_address_2"
998 name="card_address_2"
999 class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
1000 placeholder="<?php _e( 'Address line 2', 'give' ); ?>"
1001 value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
1002 <?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1003 />
1004 </p>
1005
1006 <p id="give-card-city-wrap" class="form-row form-row-wide">
1007 <label for="card_city" class="give-label">
1008 <?php _e( 'City', 'give' ); ?>
1009 <?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
1010 <span class="give-required-indicator">*</span>
1011 <?php endif; ?>
1012 <?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?>
1013 </label>
1014 <input
1015 type="text"
1016 id="card_city"
1017 name="card_city"
1018 class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
1019 placeholder="<?php _e( 'City', 'give' ); ?>"
1020 value="<?php echo isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : ''; ?>"
1021 <?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1022 />
1023 </p>
1024
1025 <p id="give-card-state-wrap"
1026 class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ) ? 'give-hidden' : ''; ?> ">
1027 <label for="card_state" class="give-label">
1028 <span class="state-label-text"><?php echo $label; ?></span>
1029 <?php if ( give_field_is_required( 'card_state', $form_id ) ) :
1030 ?>
1031 <span class="give-required-indicator <?php echo( array_key_exists( $selected_country, $states_not_required_country_list ) ? 'give-hidden' : '' ) ?> ">*</span>
1032 <?php endif; ?>
1033 <span class="give-tooltip give-icon give-icon-question"
1034 data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1035 </label>
1036 <?php
1037
1038 if ( ! empty( $states ) ) : ?>
1039 <select
1040 name="card_state"
1041 id="card_state"
1042 class="card_state give-select<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required' : '' ); ?>"
1043 <?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required aria-required="true" ' : '' ); ?>>
1044 <?php
1045 foreach ( $states as $state_code => $state ) {
1046 echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
1047 }
1048 ?>
1049 </select>
1050 <?php else : ?>
1051 <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1052 placeholder="<?php echo $label; ?>" value="<?php echo $selected_state; ?>"/>
1053 <?php endif; ?>
1054 </p>
1055
1056 <p id="give-card-zip-wrap" class="form-row form-row-last form-row-responsive">
1057 <label for="card_zip" class="give-label">
1058 <?php _e( 'Zip / Postal Code', 'give' ); ?>
1059 <?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
1060 <span class="give-required-indicator">*</span>
1061 <?php endif; ?>
1062 <?php echo Give()->tooltips->render_help( __( 'The ZIP Code or postal code for your billing address.', 'give' ) ); ?>
1063 </label>
1064
1065 <input
1066 type="text"
1067 size="4"
1068 id="card_zip"
1069 name="card_zip"
1070 class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>"
1071 placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>"
1072 value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
1073 <?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1074 />
1075 </p>
1076 <?php
1077 /**
1078 * Fires while rendering credit card billing form, after address fields.
1079 *
1080 * @since 1.0
1081 *
1082 * @param int $form_id The form ID.
1083 */
1084 do_action( 'give_cc_billing_bottom' );
1085 ?>
1086 </fieldset>
1087 <?php
1088 echo ob_get_clean();
1089 }
1090
1091 add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1092
1093
1094 /**
1095 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1096 * is provided for the user to create an account.
1097 *
1098 * @since 1.0
1099 *
1100 * @param int $form_id The form ID.
1101 *
1102 * @return string
1103 */
1104 function give_get_register_fields( $form_id ) {
1105
1106 global $user_ID;
1107
1108 if ( is_user_logged_in() ) {
1109 $user_data = get_userdata( $user_ID );
1110 }
1111
1112 $show_register_form = give_show_login_register_option( $form_id );
1113
1114 ob_start(); ?>
1115 <fieldset id="give-register-fields-<?php echo $form_id; ?>">
1116
1117 <?php
1118 /**
1119 * Fires while rendering user registration form, before registration fields.
1120 *
1121 * @since 1.0
1122 *
1123 * @param int $form_id The form ID.
1124 */
1125 do_action( 'give_register_fields_before', $form_id );
1126 ?>
1127
1128 <fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
1129 <?php
1130 /**
1131 * Fires while rendering user registration form, before account fields.
1132 *
1133 * @since 1.0
1134 *
1135 * @param int $form_id The form ID.
1136 */
1137 do_action( 'give_register_account_fields_before', $form_id );
1138 ?>
1139 <div id="give-create-account-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive">
1140 <label for="give-create-account-<?php echo $form_id; ?>">
1141 <?php
1142 // Add attributes to checkbox, if Guest Checkout is disabled.
1143 $is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true );
1144 $id = 'give-create-account-' . $form_id;
1145 if ( ! give_is_setting_enabled( $is_guest_checkout ) ) {
1146 echo Give()->tooltips->render(
1147 array(
1148 'tag_content' => sprintf(
1149 '<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />',
1150 $id
1151 ),
1152 'label' => __( 'Registration is required to donate.', 'give' ),
1153 ) );
1154 } else {
1155 ?>
1156 <input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>" class="give-input" />
1157 <?php
1158 }
1159 ?>
1160 <?php _e( 'Create an account', 'give' ); ?>
1161 <?php echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) ); ?>
1162 </label>
1163 </div>
1164
1165 <?php if ( 'both' === $show_register_form ) { ?>
1166 <div class="give-login-account-wrap form-row form-row-last form-row-responsive">
1167 <p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1168 <a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1169 data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1170 </p>
1171 <p class="give-loading-text">
1172 <span class="give-loading-animation"></span>
1173 </p>
1174 </div>
1175 <?php } ?>
1176
1177 <?php
1178 /**
1179 * Fires while rendering user registration form, after account fields.
1180 *
1181 * @since 1.0
1182 *
1183 * @param int $form_id The form ID.
1184 */
1185 do_action( 'give_register_account_fields_after', $form_id );
1186 ?>
1187 </fieldset>
1188
1189 <?php
1190 /**
1191 * Fires while rendering user registration form, after registration fields.
1192 *
1193 * @since 1.0
1194 *
1195 * @param int $form_id The form ID.
1196 */
1197 do_action( 'give_register_fields_after', $form_id );
1198 ?>
1199
1200 <input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1201
1202 <?php
1203 /**
1204 * Fire after register or login form render
1205 *
1206 * @since 1.7
1207 */
1208 do_action( 'give_donation_form_user_info', $form_id );
1209 ?>
1210
1211 </fieldset>
1212 <?php
1213 echo ob_get_clean();
1214 }
1215
1216 add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1217
1218 /**
1219 * Gets the login fields for the login form on the checkout. This function hooks
1220 * on the give_donation_form_login_fields to display the login form if a user already
1221 * had an account.
1222 *
1223 * @since 1.0
1224 *
1225 * @param int $form_id The form ID.
1226 *
1227 * @return string
1228 */
1229 function give_get_login_fields( $form_id ) {
1230
1231 $form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
1232 $show_register_form = give_show_login_register_option( $form_id );
1233
1234 ob_start();
1235 ?>
1236 <fieldset id="give-login-fields-<?php echo $form_id; ?>">
1237 <legend><?php echo apply_filters( 'give_account_login_fieldset_heading', __( 'Login to Your Account', 'give' ) );
1238 if ( ! give_logged_in_only( $form_id ) ) {
1239 echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>';
1240 } ?>
1241 </legend>
1242 <?php if ( $show_register_form == 'both' ) { ?>
1243 <p class="give-new-account-link">
1244 <?php _e( 'Don\'t have an account?', 'give' ); ?>&nbsp;
1245 <a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel"
1246 data-action="give_checkout_register">
1247 <?php if ( give_logged_in_only( $form_id ) ) {
1248 _e( 'Register as a part of your donation &raquo;', 'give' );
1249 } else {
1250 _e( 'Register or donate as a guest &raquo;', 'give' );
1251 } ?>
1252 </a>
1253 </p>
1254 <p class="give-loading-text">
1255 <span class="give-loading-animation"></span>
1256 </p>
1257 <?php } ?>
1258 <?php
1259 /**
1260 * Fires while rendering checkout login form, before the fields.
1261 *
1262 * @since 1.0
1263 *
1264 * @param int $form_id The form ID.
1265 */
1266 do_action( 'give_checkout_login_fields_before', $form_id );
1267 ?>
1268 <div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive">
1269 <label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
1270 <?php _e( 'Username', 'give' ); ?>
1271 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1272 <span class="give-required-indicator">*</span>
1273 <?php } ?>
1274 </label>
1275
1276 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" type="text"
1277 name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value=""
1278 placeholder="<?php _e( 'Your username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1279 </div>
1280
1281 <div id="give-user-pass-wrap-<?php echo $form_id; ?>"
1282 class="give_login_password form-row form-row-last form-row-responsive">
1283 <label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
1284 <?php _e( 'Password', 'give' ); ?>
1285 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1286 <span class="give-required-indicator">*</span>
1287 <?php } ?>
1288 </label>
1289 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1290 type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>"
1291 placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1292 <input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1293 </div>
1294
1295 <div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
1296 <span class="give-forgot-password ">
1297 <a href="<?php echo wp_lostpassword_url() ?>"
1298 target="_blank"><?php _e( 'Reset Password', 'give' ) ?></a>
1299 </span>
1300 </div>
1301
1302 <div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
1303 <input type="submit" class="give-submit give-btn button" name="give_login_submit"
1304 value="<?php _e( 'Login', 'give' ); ?>"/>
1305 <?php if ( $show_register_form !== 'login' ) { ?>
1306 <input type="button" data-action="give_cancel_login"
1307 class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1308 value="<?php _e( 'Cancel', 'give' ); ?>"/>
1309 <?php } ?>
1310 <span class="give-loading-animation"></span>
1311 </div>
1312 <?php
1313 /**
1314 * Fires while rendering checkout login form, after the fields.
1315 *
1316 * @since 1.0
1317 *
1318 * @param int $form_id The form ID.
1319 */
1320 do_action( 'give_checkout_login_fields_after', $form_id );
1321 ?>
1322 </fieldset><!--end #give-login-fields-->
1323 <?php
1324 echo ob_get_clean();
1325 }
1326
1327 add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1328
1329 /**
1330 * Payment Mode Select.
1331 *
1332 * Renders the payment mode form by getting all the enabled payment gateways and
1333 * outputting them as radio buttons for the user to choose the payment gateway. If
1334 * a default payment gateway has been chosen from the Give Settings, it will be
1335 * automatically selected.
1336 *
1337 * @since 1.0
1338 *
1339 * @param int $form_id The form ID.
1340 *
1341 * @return void
1342 */
1343 function give_payment_mode_select( $form_id ) {
1344
1345 $gateways = give_get_enabled_payment_gateways( $form_id );
1346
1347 /**
1348 * Fires while selecting payment gateways, before the fields.
1349 *
1350 * @since 1.7
1351 *
1352 * @param int $form_id The form ID.
1353 */
1354 do_action( 'give_payment_mode_top', $form_id );
1355 ?>
1356
1357 <fieldset id="give-payment-mode-select" <?php if ( count( $gateways ) <= 1 ) {
1358 echo 'style="display: none;"';
1359 } ?>>
1360 <?php
1361 /**
1362 * Fires while selecting payment gateways, before the wrap div.
1363 *
1364 * @since 1.7
1365 *
1366 * @param int $form_id The form ID.
1367 */
1368 do_action( 'give_payment_mode_before_gateways_wrap' );
1369 ?>
1370 <legend
1371 class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
1372 <span class="give-loading-text"><span
1373 class="give-loading-animation"></span>
1374 </span>
1375 </legend>
1376
1377 <div id="give-payment-mode-wrap">
1378 <?php
1379 /**
1380 * Fires while selecting payment gateways, befire the gateways list.
1381 *
1382 * @since 1.7
1383 */
1384 do_action( 'give_payment_mode_before_gateways' )
1385 ?>
1386 <ul id="give-gateway-radio-list">
1387 <?php
1388 /**
1389 * Loop through the active payment gateways.
1390 */
1391 $selected_gateway = give_get_chosen_gateway( $form_id );
1392 $give_settings = give_get_settings();
1393 $gateways_label = array_key_exists( 'gateways_label', $give_settings ) ?
1394 $give_settings['gateways_label'] :
1395 array();
1396
1397 foreach ( $gateways as $gateway_id => $gateway ) :
1398 //Determine the default gateway.
1399 $checked = checked( $gateway_id, $selected_gateway, false );
1400 $checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; ?>
1401 <li<?php echo $checked_class ?>>
1402 <input type="radio" name="payment-mode" class="give-gateway"
1403 id="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>"
1404 value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
1405
1406 <?php
1407 $label = $gateway['checkout_label'];
1408 if ( ! empty( $gateways_label[ $gateway_id ] ) ) {
1409 $label = $gateways_label[ $gateway_id ];
1410 }
1411 ?>
1412 <label for="give-gateway-<?php echo esc_attr( $gateway_id ) . '-' . $form_id; ?>"
1413 class="give-gateway-option"
1414 id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $label ); ?></label>
1415 </li>
1416 <?php
1417 endforeach;
1418 ?>
1419 </ul>
1420 <?php
1421 /**
1422 * Fires while selecting payment gateways, before the gateways list.
1423 *
1424 * @since 1.7
1425 */
1426 do_action( 'give_payment_mode_after_gateways' );
1427 ?>
1428 </div>
1429 <?php
1430 /**
1431 * Fires while selecting payment gateways, after the wrap div.
1432 *
1433 * @since 1.7
1434 *
1435 * @param int $form_id The form ID.
1436 */
1437 do_action( 'give_payment_mode_after_gateways_wrap' );
1438 ?>
1439 </fieldset>
1440
1441 <?php
1442 /**
1443 * Fires while selecting payment gateways, after the fields.
1444 *
1445 * @since 1.7
1446 *
1447 * @param int $form_id The form ID.
1448 */
1449 do_action( 'give_payment_mode_bottom', $form_id );
1450 ?>
1451
1452 <div id="give_purchase_form_wrap">
1453
1454 <?php
1455 /**
1456 * Fire after payment field render.
1457 *
1458 * @since 1.7
1459 */
1460 do_action( 'give_donation_form', $form_id );
1461 ?>
1462
1463 </div>
1464
1465 <?php
1466 /**
1467 * Fire after donation form render.
1468 *
1469 * @since 1.7
1470 */
1471 do_action( 'give_donation_form_wrap_bottom', $form_id );
1472 }
1473
1474 add_action( 'give_payment_mode_select', 'give_payment_mode_select' );
1475
1476 /**
1477 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1478 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1479 * set in the Give Settings.
1480 *
1481 * @since 1.0
1482 *
1483 * @param int $form_id The form ID.
1484 *
1485 * @return bool
1486 */
1487 function give_terms_agreement( $form_id ) {
1488 $form_option = give_get_meta( $form_id, '_give_terms_option', true );
1489
1490 // Bailout if per form and global term and conditions is not setup.
1491 if (
1492 give_is_setting_enabled( $form_option, 'global' )
1493 && give_is_setting_enabled( give_get_option( 'terms' ) )
1494 ) {
1495 $label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1496 $terms = $terms = give_get_option( 'agreement_text', '' );
1497 $edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1498
1499 } elseif ( give_is_setting_enabled( $form_option ) ) {
1500 $label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1501 $terms = give_get_meta( $form_id, '_give_agree_text', true );
1502 $edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1503
1504 } else {
1505 return false;
1506 }
1507
1508 // Bailout: Check if term and conditions text is empty or not.
1509 if ( empty( $terms ) ) {
1510 if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1511 echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
1512 }
1513
1514 return false;
1515 }
1516
1517 ?>
1518 <fieldset id="give_terms_agreement">
1519 <legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
1520 <div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
1521 <?php
1522 /**
1523 * Fires while rendering terms of agreement, before the fields.
1524 *
1525 * @since 1.0
1526 */
1527 do_action( 'give_before_terms' );
1528
1529 echo wpautop( stripslashes( $terms ) );
1530 /**
1531 * Fires while rendering terms of agreement, after the fields.
1532 *
1533 * @since 1.0
1534 */
1535 do_action( 'give_after_terms' );
1536 ?>
1537 </div>
1538 <div id="give_show_terms">
1539 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1540 aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1541 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1542 aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1543 </div>
1544
1545 <input name="give_agree_to_terms" class="required" type="checkbox"
1546 id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
1547 <label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
1548
1549 </fieldset>
1550 <?php
1551 }
1552
1553 add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1554
1555 /**
1556 * Checkout Final Total.
1557 *
1558 * Shows the final donation total at the bottom of the checkout page.
1559 *
1560 * @since 1.0
1561 *
1562 * @param int $form_id The form ID.
1563 *
1564 * @return void
1565 */
1566 function give_checkout_final_total( $form_id ) {
1567
1568 $total = isset( $_POST['give_total'] ) ?
1569 apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) :
1570 give_get_default_form_amount( $form_id );
1571
1572
1573 // Only proceed if give_total available.
1574 if ( empty( $total ) ) {
1575 return;
1576 }
1577 ?>
1578 <p id="give-final-total-wrap" class="form-wrap ">
1579 <?php
1580 /**
1581 * Fires before the donation total label
1582 *
1583 * @since 2.0.5
1584 */
1585 do_action( 'give_donation_final_total_label_before', $form_id );
1586 ?>
1587 <span class="give-donation-total-label">
1588 <?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?>
1589 </span>
1590 <span class="give-final-total-amount"
1591 data-total="<?php echo give_format_amount( $total, array( 'sanitize' => false ) ); ?>">
1592 <?php echo give_currency_filter( give_format_amount( $total, array( 'sanitize' => false ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ); ?>
1593 </span>
1594 <?php
1595 /**
1596 * Fires after the donation final total label
1597 *
1598 * @since 2.0.5
1599 */
1600 do_action( 'give_donation_final_total_label_after', $form_id );
1601 ?>
1602 </p>
1603 <?php
1604 }
1605
1606 add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1607
1608 /**
1609 * Renders the Checkout Submit section.
1610 *
1611 * @since 1.0
1612 *
1613 * @param int $form_id The form ID.
1614 *
1615 * @return void
1616 */
1617 function give_checkout_submit( $form_id ) {
1618 ?>
1619 <fieldset id="give_purchase_submit" class="give-donation-submit">
1620 <?php
1621 /**
1622 * Fire before donation form submit.
1623 *
1624 * @since 1.7
1625 */
1626 do_action( 'give_donation_form_before_submit', $form_id );
1627
1628 give_checkout_hidden_fields( $form_id );
1629
1630 echo give_get_donation_form_submit_button( $form_id );
1631
1632 /**
1633 * Fire after donation form submit.
1634 *
1635 * @since 1.7
1636 */
1637 do_action( 'give_donation_form_after_submit', $form_id );
1638 ?>
1639 </fieldset>
1640 <?php
1641 }
1642
1643 add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999 );
1644
1645 /**
1646 * Give Donation form submit button.
1647 *
1648 * @since 1.8.8
1649 *
1650 * @param int $form_id The form ID.
1651 *
1652 * @return string
1653 */
1654 function give_get_donation_form_submit_button( $form_id ) {
1655
1656 $display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
1657 $display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1658 ob_start();
1659 ?>
1660 <div class="give-submit-button-wrap give-clearfix">
1661 <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1662 value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>" />
1663 <span class="give-loading-animation"></span>
1664 </div>
1665 <?php
1666 return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id );
1667 }
1668
1669 /**
1670 * Show Give Goals.
1671 *
1672 * @since 1.0
1673 * @since 1.6 Add template for Give Goals Shortcode.
1674 * More info is on https://github.com/WordImpress/Give/issues/411
1675 *
1676 * @param int $form_id The form ID.
1677 * @param array $args An array of form arguments.
1678 *
1679 * @return mixed
1680 */
1681 function give_show_goal_progress( $form_id, $args = array() ) {
1682
1683 ob_start();
1684 give_get_template( 'shortcode-goal', array( 'form_id' => $form_id, 'args' => $args ) );
1685
1686 /**
1687 * Filter progress bar output
1688 *
1689 * @since 2.0
1690 */
1691 echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args );
1692
1693 return true;
1694 }
1695
1696 add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1697
1698 /**
1699 * Show Give Totals Progress.
1700 *
1701 * @since 2.1
1702 *
1703 * @param int $total Total amount based on shortcode parameter.
1704 * @param int $total_goal Total Goal amount passed by Admin.
1705 *
1706 * @return mixed
1707 */
1708 function give_show_goal_totals_progress( $total, $total_goal ) {
1709
1710 // Bail out if total goal is set as an array.
1711 if ( isset( $total_goal ) && is_array( $total_goal ) ) {
1712 return false;
1713 }
1714
1715 ob_start();
1716 give_get_template( 'shortcode-totals-progress', array( 'total' => $total, 'total_goal' => $total_goal ) );
1717
1718 echo apply_filters( 'give_total_progress_output', ob_get_clean() );
1719
1720 return true;
1721 }
1722
1723 add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
1724
1725 /**
1726 * Get form content position.
1727 *
1728 * @since 1.8
1729 *
1730 * @param $form_id
1731 * @param $args
1732 *
1733 * @return mixed|string
1734 */
1735 function give_get_form_content_placement( $form_id, $args ) {
1736 $show_content = '';
1737
1738 if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1739 // Content positions.
1740 $content_placement = array(
1741 'above' => 'give_pre_form',
1742 'below' => 'give_post_form',
1743 );
1744
1745 // Check if content position already decoded.
1746 if ( in_array( $args['show_content'], $content_placement ) ) {
1747 return $args['show_content'];
1748 }
1749
1750 $show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1751
1752 } elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
1753 $show_content = give_get_meta( $form_id, '_give_content_placement', true );
1754
1755 } elseif ( 'none' !== give_get_meta( $form_id, '_give_content_option', true ) ) {
1756 // Backward compatibility for _give_content_option for v18.
1757 $show_content = give_get_meta( $form_id, '_give_content_option', true );
1758 }
1759
1760 return $show_content;
1761 }
1762
1763 /**
1764 * Adds Actions to Render Form Content.
1765 *
1766 * @since 1.0
1767 *
1768 * @param int $form_id The form ID.
1769 * @param array $args An array of form arguments.
1770 *
1771 * @return void|bool
1772 */
1773 function give_form_content( $form_id, $args ) {
1774
1775 $show_content = give_get_form_content_placement( $form_id, $args );
1776
1777 // Bailout.
1778 if ( empty( $show_content ) ) {
1779 return false;
1780 }
1781
1782 // Add action according to value.
1783 add_action( $show_content, 'give_form_display_content', 10, 2 );
1784 }
1785
1786 add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
1787
1788 /**
1789 * Renders Post Form Content.
1790 *
1791 * Displays content for Give forms; fired by action from give_form_content.
1792 *
1793 * @since 1.0
1794 *
1795 * @param int $form_id The form ID.
1796 * @param array $args An array of form arguments.
1797 *
1798 * @return void
1799 */
1800 function give_form_display_content( $form_id, $args ) {
1801
1802 $content = wpautop( give_get_meta( $form_id, '_give_form_content', true ) );
1803 $show_content = give_get_form_content_placement( $form_id, $args );
1804
1805 if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
1806 $content = apply_filters( 'the_content', $content );
1807 }
1808
1809 $output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap ' . $show_content . '-content">' . $content . '</div>';
1810
1811 echo apply_filters( 'give_form_content_output', $output );
1812
1813 // remove action to prevent content output on addition forms on page.
1814 // @see: https://github.com/WordImpress/Give/issues/634.
1815 remove_action( $show_content, 'give_form_display_content' );
1816 }
1817
1818 /**
1819 * Renders the hidden Checkout fields.
1820 *
1821 * @since 1.0
1822 *
1823 * @param int $form_id The form ID.
1824 *
1825 * @return void
1826 */
1827 function give_checkout_hidden_fields( $form_id ) {
1828
1829 /**
1830 * Fires while rendering hidden checkout fields, before the fields.
1831 *
1832 * @since 1.0
1833 *
1834 * @param int $form_id The form ID.
1835 */
1836 do_action( 'give_hidden_fields_before', $form_id );
1837
1838 if ( is_user_logged_in() ) { ?>
1839 <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
1840 <?php } ?>
1841 <input type="hidden" name="give_action" value="purchase"/>
1842 <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
1843 <?php
1844 /**
1845 * Fires while rendering hidden checkout fields, after the fields.
1846 *
1847 * @since 1.0
1848 *
1849 * @param int $form_id The form ID.
1850 */
1851 do_action( 'give_hidden_fields_after', $form_id );
1852
1853 }
1854
1855 /**
1856 * Filter Success Page Content.
1857 *
1858 * Applies filters to the success page content.
1859 *
1860 * @since 1.0
1861 *
1862 * @param string $content Content before filters.
1863 *
1864 * @return string $content Filtered content.
1865 */
1866 function give_filter_success_page_content( $content ) {
1867
1868 $give_options = give_get_settings();
1869
1870 if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
1871 if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
1872 $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
1873 }
1874 }
1875
1876 return $content;
1877 }
1878
1879 add_filter( 'the_content', 'give_filter_success_page_content' );
1880
1881 /**
1882 * Test Mode Frontend Warning.
1883 *
1884 * Displays a notice on the frontend for donation forms.
1885 *
1886 * @since 1.1
1887 */
1888 function give_test_mode_frontend_warning() {
1889
1890 if ( give_is_test_mode() ) {
1891 echo '<div class="give_error give_warning" id="give_error_test_mode"><p><strong>' . esc_html__( 'Notice:', 'give' ) . '</strong> ' . esc_html__( 'Test mode is enabled. While in test mode no live donations are processed.', 'give' ) . '</p></div>';
1892 }
1893 }
1894
1895 add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
1896
1897 /**
1898 * Members-only Form.
1899 *
1900 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
1901 *
1902 * @since 1.4.1
1903 *
1904 * @param string $final_output
1905 * @param array $args
1906 *
1907 * @return string
1908 */
1909 function give_members_only_form( $final_output, $args ) {
1910
1911 $form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
1912
1913 //Sanity Check: Must have form_id & not be logged in.
1914 if ( empty( $form_id ) || is_user_logged_in() ) {
1915 return $final_output;
1916 }
1917
1918 //Logged in only and Register / Login set to none.
1919 if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
1920
1921 $final_output = Give()->notices->print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
1922
1923 return apply_filters( 'give_members_only_output', $final_output, $form_id );
1924
1925 }
1926
1927 return $final_output;
1928
1929 }
1930
1931 add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
1932
1933
1934 /**
1935 * Add donation form hidden fields.
1936 *
1937 * @since 1.8.17
1938 *
1939 * @param int $form_id
1940 * @param array $args
1941 * @param Give_Donate_Form $form
1942 */
1943 function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
1944 ?>
1945 <input type="hidden" name="give-form-id" value="<?php echo $form_id; ?>"/>
1946 <input type="hidden" name="give-form-title" value="<?php echo htmlentities( $form->post_title ); ?>"/>
1947 <input type="hidden" name="give-current-url"
1948 value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
1949 <input type="hidden" name="give-form-url" value="<?php echo htmlspecialchars( give_get_current_page_url() ); ?>"/>
1950 <?php
1951 // Get the custom option amount.
1952 $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
1953
1954 // If custom amount enabled.
1955 if ( give_is_setting_enabled( $custom_amount ) ) {
1956 ?>
1957 <input type="hidden" name="give-form-minimum"
1958 value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/>
1959 <input type="hidden" name="give-form-maximum"
1960 value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/>
1961 <?php
1962 }
1963
1964 // WP nonce field.
1965 wp_nonce_field( "donation_form_nonce_{$form_id}", '_wpnonce', false );
1966
1967 // Price ID hidden field for variable (multi-level) donation forms.
1968 if ( give_has_variable_prices( $form_id ) ) {
1969 // Get default selected price ID.
1970 $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
1971 $price_id = 0;
1972 //loop through prices.
1973 foreach ( $prices as $price ) {
1974 if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) {
1975 $price_id = $price['_give_id']['level_id'];
1976 };
1977 }
1978
1979
1980 echo sprintf(
1981 '<input type="hidden" name="give-price-id" value="%s"/>',
1982 $price_id
1983 );
1984 }
1985 }
1986
1987 add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
1988
1989 /**
1990 * Add currency settings on donation form.
1991 *
1992 * @since 1.8.17
1993 *
1994 * @param array $form_html_tags
1995 * @param Give_Donate_Form $form
1996 *
1997 * @return array
1998 */
1999 function __give_form_add_currency_settings( $form_html_tags, $form ) {
2000 $form_currency = give_get_currency( $form->ID );
2001 $currency_settings = give_get_currency_formatting_settings( $form_currency );
2002
2003 // Check if currency exist.
2004 if ( empty( $currency_settings ) ) {
2005 return $form_html_tags;
2006 }
2007
2008 $form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2009 $form_html_tags['data-currency_code'] = $form_currency;
2010
2011 if ( ! empty( $currency_settings ) ) {
2012 foreach ( $currency_settings as $key => $value ) {
2013 $form_html_tags["data-{$key}"] = $value;
2014 }
2015 }
2016
2017 return $form_html_tags;
2018 }
2019
2020 add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2021
2022 /**
2023 * Adds classes to progress bar container.
2024 *
2025 * @since 2.1
2026 *
2027 * @param string $class_goal
2028 *
2029 * @return string
2030 */
2031 function add_give_goal_progress_class( $class_goal ) {
2032 $class_goal = 'progress progress-striped active';
2033
2034 return $class_goal;
2035 }
2036
2037 /**
2038 * Adds classes to progress bar span tag.
2039 *
2040 * @since 2.1
2041 *
2042 * @param string $class_bar
2043 *
2044 * @return string
2045 */
2046 function add_give_goal_progress_bar_class( $class_bar ) {
2047 $class_bar = 'bar';
2048
2049 return $class_bar;
2050 }
2051
2052 /**
2053 * Add a class to the form wrap on the grid page.
2054 *
2055 * @param array $class Array of form wrapper classes.
2056 * @param int $id ID of the form.
2057 * @param array $args Additional args.
2058 *
2059 * @since 2.1
2060 *
2061 * @return array
2062 */
2063 function add_class_for_form_grid( $class, $id, $args ) {
2064 $class[] = 'give-form-grid-wrap';
2065
2066 return $class;
2067 }
2068
2069 /**
2070 * Add hidden field to Form Grid page
2071 *
2072 * @param int $form_id The form ID.
2073 * @param array $args An array of form arguments.
2074 * @param Give_Donate_Form $form Form object.
2075 *
2076 * @since 2.1
2077 */
2078 function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
2079 echo '<input type="hidden" name="is-form-grid" value="true" />';
2080 }
2081
2082 /**
2083 * Redirect to the same paginated URL on the Form Grid page
2084 * and adds query parameters to open the popup again after
2085 * redirection.
2086 *
2087 * @param string $redirect URL for redirection.
2088 * @param array $args Array of additional args.
2089 *
2090 * @since 2.1
2091 * @return string
2092 */
2093 function give_redirect_and_popup_form( $redirect, $args ) {
2094
2095 // Check the page has Form Grid.
2096 $is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
2097
2098 if ( 'true' === $is_form_grid ) {
2099
2100 $payment_mode = give_clean( $_POST['payment-mode'] );
2101 $form_id = $args['form-id'];
2102
2103 // Get the URL without Query parameters.
2104 $redirect = strtok( $redirect, '?' );
2105
2106 // Add query parameters 'form-id' and 'payment-mode'.
2107 $redirect = add_query_arg( array(
2108 'form-id' => $form_id,
2109 'payment-mode' => $payment_mode,
2110 ), $redirect );
2111 }
2112
2113 // Return the modified URL.
2114 return $redirect;
2115 }
2116
2117 add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );