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