PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.31.0
GiveWP – Donation Plugin and Fundraising Platform v2.31.0
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 3 years ago widget.php 6 years ago
template.php
2524 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 * @param int $form_id The form ID.
1197 *
1198 * @return void
1199 * @since 1.0
1200 */
1201 function give_default_cc_address_fields( $form_id ) {
1202 // Get user info.
1203 $give_user_info = _give_get_prefill_form_field_values( $form_id );
1204
1205 ob_start();
1206 ?>
1207 <fieldset id="give_cc_address" class="cc-address">
1208 <legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
1209 <?php
1210 /**
1211 * Fires while rendering credit card billing form, before address fields.
1212 *
1213 * @param int $form_id The form ID.
1214 *
1215 * @since 1.0
1216 */
1217 do_action( 'give_cc_billing_top' );
1218
1219 // For Country.
1220 $selected_country = give_get_country();
1221 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
1222 $selected_country = $give_user_info['billing_country'];
1223 }
1224 $countries = give_get_country_list();
1225
1226 // For state.
1227 $selected_state = '';
1228 if ( $selected_country === give_get_country() ) {
1229 // Get default selected state by admin.
1230 $selected_state = give_get_state();
1231 }
1232 // Get the last payment made by user states.
1233 if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
1234 $selected_state = $give_user_info['card_state'];
1235 }
1236 // Get the country code.
1237 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
1238 $selected_country = $give_user_info['billing_country'];
1239 }
1240
1241 // Get the country list that does not require city.
1242 $city_required = ! array_key_exists( $selected_country, give_city_not_required_country_list() );
1243
1244 ?>
1245 <p id="give-card-country-wrap" class="form-row form-row-wide">
1246 <label for="billing_country" class="give-label">
1247 <?php esc_html_e( 'Country', 'give' ); ?>
1248 <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
1249 <span class="give-required-indicator">*</span>
1250 <?php endif; ?>
1251 <span class="give-tooltip give-icon give-icon-question"
1252 data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
1253 </label>
1254
1255 <select
1256 name="billing_country"
1257 autocomplete="country"
1258 id="billing_country"
1259 class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
1260 <?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1261 >
1262 <?php
1263 foreach ( $countries as $country_code => $country ) {
1264 echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
1265 }
1266 ?>
1267 </select>
1268 </p>
1269
1270 <p id="give-card-address-wrap" class="form-row form-row-wide">
1271 <label for="card_address" class="give-label">
1272 <?php _e( 'Address 1', 'give' ); ?>
1273 <?php
1274 if ( give_field_is_required( 'card_address', $form_id ) ) :
1275 ?>
1276 <span class="give-required-indicator">*</span>
1277 <?php endif; ?>
1278 <?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?>
1279 </label>
1280
1281 <input
1282 type="text"
1283 id="card_address"
1284 name="card_address"
1285 autocomplete="address-line1"
1286 class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
1287 placeholder="<?php _e( 'Address line 1', 'give' ); ?>"
1288 value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
1289 <?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1290 />
1291 </p>
1292
1293 <p id="give-card-address-2-wrap" class="form-row form-row-wide">
1294 <label for="card_address_2" class="give-label">
1295 <?php _e( 'Address 2', 'give' ); ?>
1296 <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
1297 <span class="give-required-indicator">*</span>
1298 <?php endif; ?>
1299 <?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?>
1300 </label>
1301
1302 <input
1303 type="text"
1304 id="card_address_2"
1305 name="card_address_2"
1306 autocomplete="address-line2"
1307 class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
1308 placeholder="<?php _e( 'Address line 2', 'give' ); ?>"
1309 value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
1310 <?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1311 />
1312 </p>
1313
1314 <p id="give-card-city-wrap" class="form-row form-row-wide">
1315 <label for="card_city" class="give-label">
1316 <?php _e( 'City', 'give' ); ?>
1317 <?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
1318 <span class="give-required-indicator <?php echo( $city_required ? '' : 'give-hidden' ); ?>">*</span>
1319 <?php endif; ?>
1320 <?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?>
1321 </label>
1322 <input
1323 type="text"
1324 id="card_city"
1325 name="card_city"
1326 autocomplete="address-level2"
1327 class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
1328 placeholder="<?php _e( 'City', 'give' ); ?>"
1329 value="<?php echo( isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : '' ); ?>"
1330 <?php echo( give_field_is_required( 'card_city', $form_id ) && $city_required ? ' required aria-required="true" ' : '' ); ?>
1331 />
1332 </p>
1333
1334 <?php
1335 /**
1336 * State field logic.
1337 */
1338 $state_label = __( 'State', 'give' );
1339 $states_label = give_get_states_label();
1340 // Check if $country code exists in the array key for states label.
1341 if ( array_key_exists( $selected_country, $states_label ) ) {
1342 $state_label = $states_label[ $selected_country ];
1343 }
1344 $states = give_get_states( $selected_country );
1345 // Get the country list that do not have any states.
1346 $no_states_country = give_no_states_country_list();
1347 // Get the country list that does not require states.
1348 $states_not_required_country_list = give_states_not_required_country_list();
1349 // Used to determine if state is required.
1350 $require_state = ! array_key_exists( $selected_country, $no_states_country ) && give_field_is_required( 'card_state', $form_id );
1351 // Used to determine is state input should be marked as required.
1352 $validate_state = ! array_key_exists( $selected_country, $states_not_required_country_list ) && give_field_is_required( 'card_state', $form_id );
1353 // Check if post code is required
1354 $postcode_required = $selected_country
1355 ? ! array_key_exists( $selected_country, give_get_country_list_without_postcodes() ) && give_field_is_required( 'card_zip', $form_id )
1356 : give_field_is_required( 'card_zip', $form_id );
1357 ?>
1358 <p id="give-card-state-wrap"
1359 class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && ! $require_state ) ? 'give-hidden' : ''; ?> ">
1360 <label for="card_state" class="give-label">
1361 <span class="state-label-text"><?php echo $state_label; ?></span>
1362 <span
1363 class="give-required-indicator <?php echo $validate_state ? '' : 'give-hidden'; ?> ">*</span>
1364 <span class="give-tooltip give-icon give-icon-question"
1365 data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1366 </label>
1367 <?php
1368
1369 if ( ! empty( $states ) ) :
1370 ?>
1371 <select
1372 name="card_state"
1373 autocomplete="address-level1"
1374 id="card_state"
1375 class="card_state give-select<?php echo $validate_state ? ' required' : ''; ?>"
1376 <?php echo $validate_state ? ' required aria-required="true" ' : ''; ?>>
1377 <?php
1378 foreach ( $states as $state_code => $state ) {
1379 echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
1380 }
1381 ?>
1382 </select>
1383 <?php else : ?>
1384 <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1385 placeholder="<?php echo $state_label; ?>" value="<?php echo $selected_state; ?>"
1386 <?php echo $validate_state ? ' required aria-required="true" ' : ''; ?>
1387 />
1388 <?php endif; ?>
1389 </p>
1390
1391 <p id="give-card-zip-wrap" class="form-row <?php echo $require_state ? 'form-row-last' : ''; ?> form-row-responsive">
1392 <label for="card_zip" class="give-label">
1393 <?php _e( 'Zip / Postal Code', 'give' ); ?>
1394 <span class="give-required-indicator<?php echo ( $postcode_required ? '' : ' give-hidden' ); ?>">*</span>
1395 <?php echo Give()->tooltips->render_help( __( 'The zip or postal code for your billing address.', 'give' ) ); ?>
1396 </label>
1397
1398 <input
1399 type="text"
1400 size="4"
1401 id="card_zip"
1402 name="card_zip"
1403 autocomplete="postal-code"
1404 class="card-zip give-input<?php echo( $postcode_required ? ' required' : '' ); ?>"
1405 placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>"
1406 value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
1407 <?php echo( $postcode_required ? ' required aria-required="true" ' : '' ); ?>
1408 />
1409 </p>
1410 <?php
1411 /**
1412 * Fires while rendering credit card billing form, after address fields.
1413 *
1414 * @param int $form_id The form ID.
1415 *
1416 * @since 1.0
1417 */
1418 do_action( 'give_cc_billing_bottom' );
1419 ?>
1420 </fieldset>
1421 <?php
1422 echo ob_get_clean();
1423 }
1424
1425 add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1426
1427
1428 /**
1429 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1430 * is provided for the user to create an account.
1431 *
1432 * @param int $form_id The form ID.
1433 *
1434 * @return string
1435 * @since 1.0
1436 */
1437 function give_get_register_fields( $form_id ) {
1438
1439 global $user_ID;
1440
1441 if ( is_user_logged_in() ) {
1442 $user_data = get_userdata( $user_ID );
1443 }
1444
1445 $show_register_form = give_show_login_register_option( $form_id );
1446
1447 ob_start();
1448 ?>
1449 <fieldset id="give-register-fields-<?php echo $form_id; ?>">
1450
1451 <?php
1452 /**
1453 * Fires while rendering user registration form, before registration fields.
1454 *
1455 * @param int $form_id The form ID.
1456 *
1457 * @since 1.0
1458 */
1459 do_action( 'give_register_fields_before', $form_id );
1460 ?>
1461
1462 <fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
1463 <?php
1464 /**
1465 * Fires while rendering user registration form, before account fields.
1466 *
1467 * @param int $form_id The form ID.
1468 *
1469 * @since 1.0
1470 */
1471 do_action( 'give_register_account_fields_before', $form_id );
1472
1473 $class = ( 'registration' === $show_register_form ) ? 'form-row-wide' : 'form-row-first';
1474 // Add attributes to checkbox, if Guest Checkout is disabled.
1475 $is_guest_checkout = give_is_setting_enabled( give_get_meta( $form_id, '_give_logged_in_only', true ) );
1476 ?>
1477
1478 <?php
1479 /**
1480 * If Guest Checkout is enabled, display label and checkbox - unchecked.
1481 * If Guest Checkout it disabled, display hidden checkbox - checked.
1482 * @since 2.9.6
1483 * @since 2.9.7 Create account checkbox is hidden when guest registration is disabled.
1484 */
1485 ?>
1486 <div id="give-create-account-wrap-<?php echo $form_id; ?>" class="form-row <?php echo esc_attr( $class ); ?> form-row-responsive">
1487 <?php
1488 $is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true );
1489 if ( give_is_setting_enabled( $is_guest_checkout ) ) {
1490 ?>
1491 <label for="give-create-account-<?php echo $form_id; ?>">
1492 <input type="checkbox" id="give-create-account-<?php echo $form_id; ?>" name="give_create_account" class="give-input" value="on" />
1493 <?php
1494 _e( 'Create an account', 'give' );
1495 echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) );
1496 ?>
1497 </label>
1498 <?php } else { ?>
1499 <input type="hidden" id="give-create-account-<?php echo $form_id; ?>" name="give_create_account" class="give-input" value="on" checked />
1500 <?php } ?>
1501 <?php
1502 echo str_replace(
1503 '/>',
1504 'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
1505 give_get_nonce_field( "give_form_create_user_nonce_{$form_id}", 'give-form-user-register-hash', false )
1506 );
1507 ?>
1508 </div>
1509
1510 <?php if ( 'both' === $show_register_form ) { ?>
1511 <div class="give-login-account-wrap form-row form-row-last form-row-responsive">
1512 <p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1513 <a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1514 data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1515 </p>
1516 <p class="give-loading-text">
1517 <span class="give-loading-animation"></span>
1518 </p>
1519 </div>
1520 <?php } ?>
1521
1522 <?php
1523 /**
1524 * Fires while rendering user registration form, after account fields.
1525 *
1526 * @param int $form_id The form ID.
1527 *
1528 * @since 1.0
1529 */
1530 do_action( 'give_register_account_fields_after', $form_id );
1531 ?>
1532 </fieldset>
1533
1534 <?php
1535 /**
1536 * Fires while rendering user registration form, after registration fields.
1537 *
1538 * @param int $form_id The form ID.
1539 *
1540 * @since 1.0
1541 */
1542 do_action( 'give_register_fields_after', $form_id );
1543 ?>
1544
1545 <input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1546
1547 <?php
1548 /**
1549 * Fire after register or login form render
1550 *
1551 * @since 1.7
1552 */
1553 do_action( 'give_donation_form_user_info', $form_id );
1554 ?>
1555
1556 </fieldset>
1557 <?php
1558 echo ob_get_clean();
1559 }
1560
1561 add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1562
1563 /**
1564 * Gets the login fields for the login form on the checkout. This function hooks
1565 * on the give_donation_form_login_fields to display the login form if a user already
1566 * had an account.
1567 *
1568 * @param int $form_id The form ID.
1569 *
1570 * @return string
1571 * @since 1.0
1572 */
1573 function give_get_login_fields( $form_id ) {
1574
1575 $form_id = isset( $_POST['form_id'] ) ? give_clean( $_POST['form_id'] ) : $form_id;
1576 $show_register_form = give_show_login_register_option( $form_id );
1577
1578 ob_start();
1579 ?>
1580 <fieldset id="give-login-fields-<?php echo esc_attr( $form_id ); ?>">
1581 <legend>
1582 <?php
1583 echo apply_filters( 'give_account_login_fieldset_heading', __( 'Log In to Your Account', 'give' ) );
1584 if ( ! give_logged_in_only( $form_id ) ) {
1585 echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>';
1586 }
1587 ?>
1588 </legend>
1589 <?php if ( $show_register_form === 'both' ) { ?>
1590 <p class="give-new-account-link">
1591 <?php _e( 'Don\'t have an account?', 'give' ); ?>&nbsp;
1592 <a href="<?php echo esc_url( remove_query_arg( 'login' ) ); ?>" class="give-checkout-register-cancel"
1593 data-action="give_checkout_register">
1594 <?php
1595 if ( give_logged_in_only( $form_id ) ) {
1596 _e( 'Register as a part of your donation &raquo;', 'give' );
1597 } else {
1598 _e( 'Register or donate as a guest &raquo;', 'give' );
1599 }
1600 ?>
1601 </a>
1602 </p>
1603 <p class="give-loading-text">
1604 <span class="give-loading-animation"></span>
1605 </p>
1606 <?php } ?>
1607 <?php
1608 /**
1609 * Fires while rendering checkout login form, before the fields.
1610 *
1611 * @param int $form_id The form ID.
1612 *
1613 * @since 1.0
1614 */
1615 do_action( 'give_donation_form_login_fields_before', $form_id );
1616 ?>
1617 <div class="give-user-login-fields-container">
1618 <div id="give-user-login-wrap-<?php echo esc_attr( $form_id ); ?>" class="form-row form-row-first form-row-responsive">
1619 <label class="give-label" for="give-user-login-<?php echo esc_attr( $form_id ); ?>">
1620 <?php _e( 'Username or Email Address', 'give' ); ?>
1621 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1622 <span class="give-required-indicator">*</span>
1623 <?php } ?>
1624 </label>
1625
1626 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1627 type="text"
1628 name="give_user_login" id="give-user-login-<?php echo esc_attr( $form_id ); ?>" value=""
1629 placeholder="<?php _e( 'Your username or email', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1630 </div>
1631
1632 <div id="give-user-pass-wrap-<?php echo esc_attr( $form_id ); ?>"
1633 class="give_login_password form-row form-row-last form-row-responsive">
1634 <label class="give-label" for="give-user-pass-<?php echo esc_attr( $form_id ); ?>">
1635 <?php _e( 'Password', 'give' ); ?>
1636 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1637 <span class="give-required-indicator">*</span>
1638 <?php } ?>
1639 </label>
1640 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1641 type="password" name="give_user_pass" id="give-user-pass-<?php echo esc_attr( $form_id ); ?>"
1642 placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1643 <?php if ( give_logged_in_only( $form_id ) ) : ?>
1644 <input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1645 <?php endif; ?>
1646 </div>
1647 </div>
1648
1649 <div id="give-user-login-submit-<?php echo esc_attr( $form_id ); ?>" class="give-clearfix">
1650 <input type="submit" class="give-submit give-btn button" name="give_login_submit"
1651 value="<?php _e( 'Login', 'give' ); ?>"/>
1652 <?php if ( $show_register_form !== 'login' ) { ?>
1653 <input type="button" data-action="give_cancel_login"
1654 class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1655 value="<?php _e( 'Cancel', 'give' ); ?>"/>
1656 <?php } ?>
1657 <span class="give-loading-animation"></span>
1658 <div id="give-forgot-password-wrap-<?php echo esc_attr( $form_id ); ?>" class="give_login_forgot_password">
1659 <span class="give-forgot-password ">
1660 <a href="<?php echo wp_lostpassword_url(); ?>" target="_blank"><?php _e( 'Reset Password', 'give' ); ?></a>
1661 </span>
1662 </div>
1663 </div>
1664 <?php
1665 /**
1666 * Fires while rendering checkout login form, after the fields.
1667 *
1668 * @param int $form_id The form ID.
1669 *
1670 * @since 1.0
1671 */
1672 do_action( 'give_donation_form_login_fields_after', $form_id );
1673 ?>
1674 </fieldset><!--end #give-login-fields-->
1675 <?php
1676 echo ob_get_clean();
1677 }
1678
1679 add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1680
1681 /**
1682 * Payment Mode Select.
1683 *
1684 * Renders the payment mode form by getting all the enabled payment gateways and
1685 * outputting them as radio buttons for the user to choose the payment gateway. If
1686 * a default payment gateway has been chosen from the Give Settings, it will be
1687 * automatically selected.
1688 *
1689 * @param int $form_id The form ID.
1690 *
1691 * @return void
1692 * @since 1.0
1693 */
1694 function give_payment_mode_select( $form_id, $args ) {
1695
1696 $gateways = give_get_enabled_payment_gateways( $form_id );
1697 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1698
1699 /**
1700 * Fires while selecting payment gateways, before the fields.
1701 *
1702 * @since 1.7
1703 *
1704 * @param int $form_id The form ID.
1705 *
1706 */
1707 do_action( 'give_payment_mode_top', $form_id );
1708 ?>
1709
1710 <fieldset id="give-payment-mode-select"<?php echo count( $gateways ) <= 1 ? ' style="display: none;"' : ''; ?>>
1711 <?php
1712 /**
1713 * Fires while selecting payment gateways, before the wrap div.
1714 *
1715 * @since 1.7
1716 *
1717 * @param int $form_id The form ID.
1718 *
1719 */
1720 do_action( 'give_payment_mode_before_gateways_wrap' );
1721 ?>
1722 <legend
1723 class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
1724 <span class="give-loading-text"><span
1725 class="give-loading-animation"></span>
1726 </span>
1727 </legend>
1728
1729 <div id="give-payment-mode-wrap">
1730 <?php
1731 /**
1732 * Fires while selecting payment gateways, before the gateways list.
1733 *
1734 * @since 1.7
1735 */
1736 do_action( 'give_payment_mode_before_gateways' )
1737 ?>
1738 <ul id="give-gateway-radio-list">
1739 <?php
1740 /**
1741 * Loop through the active payment gateways.
1742 */
1743 $selected_gateway = give_get_chosen_gateway( $form_id );
1744
1745 foreach ( $gateways as $gateway_id => $gateway ) :
1746 // Determine the default gateway.
1747 $checked = checked( $gateway_id, $selected_gateway, false );
1748 $checked_class = $checked ? ' class="give-gateway-option-selected"' : '';
1749 $is_payment_method_visible = isset( $gateway['is_visible'] ) ? $gateway['is_visible'] : true;
1750
1751 if ( true === $is_payment_method_visible ) {
1752 ?>
1753 <li<?php echo $checked_class; ?>>
1754 <input type="radio" name="payment-mode" class="give-gateway"
1755 id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1756 value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
1757 <label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1758 class="give-gateway-option"
1759 id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1760 </li>
1761 <?php
1762 }
1763 endforeach;
1764 ?>
1765 </ul>
1766 <?php
1767 /**
1768 * Fires while selecting payment gateways, before the gateways list.
1769 *
1770 * @since 1.7
1771 */
1772 do_action( 'give_payment_mode_after_gateways' );
1773 ?>
1774 </div>
1775 <?php
1776 /**
1777 * Fires while selecting payment gateways, after the wrap div.
1778 *
1779 * @param int $form_id The form ID.
1780 *
1781 * @since 1.7
1782 */
1783 do_action( 'give_payment_mode_after_gateways_wrap' );
1784 ?>
1785 </fieldset>
1786
1787 <?php
1788 /**
1789 * Fires while selecting payment gateways, after the fields.
1790 *
1791 * @param int $form_id The form ID.
1792 *
1793 * @since 1.7
1794 */
1795 do_action( 'give_payment_mode_bottom', $form_id );
1796 ?>
1797
1798 <div id="give_purchase_form_wrap">
1799
1800 <?php
1801 /**
1802 * Fire after payment field render.
1803 *
1804 * @since 1.7
1805 */
1806 do_action( 'give_donation_form', $form_id, $args );
1807 ?>
1808
1809 </div>
1810
1811 <?php
1812 /**
1813 * Fire after donation form render.
1814 *
1815 * @since 1.7
1816 */
1817 do_action( 'give_donation_form_wrap_bottom', $form_id );
1818 }
1819
1820 add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 );
1821
1822 /**
1823 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1824 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1825 * set in the Give Settings.
1826 *
1827 * @param int $form_id The form ID.
1828 *
1829 * @return bool
1830 * @since 1.0
1831 */
1832 function give_terms_agreement( $form_id ) {
1833 $form_option = give_get_meta( $form_id, '_give_terms_option', true );
1834
1835 // Bailout if per form and global term and conditions is not setup.
1836 if (
1837 give_is_setting_enabled( $form_option, 'global' )
1838 && give_is_setting_enabled( give_get_option( 'terms' ) )
1839 ) {
1840 $label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1841 $terms = $terms = give_get_option( 'agreement_text', '' );
1842 $edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1843
1844 } elseif ( give_is_setting_enabled( $form_option ) ) {
1845 $label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1846 $terms = give_get_meta( $form_id, '_give_agree_text', true );
1847 $edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1848
1849 } else {
1850 return false;
1851 }
1852
1853 // Bailout: Check if term and conditions text is empty or not.
1854 if ( empty( $terms ) ) {
1855 if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1856 echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
1857 }
1858
1859 return false;
1860 }
1861
1862 /**
1863 * Filter the form term content
1864 *
1865 * @since 2.1.5
1866 */
1867 $terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id );
1868
1869 ?>
1870 <fieldset id="give_terms_agreement">
1871 <legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
1872 <div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
1873 <?php
1874 /**
1875 * Fires while rendering terms of agreement, before the fields.
1876 *
1877 * @since 1.0
1878 */
1879 do_action( 'give_before_terms' );
1880
1881 echo $terms;
1882 /**
1883 * Fires while rendering terms of agreement, after the fields.
1884 *
1885 * @since 1.0
1886 */
1887 do_action( 'give_after_terms' );
1888 ?>
1889 </div>
1890 <div id="give_show_terms">
1891 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1892 aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1893 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1894 aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1895 </div>
1896
1897 <input name="give_agree_to_terms" class="required" type="checkbox"
1898 id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
1899 <label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
1900
1901 </fieldset>
1902 <?php
1903 }
1904
1905 add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1906
1907 /**
1908 * Checkout Final Total.
1909 *
1910 * Shows the final donation total at the bottom of the checkout page.
1911 *
1912 * @param int $form_id The form ID.
1913 *
1914 * @return void
1915 * @since 1.0
1916 */
1917 function give_checkout_final_total( $form_id ) {
1918
1919 $total = isset( $_POST['give_total'] ) ?
1920 apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'], [ 'currency' => give_get_currency( $form_id ) ] ) ) :
1921 give_get_default_form_amount( $form_id );
1922
1923 // Only proceed if give_total available.
1924 if ( empty( $total ) ) {
1925 return;
1926 }
1927 ?>
1928 <p id="give-final-total-wrap" class="form-wrap ">
1929 <?php
1930 /**
1931 * Fires before the donation total label
1932 *
1933 * @since 2.0.5
1934 */
1935 do_action( 'give_donation_final_total_label_before', $form_id );
1936 ?>
1937 <span class="give-donation-total-label">
1938 <?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?>
1939 </span>
1940 <span class="give-final-total-amount"
1941 data-total="<?php echo give_format_amount( $total, [ 'sanitize' => false ] ); ?>">
1942 <?php
1943 echo give_currency_filter(
1944 give_format_amount(
1945 $total,
1946 [
1947 'sanitize' => false,
1948 'currency' => give_get_currency( $form_id ),
1949 ]
1950 ),
1951 [ 'currency_code' => give_get_currency( $form_id ) ]
1952 );
1953 ?>
1954 </span>
1955 <?php
1956 /**
1957 * Fires after the donation final total label
1958 *
1959 * @since 2.0.5
1960 */
1961 do_action( 'give_donation_final_total_label_after', $form_id );
1962 ?>
1963 </p>
1964 <?php
1965 }
1966
1967 add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1968
1969 /**
1970 * Renders the Checkout Submit section.
1971 *
1972 * @param int $form_id The donation form ID.
1973 * @param array $args List of arguments.
1974 *
1975 * @return void
1976 * @since 1.0
1977 */
1978 function give_checkout_submit( $form_id, $args ) {
1979 ?>
1980 <fieldset id="give_purchase_submit" class="give-donation-submit">
1981 <?php
1982 /**
1983 * Fire before donation form submit.
1984 *
1985 * @since 1.7
1986 */
1987 do_action( 'give_donation_form_before_submit', $form_id, $args );
1988
1989 give_checkout_hidden_fields( $form_id, $args );
1990
1991 echo give_get_donation_form_submit_button( $form_id, $args );
1992
1993 /**
1994 * Fire after donation form submit.
1995 *
1996 * @since 1.7
1997 */
1998 do_action( 'give_donation_form_after_submit', $form_id, $args );
1999 ?>
2000 </fieldset>
2001 <?php
2002 }
2003
2004 add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 );
2005
2006 /**
2007 * Give Donation form submit button.
2008 *
2009 * @param int $form_id The form ID.
2010 * @param array $args
2011 *
2012 * @return string
2013 * @since 1.8.8
2014 */
2015 function give_get_donation_form_submit_button( $form_id, $args = [] ) {
2016
2017 $display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
2018 $display_label_field = apply_filters( 'give_donation_form_submit_button_text', $display_label_field, $form_id, $args );
2019 $display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
2020 ob_start();
2021 ?>
2022 <div class="give-submit-button-wrap give-clearfix">
2023 <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
2024 value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>"/>
2025 <span class="give-loading-animation"></span>
2026 </div>
2027 <?php
2028 return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id, $args );
2029 }
2030
2031 /**
2032 * Show Give Goals.
2033 *
2034 * @param int $form_id The form ID.
2035 * @param array $args An array of form arguments.
2036 *
2037 * @return mixed
2038 * @since 1.6 Add template for Give Goals Shortcode.
2039 * More info is on https://github.com/impress-org/give/issues/411
2040 *
2041 * @since 1.0
2042 */
2043 function give_show_goal_progress( $form_id, $args = [] ) {
2044
2045 ob_start();
2046 give_get_template(
2047 'shortcode-goal',
2048 [
2049 'form_id' => $form_id,
2050 'args' => $args,
2051 ]
2052 );
2053
2054 /**
2055 * Filter progress bar output
2056 *
2057 * @since 2.0
2058 */
2059 echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args );
2060
2061 return true;
2062 }
2063
2064 add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
2065
2066 /**
2067 * Show Give Totals Progress.
2068 *
2069 * @param int $total Total amount based on shortcode parameter.
2070 * @param int $total_goal Total Goal amount passed by Admin.
2071 *
2072 * @return mixed
2073 * @since 2.1
2074 */
2075 function give_show_goal_totals_progress( $total, $total_goal ) {
2076
2077 // Bail out if total goal is set as an array.
2078 if ( isset( $total_goal ) && is_array( $total_goal ) ) {
2079 return false;
2080 }
2081
2082 ob_start();
2083 give_get_template(
2084 'shortcode-totals-progress',
2085 [
2086 'total' => $total,
2087 'total_goal' => $total_goal,
2088 ]
2089 );
2090
2091 echo apply_filters( 'give_total_progress_output', ob_get_clean() );
2092
2093 return true;
2094 }
2095
2096 add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
2097
2098 /**
2099 * Get form content position.
2100 *
2101 * @param $form_id
2102 * @param $args
2103 *
2104 * @return mixed|string
2105 * @since 1.8
2106 */
2107 function give_get_form_content_placement( $form_id, $args ) {
2108 $show_content = '';
2109
2110 if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
2111 // Content positions.
2112 $content_placement = [
2113 'above' => 'give_pre_form',
2114 'below' => 'give_post_form',
2115 ];
2116
2117 // Check if content position already decoded.
2118 if ( in_array( $args['show_content'], $content_placement ) ) {
2119 return $args['show_content'];
2120 }
2121
2122 $show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
2123
2124 } elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
2125 $show_content = give_get_meta( $form_id, '_give_content_placement', true );
2126
2127 }
2128
2129 return $show_content;
2130 }
2131
2132 /**
2133 * Adds Actions to Render Form Content.
2134 *
2135 * @param int $form_id The form ID.
2136 * @param array $args An array of form arguments.
2137 *
2138 * @return void|bool
2139 * @since 1.0
2140 */
2141 function give_form_content( $form_id, $args ) {
2142
2143 $show_content = give_get_form_content_placement( $form_id, $args );
2144
2145 // Bailout.
2146 if ( empty( $show_content ) ) {
2147 return false;
2148 }
2149
2150 // Add action according to value.
2151 add_action( $show_content, 'give_form_display_content', 10, 2 );
2152 }
2153
2154 add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
2155
2156 /**
2157 * Renders Post Form Content.
2158 *
2159 * Displays content for Give forms; fired by action from give_form_content.
2160 *
2161 * @param int $form_id The form ID.
2162 * @param array $args An array of form arguments.
2163 *
2164 * @return void
2165 * @since 1.0
2166 */
2167 function give_form_display_content( $form_id, $args ) {
2168 $content = give_get_meta( $form_id, '_give_form_content', true );
2169 $show_content = give_get_form_content_placement( $form_id, $args );
2170
2171 if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
2172
2173 // Do not restore wpautop if we are still parsing blocks.
2174 $priority = has_filter( 'the_content', '_restore_wpautop_hook' );
2175 if ( false !== $priority && doing_filter( 'the_content' ) ) {
2176 remove_filter( 'the_content', '_restore_wpautop_hook', $priority );
2177 }
2178
2179 $content = apply_filters( 'the_content', $content );
2180
2181 // Restore wpautop after done with blocks parsing.
2182 if ( $priority ) {
2183 // Run wpautop manually if parsing block
2184 $content = wpautop( $content );
2185
2186 add_filter( 'the_content', '_restore_wpautop_hook', $priority );
2187 }
2188 } else {
2189 $content = wpautop( do_shortcode( $content ) );
2190 }
2191
2192 $output = sprintf(
2193 '<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>',
2194 $form_id,
2195 $show_content,
2196 $content
2197 );
2198
2199 /**
2200 * Filter form content html
2201 *
2202 * @param string $output
2203 * @param int $form_id
2204 * @param array $args
2205 *
2206 * @since 1.0
2207 */
2208 echo apply_filters( 'give_form_content_output', $output, $form_id, $args );
2209
2210 // remove action to prevent content output on addition forms on page.
2211 // @see: https://github.com/impress-org/give/issues/634.
2212 remove_action( $show_content, 'give_form_display_content' );
2213 }
2214
2215 /**
2216 * Renders the hidden Checkout fields.
2217 *
2218 * @param int $form_id The form ID.
2219 * @param array $args Shortcode args.
2220 *
2221 * @return void
2222 * @since 1.0
2223 */
2224 function give_checkout_hidden_fields( $form_id, $args = [] ) {
2225
2226 /**
2227 * Fires while rendering hidden checkout fields, before the fields.
2228 *
2229 * @param int $form_id The form ID.
2230 *
2231 * @since 1.0
2232 */
2233 do_action( 'give_hidden_fields_before', $form_id, $args );
2234
2235 if ( is_user_logged_in() ) {
2236 ?>
2237 <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
2238 <?php } ?>
2239 <input type="hidden" name="give_action" value="purchase"/>
2240 <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
2241 <?php
2242 /**
2243 * Fires while rendering hidden checkout fields, after the fields.
2244 *
2245 * @param int $form_id The form ID.
2246 *
2247 * @since 1.0
2248 */
2249 do_action( 'give_hidden_fields_after', $form_id, $args );
2250
2251 }
2252
2253 /**
2254 * Filter Success Page Content.
2255 *
2256 * Applies filters to the success page content.
2257 *
2258 * @param string $content Content before filters.
2259 *
2260 * @return string $content Filtered content.
2261 * @since 1.0
2262 */
2263 function give_filter_success_page_content( $content ) {
2264
2265 $give_options = give_get_settings();
2266
2267 if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
2268 if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
2269 $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
2270 }
2271 }
2272
2273 return $content;
2274 }
2275
2276 add_filter( 'the_content', 'give_filter_success_page_content' );
2277
2278 /**
2279 * Test Mode Frontend Warning.
2280 *
2281 * Displays a notice on the frontend for donation forms.
2282 *
2283 * @since 1.1
2284 */
2285 function give_test_mode_frontend_warning() {
2286
2287 if ( give_is_test_mode() ) {
2288 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>';
2289 }
2290 }
2291
2292 add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
2293
2294 /**
2295 * Members-only Form.
2296 *
2297 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
2298 *
2299 * @param string $final_output
2300 * @param array $args
2301 *
2302 * @return string
2303 * @since 1.4.1
2304 */
2305 function give_members_only_form( $final_output, $args ) {
2306
2307 $form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
2308
2309 // Sanity Check: Must have form_id & not be logged in.
2310 if ( empty( $form_id ) || is_user_logged_in() ) {
2311 return $final_output;
2312 }
2313
2314 // Logged in only and Register / Login set to none.
2315 if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
2316
2317 $final_output = Give_Notices::print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
2318
2319 return apply_filters( 'give_members_only_output', $final_output, $form_id );
2320
2321 }
2322
2323 return $final_output;
2324
2325 }
2326
2327 add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
2328
2329
2330 /**
2331 * Add donation form hidden fields.
2332 *
2333 * @param int $form_id
2334 * @param array $args
2335 * @param Give_Donate_Form $form
2336 *
2337 * @since 1.8.17
2338 */
2339 function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
2340 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
2341 ?>
2342 <input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/>
2343 <input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/>
2344 <input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/>
2345 <input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2346 <input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2347 <?php
2348 // Get the custom option amount.
2349 $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
2350
2351 // If custom amount enabled.
2352 if ( give_is_setting_enabled( $custom_amount ) ) {
2353 ?>
2354 <input type="hidden" name="give-form-minimum"
2355 value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/>
2356 <input type="hidden" name="give-form-maximum"
2357 value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/>
2358 <?php
2359 }
2360
2361 $data_attr = sprintf(
2362 'data-time="%1$s" data-nonce-life="%2$s" data-donor-session="%3$s"',
2363 time(),
2364 give_get_nonce_life(),
2365 absint( Give()->session->has_session() )
2366 );
2367
2368 // WP nonce field.
2369 echo str_replace(
2370 '/>',
2371 "{$data_attr}/>",
2372 give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
2373 );
2374
2375 // Price ID hidden field for variable (multi-level) donation forms.
2376 if ( give_has_variable_prices( $form_id ) ) {
2377 // Get the default price ID.
2378 $default_price = give_form_get_default_level( $form_id );
2379 $price_id = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0;
2380
2381 echo sprintf(
2382 '<input type="hidden" name="give-price-id" value="%s"/>',
2383 $price_id
2384 );
2385 }
2386 }
2387
2388 add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
2389
2390 /**
2391 * Add currency settings on donation form.
2392 *
2393 * @param array $form_html_tags
2394 * @param Give_Donate_Form $form
2395 *
2396 * @return array
2397 * @since 1.8.17
2398 */
2399 function __give_form_add_currency_settings( $form_html_tags, $form ) {
2400 $form_currency = give_get_currency( $form->ID );
2401 $currency_settings = give_get_currency_formatting_settings( $form_currency );
2402
2403 // Check if currency exist.
2404 if ( empty( $currency_settings ) ) {
2405 return $form_html_tags;
2406 }
2407
2408 $form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2409 $form_html_tags['data-currency_code'] = $form_currency;
2410
2411 if ( ! empty( $currency_settings ) ) {
2412 foreach ( $currency_settings as $key => $value ) {
2413 $form_html_tags[ "data-{$key}" ] = $value;
2414 }
2415 }
2416
2417 return $form_html_tags;
2418 }
2419
2420 add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2421
2422 /**
2423 * Adds classes to progress bar container.
2424 *
2425 * @param string $class_goal
2426 *
2427 * @return string
2428 * @since 2.1
2429 */
2430 function add_give_goal_progress_class( $class_goal ) {
2431 $class_goal = 'progress progress-striped active';
2432
2433 return $class_goal;
2434 }
2435
2436 /**
2437 * Adds classes to progress bar span tag.
2438 *
2439 * @param string $class_bar
2440 *
2441 * @return string
2442 * @since 2.1
2443 */
2444 function add_give_goal_progress_bar_class( $class_bar ) {
2445 $class_bar = 'bar';
2446
2447 return $class_bar;
2448 }
2449
2450 /**
2451 * Add a class to the form wrap on the grid page.
2452 *
2453 * @param array $class Array of form wrapper classes.
2454 * @param int $id ID of the form.
2455 * @param array $args Additional args.
2456 *
2457 * @return array
2458 * @since 2.1
2459 */
2460 function add_class_for_form_grid( $class, $id, $args ) {
2461 $class[] = 'give-form-grid-wrap';
2462
2463 foreach ( $class as $index => $item ) {
2464 if ( false !== strpos( $item, 'give-display-' ) ) {
2465 unset( $class[ $index ] );
2466 }
2467 }
2468
2469 return $class;
2470 }
2471
2472 /**
2473 * Add hidden field to Form Grid page
2474 *
2475 * @param int $form_id The form ID.
2476 * @param array $args An array of form arguments.
2477 * @param Give_Donate_Form $form Form object.
2478 *
2479 * @since 2.1
2480 */
2481 function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
2482 echo '<input type="hidden" name="is-form-grid" value="true" />';
2483 }
2484
2485 /**
2486 * Redirect to the same paginated URL on the Form Grid page
2487 * and adds query parameters to open the popup again after
2488 * redirection.
2489 *
2490 * @param string $redirect URL for redirection.
2491 * @param array $args Array of additional args.
2492 *
2493 * @return string
2494 * @since 2.1
2495 */
2496 function give_redirect_and_popup_form( $redirect, $args ) {
2497
2498 // Check the page has Form Grid.
2499 $is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
2500
2501 if ( 'true' === $is_form_grid ) {
2502
2503 $payment_mode = give_clean( $_POST['payment-mode'] );
2504 $form_id = $args['form-id'];
2505
2506 // Get the URL without Query parameters.
2507 $redirect = strtok( $redirect, '?' );
2508
2509 // Add query parameters 'form-id' and 'payment-mode'.
2510 $redirect = add_query_arg(
2511 [
2512 'form-id' => $form_id,
2513 'payment-mode' => $payment_mode,
2514 ],
2515 $redirect
2516 );
2517 }
2518
2519 // Return the modified URL.
2520 return esc_url_raw( $redirect );
2521 }
2522
2523 add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );
2524