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