PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.0.1
GiveWP – Donation Plugin and Fundraising Platform v3.0.1
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
2532 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
1704 $gateways = give_get_enabled_payment_gateways( $form_id );
1705 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1706
1707 /**
1708 * Fires while selecting payment gateways, before the fields.
1709 *
1710 * @since 1.7
1711 *
1712 * @param int $form_id The form ID.
1713 *
1714 */
1715 do_action( 'give_payment_mode_top', $form_id );
1716 ?>
1717
1718 <fieldset id="give-payment-mode-select"<?php echo count( $gateways ) <= 1 ? ' style="display: none;"' : ''; ?>>
1719 <?php
1720 /**
1721 * Fires while selecting payment gateways, before the wrap div.
1722 *
1723 * @since 1.7
1724 *
1725 * @param int $form_id The form ID.
1726 *
1727 */
1728 do_action( 'give_payment_mode_before_gateways_wrap' );
1729 ?>
1730 <legend
1731 class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
1732 <span class="give-loading-text"><span
1733 class="give-loading-animation"></span>
1734 </span>
1735 </legend>
1736
1737 <div id="give-payment-mode-wrap">
1738 <?php
1739 /**
1740 * Fires while selecting payment gateways, before the gateways list.
1741 *
1742 * @since 1.7
1743 */
1744 do_action( 'give_payment_mode_before_gateways' )
1745 ?>
1746 <ul id="give-gateway-radio-list">
1747 <?php
1748 /**
1749 * Loop through the active payment gateways.
1750 */
1751 $selected_gateway = give_get_chosen_gateway( $form_id );
1752
1753 foreach ( $gateways as $gateway_id => $gateway ) :
1754 // Determine the default gateway.
1755 $checked = checked( $gateway_id, $selected_gateway, false );
1756 $checked_class = $checked ? ' class="give-gateway-option-selected"' : '';
1757 $is_payment_method_visible = isset( $gateway['is_visible'] ) ? $gateway['is_visible'] : true;
1758
1759 if ( true === $is_payment_method_visible ) {
1760 ?>
1761 <li<?php echo $checked_class; ?>>
1762 <input type="radio" name="payment-mode" class="give-gateway"
1763 id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1764 value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
1765 <label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1766 class="give-gateway-option"
1767 id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1768 </li>
1769 <?php
1770 }
1771 endforeach;
1772 ?>
1773 </ul>
1774 <?php
1775 /**
1776 * Fires while selecting payment gateways, before the gateways list.
1777 *
1778 * @since 1.7
1779 */
1780 do_action( 'give_payment_mode_after_gateways' );
1781 ?>
1782 </div>
1783 <?php
1784 /**
1785 * Fires while selecting payment gateways, after the wrap div.
1786 *
1787 * @param int $form_id The form ID.
1788 *
1789 * @since 1.7
1790 */
1791 do_action( 'give_payment_mode_after_gateways_wrap' );
1792 ?>
1793 </fieldset>
1794
1795 <?php
1796 /**
1797 * Fires while selecting payment gateways, after the fields.
1798 *
1799 * @param int $form_id The form ID.
1800 *
1801 * @since 1.7
1802 */
1803 do_action( 'give_payment_mode_bottom', $form_id );
1804 ?>
1805
1806 <div id="give_purchase_form_wrap">
1807
1808 <?php
1809 /**
1810 * Fire after payment field render.
1811 *
1812 * @since 1.7
1813 */
1814 do_action( 'give_donation_form', $form_id, $args );
1815 ?>
1816
1817 </div>
1818
1819 <?php
1820 /**
1821 * Fire after donation form render.
1822 *
1823 * @since 1.7
1824 */
1825 do_action( 'give_donation_form_wrap_bottom', $form_id );
1826 }
1827
1828 add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 );
1829
1830 /**
1831 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1832 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1833 * set in the Give Settings.
1834 *
1835 * @param int $form_id The form ID.
1836 *
1837 * @return bool
1838 * @since 1.0
1839 */
1840 function give_terms_agreement( $form_id ) {
1841 $form_option = give_get_meta( $form_id, '_give_terms_option', true );
1842
1843 // Bailout if per form and global term and conditions is not setup.
1844 if (
1845 give_is_setting_enabled( $form_option, 'global' )
1846 && give_is_setting_enabled( give_get_option( 'terms' ) )
1847 ) {
1848 $label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1849 $terms = $terms = give_get_option( 'agreement_text', '' );
1850 $edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1851
1852 } elseif ( give_is_setting_enabled( $form_option ) ) {
1853 $label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1854 $terms = give_get_meta( $form_id, '_give_agree_text', true );
1855 $edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1856
1857 } else {
1858 return false;
1859 }
1860
1861 // Bailout: Check if term and conditions text is empty or not.
1862 if ( empty( $terms ) ) {
1863 if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1864 echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
1865 }
1866
1867 return false;
1868 }
1869
1870 /**
1871 * Filter the form term content
1872 *
1873 * @since 2.1.5
1874 */
1875 $terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id );
1876
1877 ?>
1878 <fieldset id="give_terms_agreement">
1879 <legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
1880 <div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
1881 <?php
1882 /**
1883 * Fires while rendering terms of agreement, before the fields.
1884 *
1885 * @since 1.0
1886 */
1887 do_action( 'give_before_terms' );
1888
1889 echo $terms;
1890 /**
1891 * Fires while rendering terms of agreement, after the fields.
1892 *
1893 * @since 1.0
1894 */
1895 do_action( 'give_after_terms' );
1896 ?>
1897 </div>
1898 <div id="give_show_terms">
1899 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1900 aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1901 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1902 aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1903 </div>
1904
1905 <input name="give_agree_to_terms" class="required" type="checkbox"
1906 id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
1907 <label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
1908
1909 </fieldset>
1910 <?php
1911 }
1912
1913 add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1914
1915 /**
1916 * Checkout Final Total.
1917 *
1918 * Shows the final donation total at the bottom of the checkout page.
1919 *
1920 * @param int $form_id The form ID.
1921 *
1922 * @return void
1923 * @since 1.0
1924 */
1925 function give_checkout_final_total( $form_id ) {
1926
1927 $total = isset( $_POST['give_total'] ) ?
1928 apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'], [ 'currency' => give_get_currency( $form_id ) ] ) ) :
1929 give_get_default_form_amount( $form_id );
1930
1931 // Only proceed if give_total available.
1932 if ( empty( $total ) ) {
1933 return;
1934 }
1935 ?>
1936 <p id="give-final-total-wrap" class="form-wrap ">
1937 <?php
1938 /**
1939 * Fires before the donation total label
1940 *
1941 * @since 2.0.5
1942 */
1943 do_action( 'give_donation_final_total_label_before', $form_id );
1944 ?>
1945 <span class="give-donation-total-label">
1946 <?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?>
1947 </span>
1948 <span class="give-final-total-amount"
1949 data-total="<?php echo give_format_amount( $total, [ 'sanitize' => false ] ); ?>">
1950 <?php
1951 echo give_currency_filter(
1952 give_format_amount(
1953 $total,
1954 [
1955 'sanitize' => false,
1956 'currency' => give_get_currency( $form_id ),
1957 ]
1958 ),
1959 [ 'currency_code' => give_get_currency( $form_id ) ]
1960 );
1961 ?>
1962 </span>
1963 <?php
1964 /**
1965 * Fires after the donation final total label
1966 *
1967 * @since 2.0.5
1968 */
1969 do_action( 'give_donation_final_total_label_after', $form_id );
1970 ?>
1971 </p>
1972 <?php
1973 }
1974
1975 add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1976
1977 /**
1978 * Renders the Checkout Submit section.
1979 *
1980 * @param int $form_id The donation form ID.
1981 * @param array $args List of arguments.
1982 *
1983 * @return void
1984 * @since 1.0
1985 */
1986 function give_checkout_submit( $form_id, $args ) {
1987 ?>
1988 <fieldset id="give_purchase_submit" class="give-donation-submit">
1989 <?php
1990 /**
1991 * Fire before donation form submit.
1992 *
1993 * @since 1.7
1994 */
1995 do_action( 'give_donation_form_before_submit', $form_id, $args );
1996
1997 give_checkout_hidden_fields( $form_id, $args );
1998
1999 echo give_get_donation_form_submit_button( $form_id, $args );
2000
2001 /**
2002 * Fire after donation form submit.
2003 *
2004 * @since 1.7
2005 */
2006 do_action( 'give_donation_form_after_submit', $form_id, $args );
2007 ?>
2008 </fieldset>
2009 <?php
2010 }
2011
2012 add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 );
2013
2014 /**
2015 * Give Donation form submit button.
2016 *
2017 * @param int $form_id The form ID.
2018 * @param array $args
2019 *
2020 * @return string
2021 * @since 1.8.8
2022 */
2023 function give_get_donation_form_submit_button( $form_id, $args = [] ) {
2024
2025 $display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
2026 $display_label_field = apply_filters( 'give_donation_form_submit_button_text', $display_label_field, $form_id, $args );
2027 $display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
2028 ob_start();
2029 ?>
2030 <div class="give-submit-button-wrap give-clearfix">
2031 <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
2032 value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>"/>
2033 <span class="give-loading-animation"></span>
2034 </div>
2035 <?php
2036 return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id, $args );
2037 }
2038
2039 /**
2040 * Show Give Goals.
2041 *
2042 * @param int $form_id The form ID.
2043 * @param array $args An array of form arguments.
2044 *
2045 * @return mixed
2046 * @since 1.6 Add template for Give Goals Shortcode.
2047 * More info is on https://github.com/impress-org/give/issues/411
2048 *
2049 * @since 1.0
2050 */
2051 function give_show_goal_progress( $form_id, $args = [] ) {
2052
2053 ob_start();
2054 give_get_template(
2055 'shortcode-goal',
2056 [
2057 'form_id' => $form_id,
2058 'args' => $args,
2059 ]
2060 );
2061
2062 /**
2063 * Filter progress bar output
2064 *
2065 * @since 2.0
2066 */
2067 echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args );
2068
2069 return true;
2070 }
2071
2072 add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
2073
2074 /**
2075 * Show Give Totals Progress.
2076 *
2077 * @param int $total Total amount based on shortcode parameter.
2078 * @param int $total_goal Total Goal amount passed by Admin.
2079 *
2080 * @return mixed
2081 * @since 2.1
2082 */
2083 function give_show_goal_totals_progress( $total, $total_goal ) {
2084
2085 // Bail out if total goal is set as an array.
2086 if ( isset( $total_goal ) && is_array( $total_goal ) ) {
2087 return false;
2088 }
2089
2090 ob_start();
2091 give_get_template(
2092 'shortcode-totals-progress',
2093 [
2094 'total' => $total,
2095 'total_goal' => $total_goal,
2096 ]
2097 );
2098
2099 echo apply_filters( 'give_total_progress_output', ob_get_clean() );
2100
2101 return true;
2102 }
2103
2104 add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
2105
2106 /**
2107 * Get form content position.
2108 *
2109 * @param $form_id
2110 * @param $args
2111 *
2112 * @return mixed|string
2113 * @since 1.8
2114 */
2115 function give_get_form_content_placement( $form_id, $args ) {
2116 $show_content = '';
2117
2118 if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
2119 // Content positions.
2120 $content_placement = [
2121 'above' => 'give_pre_form',
2122 'below' => 'give_post_form',
2123 ];
2124
2125 // Check if content position already decoded.
2126 if ( in_array( $args['show_content'], $content_placement ) ) {
2127 return $args['show_content'];
2128 }
2129
2130 $show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
2131
2132 } elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
2133 $show_content = give_get_meta( $form_id, '_give_content_placement', true );
2134
2135 }
2136
2137 return $show_content;
2138 }
2139
2140 /**
2141 * Adds Actions to Render Form Content.
2142 *
2143 * @param int $form_id The form ID.
2144 * @param array $args An array of form arguments.
2145 *
2146 * @return void|bool
2147 * @since 1.0
2148 */
2149 function give_form_content( $form_id, $args ) {
2150
2151 $show_content = give_get_form_content_placement( $form_id, $args );
2152
2153 // Bailout.
2154 if ( empty( $show_content ) ) {
2155 return false;
2156 }
2157
2158 // Add action according to value.
2159 add_action( $show_content, 'give_form_display_content', 10, 2 );
2160 }
2161
2162 add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
2163
2164 /**
2165 * Renders Post Form Content.
2166 *
2167 * Displays content for Give forms; fired by action from give_form_content.
2168 *
2169 * @param int $form_id The form ID.
2170 * @param array $args An array of form arguments.
2171 *
2172 * @return void
2173 * @since 1.0
2174 */
2175 function give_form_display_content( $form_id, $args ) {
2176 $content = give_get_meta( $form_id, '_give_form_content', true );
2177 $show_content = give_get_form_content_placement( $form_id, $args );
2178
2179 if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
2180
2181 // Do not restore wpautop if we are still parsing blocks.
2182 $priority = has_filter( 'the_content', '_restore_wpautop_hook' );
2183 if ( false !== $priority && doing_filter( 'the_content' ) ) {
2184 remove_filter( 'the_content', '_restore_wpautop_hook', $priority );
2185 }
2186
2187 $content = apply_filters( 'the_content', $content );
2188
2189 // Restore wpautop after done with blocks parsing.
2190 if ( $priority ) {
2191 // Run wpautop manually if parsing block
2192 $content = wpautop( $content );
2193
2194 add_filter( 'the_content', '_restore_wpautop_hook', $priority );
2195 }
2196 } else {
2197 $content = wpautop( do_shortcode( $content ) );
2198 }
2199
2200 $output = sprintf(
2201 '<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>',
2202 $form_id,
2203 $show_content,
2204 $content
2205 );
2206
2207 /**
2208 * Filter form content html
2209 *
2210 * @param string $output
2211 * @param int $form_id
2212 * @param array $args
2213 *
2214 * @since 1.0
2215 */
2216 echo apply_filters( 'give_form_content_output', $output, $form_id, $args );
2217
2218 // remove action to prevent content output on addition forms on page.
2219 // @see: https://github.com/impress-org/give/issues/634.
2220 remove_action( $show_content, 'give_form_display_content' );
2221 }
2222
2223 /**
2224 * Renders the hidden Checkout fields.
2225 *
2226 * @param int $form_id The form ID.
2227 * @param array $args Shortcode args.
2228 *
2229 * @return void
2230 * @since 1.0
2231 */
2232 function give_checkout_hidden_fields( $form_id, $args = [] ) {
2233
2234 /**
2235 * Fires while rendering hidden checkout fields, before the fields.
2236 *
2237 * @param int $form_id The form ID.
2238 *
2239 * @since 1.0
2240 */
2241 do_action( 'give_hidden_fields_before', $form_id, $args );
2242
2243 if ( is_user_logged_in() ) {
2244 ?>
2245 <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
2246 <?php } ?>
2247 <input type="hidden" name="give_action" value="purchase"/>
2248 <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
2249 <?php
2250 /**
2251 * Fires while rendering hidden checkout fields, after the fields.
2252 *
2253 * @param int $form_id The form ID.
2254 *
2255 * @since 1.0
2256 */
2257 do_action( 'give_hidden_fields_after', $form_id, $args );
2258
2259 }
2260
2261 /**
2262 * Filter Success Page Content.
2263 *
2264 * Applies filters to the success page content.
2265 *
2266 * @param string $content Content before filters.
2267 *
2268 * @return string $content Filtered content.
2269 * @since 1.0
2270 */
2271 function give_filter_success_page_content( $content ) {
2272
2273 $give_options = give_get_settings();
2274
2275 if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
2276 if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
2277 $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
2278 }
2279 }
2280
2281 return $content;
2282 }
2283
2284 add_filter( 'the_content', 'give_filter_success_page_content' );
2285
2286 /**
2287 * Test Mode Frontend Warning.
2288 *
2289 * Displays a notice on the frontend for donation forms.
2290 *
2291 * @since 1.1
2292 */
2293 function give_test_mode_frontend_warning() {
2294
2295 if ( give_is_test_mode() ) {
2296 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>';
2297 }
2298 }
2299
2300 add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
2301
2302 /**
2303 * Members-only Form.
2304 *
2305 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
2306 *
2307 * @param string $final_output
2308 * @param array $args
2309 *
2310 * @return string
2311 * @since 1.4.1
2312 */
2313 function give_members_only_form( $final_output, $args ) {
2314
2315 $form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
2316
2317 // Sanity Check: Must have form_id & not be logged in.
2318 if ( empty( $form_id ) || is_user_logged_in() ) {
2319 return $final_output;
2320 }
2321
2322 // Logged in only and Register / Login set to none.
2323 if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
2324
2325 $final_output = Give_Notices::print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
2326
2327 return apply_filters( 'give_members_only_output', $final_output, $form_id );
2328
2329 }
2330
2331 return $final_output;
2332
2333 }
2334
2335 add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
2336
2337
2338 /**
2339 * Add donation form hidden fields.
2340 *
2341 * @param int $form_id
2342 * @param array $args
2343 * @param Give_Donate_Form $form
2344 *
2345 * @since 1.8.17
2346 */
2347 function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
2348 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
2349 ?>
2350 <input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/>
2351 <input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/>
2352 <input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/>
2353 <input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2354 <input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2355 <?php
2356 // Get the custom option amount.
2357 $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
2358
2359 // If custom amount enabled.
2360 if ( give_is_setting_enabled( $custom_amount ) ) {
2361 ?>
2362 <input type="hidden" name="give-form-minimum"
2363 value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/>
2364 <input type="hidden" name="give-form-maximum"
2365 value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/>
2366 <?php
2367 }
2368
2369 $data_attr = sprintf(
2370 'data-time="%1$s" data-nonce-life="%2$s" data-donor-session="%3$s"',
2371 time(),
2372 give_get_nonce_life(),
2373 absint( Give()->session->has_session() )
2374 );
2375
2376 // WP nonce field.
2377 echo str_replace(
2378 '/>',
2379 "{$data_attr}/>",
2380 give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
2381 );
2382
2383 // Price ID hidden field for variable (multi-level) donation forms.
2384 if ( give_has_variable_prices( $form_id ) ) {
2385 // Get the default price ID.
2386 $default_price = give_form_get_default_level( $form_id );
2387 $price_id = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0;
2388
2389 echo sprintf(
2390 '<input type="hidden" name="give-price-id" value="%s"/>',
2391 $price_id
2392 );
2393 }
2394 }
2395
2396 add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
2397
2398 /**
2399 * Add currency settings on donation form.
2400 *
2401 * @param array $form_html_tags
2402 * @param Give_Donate_Form $form
2403 *
2404 * @return array
2405 * @since 1.8.17
2406 */
2407 function __give_form_add_currency_settings( $form_html_tags, $form ) {
2408 $form_currency = give_get_currency( $form->ID );
2409 $currency_settings = give_get_currency_formatting_settings( $form_currency );
2410
2411 // Check if currency exist.
2412 if ( empty( $currency_settings ) ) {
2413 return $form_html_tags;
2414 }
2415
2416 $form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2417 $form_html_tags['data-currency_code'] = $form_currency;
2418
2419 if ( ! empty( $currency_settings ) ) {
2420 foreach ( $currency_settings as $key => $value ) {
2421 $form_html_tags[ "data-{$key}" ] = $value;
2422 }
2423 }
2424
2425 return $form_html_tags;
2426 }
2427
2428 add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2429
2430 /**
2431 * Adds classes to progress bar container.
2432 *
2433 * @param string $class_goal
2434 *
2435 * @return string
2436 * @since 2.1
2437 */
2438 function add_give_goal_progress_class( $class_goal ) {
2439 $class_goal = 'progress progress-striped active';
2440
2441 return $class_goal;
2442 }
2443
2444 /**
2445 * Adds classes to progress bar span tag.
2446 *
2447 * @param string $class_bar
2448 *
2449 * @return string
2450 * @since 2.1
2451 */
2452 function add_give_goal_progress_bar_class( $class_bar ) {
2453 $class_bar = 'bar';
2454
2455 return $class_bar;
2456 }
2457
2458 /**
2459 * Add a class to the form wrap on the grid page.
2460 *
2461 * @param array $class Array of form wrapper classes.
2462 * @param int $id ID of the form.
2463 * @param array $args Additional args.
2464 *
2465 * @return array
2466 * @since 2.1
2467 */
2468 function add_class_for_form_grid( $class, $id, $args ) {
2469 $class[] = 'give-form-grid-wrap';
2470
2471 foreach ( $class as $index => $item ) {
2472 if ( false !== strpos( $item, 'give-display-' ) ) {
2473 unset( $class[ $index ] );
2474 }
2475 }
2476
2477 return $class;
2478 }
2479
2480 /**
2481 * Add hidden field to Form Grid page
2482 *
2483 * @param int $form_id The form ID.
2484 * @param array $args An array of form arguments.
2485 * @param Give_Donate_Form $form Form object.
2486 *
2487 * @since 2.1
2488 */
2489 function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
2490 echo '<input type="hidden" name="is-form-grid" value="true" />';
2491 }
2492
2493 /**
2494 * Redirect to the same paginated URL on the Form Grid page
2495 * and adds query parameters to open the popup again after
2496 * redirection.
2497 *
2498 * @param string $redirect URL for redirection.
2499 * @param array $args Array of additional args.
2500 *
2501 * @return string
2502 * @since 2.1
2503 */
2504 function give_redirect_and_popup_form( $redirect, $args ) {
2505
2506 // Check the page has Form Grid.
2507 $is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
2508
2509 if ( 'true' === $is_form_grid ) {
2510
2511 $payment_mode = give_clean( $_POST['payment-mode'] );
2512 $form_id = $args['form-id'];
2513
2514 // Get the URL without Query parameters.
2515 $redirect = strtok( $redirect, '?' );
2516
2517 // Add query parameters 'form-id' and 'payment-mode'.
2518 $redirect = add_query_arg(
2519 [
2520 'form-id' => $form_id,
2521 'payment-mode' => $payment_mode,
2522 ],
2523 $redirect
2524 );
2525 }
2526
2527 // Return the modified URL.
2528 return esc_url_raw( $redirect );
2529 }
2530
2531 add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );
2532