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