PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.18.0
GiveWP – Donation Plugin and Fundraising Platform v4.18.0
4.18.0 4.17.0 4.16.9 4.16.8.1 4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 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 All 257 releases
give / includes / forms / template.php

template.php in GiveWP – Donation Plugin and Fundraising Platform 4.18.0, at includes/forms/template.php

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