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