PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.5.11
GiveWP – Donation Plugin and Fundraising Platform v2.5.11
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
2490 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
750 /**
751 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
752 *
753 * @param int $form_id The form ID.
754 *
755 * @return void
756 * @see For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
757 *
758 * @since 1.0
759 *
760 */
761 function give_user_info_fields( $form_id ) {
762
763 // Get user info.
764 $give_user_info = _give_get_prefill_form_field_values( $form_id );
765 $title = ! empty( $give_user_info['give_title'] ) ? $give_user_info['give_title'] : '';
766 $first_name = ! empty( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : '';
767 $last_name = ! empty( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : '';
768 $company_name = ! empty( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : '';
769 $email = ! empty( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : '';
770 $title_prefixes = give_get_name_title_prefixes( $form_id );
771
772 /**
773 * Fire before user personal information fields
774 *
775 * @since 1.7
776 */
777 do_action( 'give_donation_form_before_personal_info', $form_id );
778
779 $title_prefix_classes = '';
780 if ( give_is_name_title_prefix_enabled( $form_id ) ) {
781 $title_prefix_classes = 'give-title-prefix-wrap';
782 }
783 ?>
784 <fieldset id="give_checkout_user_info" class="<?php echo esc_html( $title_prefix_classes ); ?>">
785 <legend>
786 <?php echo esc_html( apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ) ); ?>
787 </legend>
788
789 <?php if ( give_is_name_title_prefix_enabled( $form_id ) && is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) { ?>
790 <p id="give-title-wrap" class="form-row form-row-title form-row-responsive">
791 <label class="give-label" for="give-title">
792 <?php esc_attr_e( 'Title', 'give' ); ?>
793 <?php if ( give_field_is_required( 'give_title', $form_id ) ) : ?>
794 <span class="give-required-indicator">*</span>
795 <?php endif ?>
796 <?php echo Give()->tooltips->render_help( __( 'Title is used to personalize your donation record..', 'give' ) ); ?>
797 </label>
798 <select
799 class="give-input required"
800 type="text"
801 name="give_title"
802 id="give-title"
803 <?php echo( give_field_is_required( 'give_title', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
804 >
805 <?php foreach ( $title_prefixes as $key => $value ) { ?>
806 <option
807 value="<?php echo esc_html( $value ); ?>" <?php selected( $value, $title, true ); ?>><?php echo esc_html( $value ); ?></option>
808 <?php } ?>
809 </select>
810 </p>
811 <?php } ?>
812
813 <p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive">
814 <label class="give-label" for="give-first">
815 <?php esc_attr_e( 'First Name', 'give' ); ?>
816 <?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
817 <span class="give-required-indicator">*</span>
818 <?php endif ?>
819 <?php echo Give()->tooltips->render_help( __( 'First Name is used to personalize your donation record.', 'give' ) ); ?>
820 </label>
821 <input
822 class="give-input required"
823 type="text"
824 name="give_first"
825 autocomplete="given-name"
826 placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>"
827 id="give-first"
828 value="<?php echo esc_html( $first_name ); ?>"
829 <?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
830 />
831 </p>
832
833 <p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive">
834 <label class="give-label" for="give-last">
835 <?php esc_attr_e( 'Last Name', 'give' ); ?>
836 <?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
837 <span class="give-required-indicator">*</span>
838 <?php endif ?>
839 <?php echo Give()->tooltips->render_help( __( 'Last Name is used to personalize your donation record.', 'give' ) ); ?>
840 </label>
841
842 <input
843 class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>"
844 type="text"
845 name="give_last"
846 autocomplete="family-name"
847 id="give-last"
848 placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>"
849 value="<?php echo esc_html( $last_name ); ?>"
850 <?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
851 />
852 </p>
853
854 <?php if ( give_is_company_field_enabled( $form_id ) ) : ?>
855 <?php $give_company = give_field_is_required( 'give_company_name', $form_id ); ?>
856 <p id="give-company-wrap" class="form-row form-row-wide">
857 <label class="give-label" for="give-company">
858 <?php esc_attr_e( 'Company Name', 'give' ); ?>
859 <?php if ( $give_company ) : ?>
860 <span class="give-required-indicator">*</span>
861 <?php endif; ?>
862 <?php echo Give()->tooltips->render_help( __( 'Donate on behalf of Company', 'give' ) ); ?>
863 </label>
864 <input
865 class="give-input<?php echo( $give_company ? ' required' : '' ); ?>"
866 type="text"
867 name="give_company_name"
868 placeholder="<?php esc_attr_e( 'Company Name', 'give' ); ?>"
869 id="give-company"
870 value="<?php echo esc_html( $company_name ); ?>"
871 <?php echo( $give_company ? ' required aria-required="true" ' : '' ); ?>
872 />
873 </p>
874 <?php endif ?>
875
876 <?php
877 /**
878 * Fire before user email field
879 *
880 * @since 1.7
881 */
882 do_action( 'give_donation_form_before_email', $form_id );
883 ?>
884 <p id="give-email-wrap" class="form-row form-row-wide">
885 <label class="give-label" for="give-email">
886 <?php esc_attr_e( 'Email Address', 'give' ); ?>
887 <?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
888 <span class="give-required-indicator">*</span>
889 <?php } ?>
890 <?php echo Give()->tooltips->render_help( __( 'We will send the donation receipt to this address.', 'give' ) ); ?>
891 </label>
892 <input
893 class="give-input required"
894 type="email"
895 name="give_email"
896 autocomplete="email"
897 placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>"
898 id="give-email"
899 value="<?php echo esc_html( $email ); ?>"
900 <?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
901 />
902
903 </p>
904
905 <?php if ( give_is_anonymous_donation_field_enabled( $form_id ) ) : ?>
906 <?php $is_anonymous_donation = isset( $_POST['give_anonymous_donation'] ) ? absint( $_POST['give_anonymous_donation'] ) : 0; ?>
907 <p id="give-anonymous-donation-wrap" class="form-row form-row-wide">
908 <label class="give-label" for="give-anonymous-donation">
909 <input
910 type="checkbox"
911 class="give-input<?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required' : '' ); ?>"
912 name="give_anonymous_donation"
913 id="give-anonymous-donation"
914 value="1"
915 <?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
916 <?php checked( 1, $is_anonymous_donation ); ?>
917 >
918 <?php
919 /**
920 * Filters the checkbox label.
921 *
922 * @since 2.4.1
923 */
924 echo apply_filters( 'give_anonymous_donation_checkbox_label', __( 'Make this an anonymous donation.', 'give' ), $form_id );
925
926 if ( give_field_is_required( 'give_comment', $form_id ) ) {
927 ?>
928 <span class="give-required-indicator">*</span>
929 <?php } ?>
930 <?php
931 // Conditional tooltip text when comments enabled:
932 // https://github.com/impress-org/give/issues/3911
933 $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' );
934
935 echo Give()->tooltips->render_help( $anonymous_donation_tooltip );
936 ?>
937
938 </label>
939 </p>
940 <?php endif; ?>
941
942 <?php if ( give_is_donor_comment_field_enabled( $form_id ) ) : ?>
943 <p id="give-comment-wrap" class="form-row form-row-wide">
944 <label class="give-label" for="give-comment">
945 <?php _e( 'Comment', 'give' ); ?>
946 <?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?>
947 <span class="give-required-indicator">*</span>
948 <?php } ?>
949 <?php echo Give()->tooltips->render_help( __( 'Would you like to add a comment to this donation?', 'give' ) ); ?>
950 </label>
951
952 <textarea
953 class="give-input<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required' : '' ); ?>"
954 name="give_comment"
955 placeholder="<?php _e( 'Leave a comment', 'give' ); ?>"
956 id="give-comment"
957 <?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
958 ><?php echo isset( $_POST['give_comment'] ) ? give_clean( $_POST['give_comment'] ) : ''; ?></textarea>
959
960 </p>
961 <?php endif; ?>
962 <?php
963 /**
964 * Fire after user email field
965 *
966 * @since 1.7
967 */
968 do_action( 'give_donation_form_after_email', $form_id );
969
970 /**
971 * Fire after personal email field
972 *
973 * @since 1.7
974 */
975 do_action( 'give_donation_form_user_info', $form_id );
976 ?>
977 </fieldset>
978 <?php
979 /**
980 * Fire after user personal information fields
981 *
982 * @since 1.7
983 */
984 do_action( 'give_donation_form_after_personal_info', $form_id );
985 }
986
987 add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
988 add_action( 'give_register_fields_before', 'give_user_info_fields' );
989
990 /**
991 * Renders the credit card info form.
992 *
993 * @param int $form_id The form ID.
994 *
995 * @return void
996 * @since 1.0
997 *
998 */
999 function give_get_cc_form( $form_id ) {
1000
1001 ob_start();
1002
1003 /**
1004 * Fires while rendering credit card info form, before the fields.
1005 *
1006 * @param int $form_id The form ID.
1007 *
1008 * @since 1.0
1009 *
1010 */
1011 do_action( 'give_before_cc_fields', $form_id );
1012 ?>
1013 <fieldset id="give_cc_fields-<?php echo $form_id; ?>" class="give-do-validate">
1014 <legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
1015 <?php if ( is_ssl() ) : ?>
1016 <div id="give_secure_site_wrapper-<?php echo $form_id; ?>">
1017 <span class="give-icon padlock"></span>
1018 <span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
1019 </div>
1020 <?php endif; ?>
1021 <p id="give-card-number-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive">
1022 <label for="card_number-<?php echo $form_id; ?>" class="give-label">
1023 <?php _e( 'Card Number', 'give' ); ?>
1024 <span class="give-required-indicator">*</span>
1025 <?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?>
1026 <span class="card-type"></span>
1027 </label>
1028
1029 <input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id; ?>"
1030 class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>"
1031 required aria-required="true"/>
1032 </p>
1033
1034 <p id="give-card-cvc-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-responsive">
1035 <label for="card_cvc-<?php echo $form_id; ?>" class="give-label">
1036 <?php _e( 'CVC', 'give' ); ?>
1037 <span class="give-required-indicator">*</span>
1038 <?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?>
1039 </label>
1040
1041 <input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id; ?>"
1042 class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>"
1043 required aria-required="true"/>
1044 </p>
1045
1046 <p id="give-card-name-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive">
1047 <label for="card_name-<?php echo $form_id; ?>" class="give-label">
1048 <?php _e( 'Cardholder Name', 'give' ); ?>
1049 <span class="give-required-indicator">*</span>
1050 <?php echo Give()->tooltips->render_help( __( 'The name of the credit card account holder.', 'give' ) ); ?>
1051 </label>
1052
1053 <input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id; ?>"
1054 class="card-name give-input required" placeholder="<?php esc_attr_e( 'Cardholder Name', 'give' ); ?>"
1055 required aria-required="true"/>
1056 </p>
1057 <?php
1058 /**
1059 * Fires while rendering credit card info form, before expiration fields.
1060 *
1061 * @param int $form_id The form ID.
1062 *
1063 * @since 1.0
1064 *
1065 */
1066 do_action( 'give_before_cc_expiration' );
1067 ?>
1068 <p class="card-expiration form-row form-row-one-third form-row-responsive">
1069 <label for="card_expiry-<?php echo $form_id; ?>" class="give-label">
1070 <?php _e( 'Expiration', 'give' ); ?>
1071 <span class="give-required-indicator">*</span>
1072 <?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?>
1073 </label>
1074
1075 <input type="hidden" id="card_exp_month-<?php echo $form_id; ?>" name="card_exp_month"
1076 class="card-expiry-month"/>
1077 <input type="hidden" id="card_exp_year-<?php echo $form_id; ?>" name="card_exp_year"
1078 class="card-expiry-year"/>
1079
1080 <input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id; ?>"
1081 class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>"
1082 required aria-required="true"/>
1083 </p>
1084 <?php
1085 /**
1086 * Fires while rendering credit card info form, after expiration fields.
1087 *
1088 * @param int $form_id The form ID.
1089 *
1090 * @since 1.0
1091 *
1092 */
1093 do_action( 'give_after_cc_expiration', $form_id );
1094 ?>
1095 </fieldset>
1096 <?php
1097 /**
1098 * Fires while rendering credit card info form, before the fields.
1099 *
1100 * @param int $form_id The form ID.
1101 *
1102 * @since 1.0
1103 *
1104 */
1105 do_action( 'give_after_cc_fields', $form_id );
1106
1107 echo ob_get_clean();
1108 }
1109
1110 add_action( 'give_cc_form', 'give_get_cc_form' );
1111
1112 /**
1113 * Outputs the default credit card address fields.
1114 *
1115 * @param int $form_id The form ID.
1116 *
1117 * @return void
1118 * @since 1.0
1119 *
1120 */
1121 function give_default_cc_address_fields( $form_id ) {
1122 // Get user info.
1123 $give_user_info = _give_get_prefill_form_field_values( $form_id );
1124
1125 ob_start();
1126 ?>
1127 <fieldset id="give_cc_address" class="cc-address">
1128 <legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
1129 <?php
1130 /**
1131 * Fires while rendering credit card billing form, before address fields.
1132 *
1133 * @param int $form_id The form ID.
1134 *
1135 * @since 1.0
1136 *
1137 */
1138 do_action( 'give_cc_billing_top' );
1139
1140 // For Country.
1141 $selected_country = give_get_country();
1142 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
1143 $selected_country = $give_user_info['billing_country'];
1144 }
1145 $countries = give_get_country_list();
1146
1147 // For state.
1148 $selected_state = '';
1149 if ( $selected_country === give_get_country() ) {
1150 // Get default selected state by admin.
1151 $selected_state = give_get_state();
1152 }
1153 // Get the last payment made by user states.
1154 if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
1155 $selected_state = $give_user_info['card_state'];
1156 }
1157 // Get the country code.
1158 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
1159 $selected_country = $give_user_info['billing_country'];
1160 }
1161
1162
1163 // Get the country list that does not require city.
1164 $city_required = ! array_key_exists( $selected_country, give_city_not_required_country_list() );
1165
1166 ?>
1167 <p id="give-card-country-wrap" class="form-row form-row-wide">
1168 <label for="billing_country" class="give-label">
1169 <?php esc_html_e( 'Country', 'give' ); ?>
1170 <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
1171 <span class="give-required-indicator">*</span>
1172 <?php endif; ?>
1173 <span class="give-tooltip give-icon give-icon-question"
1174 data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
1175 </label>
1176
1177 <select
1178 name="billing_country"
1179 autocomplete="country"
1180 id="billing_country"
1181 class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
1182 <?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1183 >
1184 <?php
1185 foreach ( $countries as $country_code => $country ) {
1186 echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
1187 }
1188 ?>
1189 </select>
1190 </p>
1191
1192 <p id="give-card-address-wrap" class="form-row form-row-wide">
1193 <label for="card_address" class="give-label">
1194 <?php _e( 'Address 1', 'give' ); ?>
1195 <?php
1196 if ( give_field_is_required( 'card_address', $form_id ) ) :
1197 ?>
1198 <span class="give-required-indicator">*</span>
1199 <?php endif; ?>
1200 <?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?>
1201 </label>
1202
1203 <input
1204 type="text"
1205 id="card_address"
1206 name="card_address"
1207 autocomplete="address-line1"
1208 class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
1209 placeholder="<?php _e( 'Address line 1', 'give' ); ?>"
1210 value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
1211 <?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1212 />
1213 </p>
1214
1215 <p id="give-card-address-2-wrap" class="form-row form-row-wide">
1216 <label for="card_address_2" class="give-label">
1217 <?php _e( 'Address 2', 'give' ); ?>
1218 <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
1219 <span class="give-required-indicator">*</span>
1220 <?php endif; ?>
1221 <?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?>
1222 </label>
1223
1224 <input
1225 type="text"
1226 id="card_address_2"
1227 name="card_address_2"
1228 autocomplete="address-line2"
1229 class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
1230 placeholder="<?php _e( 'Address line 2', 'give' ); ?>"
1231 value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
1232 <?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1233 />
1234 </p>
1235
1236 <p id="give-card-city-wrap" class="form-row form-row-wide">
1237 <label for="card_city" class="give-label">
1238 <?php _e( 'City', 'give' ); ?>
1239 <?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
1240 <span class="give-required-indicator <?php echo( $city_required ? '' : 'give-hidden' ); ?>">*</span>
1241 <?php endif; ?>
1242 <?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?>
1243 </label>
1244 <input
1245 type="text"
1246 id="card_city"
1247 name="card_city"
1248 autocomplete="address-level2"
1249 class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
1250 placeholder="<?php _e( 'City', 'give' ); ?>"
1251 value="<?php echo( isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : '' ); ?>"
1252 <?php echo( give_field_is_required( 'card_city', $form_id ) && $city_required ? ' required aria-required="true" ' : '' ); ?>
1253 />
1254 </p>
1255
1256 <?php
1257 /**
1258 * State field logic.
1259 */
1260 $state_label = __( 'State', 'give' );
1261 $states_label = give_get_states_label();
1262 // Check if $country code exists in the array key for states label.
1263 if ( array_key_exists( $selected_country, $states_label ) ) {
1264 $state_label = $states_label[ $selected_country ];
1265 }
1266 $states = give_get_states( $selected_country );
1267 // Get the country list that do not have any states.
1268 $no_states_country = give_no_states_country_list();
1269 // Get the country list that does not require states.
1270 $states_not_required_country_list = give_states_not_required_country_list();
1271 // Used to determine if state is required.
1272 $require_state = ! array_key_exists( $selected_country, $no_states_country ) && give_field_is_required( 'card_state', $form_id );
1273 // Used to determine is state input should be marked as required.
1274 $validate_state = ! array_key_exists( $selected_country, $states_not_required_country_list ) && give_field_is_required( 'card_state', $form_id );
1275
1276 ?>
1277 <p id="give-card-state-wrap"
1278 class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && ! $require_state ) ? 'give-hidden' : ''; ?> ">
1279 <label for="card_state" class="give-label">
1280 <span class="state-label-text"><?php echo $state_label; ?></span>
1281 <span
1282 class="give-required-indicator <?php echo $validate_state ? '' : 'give-hidden'; ?> ">*</span>
1283 <span class="give-tooltip give-icon give-icon-question"
1284 data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1285 </label>
1286 <?php
1287
1288 if ( ! empty( $states ) ) :
1289 ?>
1290 <select
1291 name="card_state"
1292 autocomplete="address-level1"
1293 id="card_state"
1294 class="card_state give-select<?php echo $validate_state ? ' required' : ''; ?>"
1295 <?php echo $validate_state ? ' required aria-required="true" ' : ''; ?>>
1296 <?php
1297 foreach ( $states as $state_code => $state ) {
1298 echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
1299 }
1300 ?>
1301 </select>
1302 <?php else : ?>
1303 <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1304 placeholder="<?php echo $state_label; ?>" value="<?php echo $selected_state; ?>"
1305 <?php echo $validate_state ? ' required aria-required="true" ' : ''; ?>
1306 />
1307 <?php endif; ?>
1308 </p>
1309
1310 <p id="give-card-zip-wrap" class="form-row <?php echo $require_state ? 'form-row-last' : ''; ?> form-row-responsive">
1311 <label for="card_zip" class="give-label">
1312 <?php _e( 'Zip / Postal Code', 'give' ); ?>
1313 <?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
1314 <span class="give-required-indicator">*</span>
1315 <?php endif; ?>
1316 <?php echo Give()->tooltips->render_help( __( 'The zip or postal code for your billing address.', 'give' ) ); ?>
1317 </label>
1318
1319 <input
1320 type="text"
1321 size="4"
1322 id="card_zip"
1323 name="card_zip"
1324 autocomplete="postal-code"
1325 class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>"
1326 placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>"
1327 value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
1328 <?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1329 />
1330 </p>
1331 <?php
1332 /**
1333 * Fires while rendering credit card billing form, after address fields.
1334 *
1335 * @param int $form_id The form ID.
1336 *
1337 * @since 1.0
1338 *
1339 */
1340 do_action( 'give_cc_billing_bottom' );
1341 ?>
1342 </fieldset>
1343 <?php
1344 echo ob_get_clean();
1345 }
1346
1347 add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1348
1349
1350 /**
1351 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1352 * is provided for the user to create an account.
1353 *
1354 * @param int $form_id The form ID.
1355 *
1356 * @return string
1357 * @since 1.0
1358 *
1359 */
1360 function give_get_register_fields( $form_id ) {
1361
1362 global $user_ID;
1363
1364 if ( is_user_logged_in() ) {
1365 $user_data = get_userdata( $user_ID );
1366 }
1367
1368 $show_register_form = give_show_login_register_option( $form_id );
1369
1370 ob_start();
1371 ?>
1372 <fieldset id="give-register-fields-<?php echo $form_id; ?>">
1373
1374 <?php
1375 /**
1376 * Fires while rendering user registration form, before registration fields.
1377 *
1378 * @param int $form_id The form ID.
1379 *
1380 * @since 1.0
1381 *
1382 */
1383 do_action( 'give_register_fields_before', $form_id );
1384 ?>
1385
1386 <fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
1387 <?php
1388 /**
1389 * Fires while rendering user registration form, before account fields.
1390 *
1391 * @param int $form_id The form ID.
1392 *
1393 * @since 1.0
1394 *
1395 */
1396 do_action( 'give_register_account_fields_before', $form_id );
1397
1398 $class = ( 'registration' === $show_register_form ) ? 'form-row-wide' : 'form-row-first';
1399 ?>
1400 <div id="give-create-account-wrap-<?php echo $form_id; ?>"
1401 class="form-row <?php echo esc_attr( $class ); ?> form-row-responsive">
1402 <label for="give-create-account-<?php echo $form_id; ?>">
1403 <?php
1404 // Add attributes to checkbox, if Guest Checkout is disabled.
1405 $is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true );
1406 $id = 'give-create-account-' . $form_id;
1407 if ( ! give_is_setting_enabled( $is_guest_checkout ) ) {
1408 echo Give()->tooltips->render(
1409 array(
1410 'tag_content' => sprintf(
1411 '<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />',
1412 $id
1413 ),
1414 'label' => __( 'Registration is required to donate.', 'give' ),
1415 )
1416 );
1417 } else {
1418 ?>
1419 <input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>"
1420 class="give-input"/>
1421 <?php
1422 }
1423
1424 _e( 'Create an account', 'give' );
1425 echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) );
1426 echo str_replace(
1427 '/>',
1428 'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
1429 give_get_nonce_field( "give_form_create_user_nonce_{$form_id}", 'give-form-user-register-hash', false )
1430 );
1431 ?>
1432 </label>
1433 </div>
1434
1435 <?php if ( 'both' === $show_register_form ) { ?>
1436 <div class="give-login-account-wrap form-row form-row-last form-row-responsive">
1437 <p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1438 <a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1439 data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1440 </p>
1441 <p class="give-loading-text">
1442 <span class="give-loading-animation"></span>
1443 </p>
1444 </div>
1445 <?php } ?>
1446
1447 <?php
1448 /**
1449 * Fires while rendering user registration form, after account fields.
1450 *
1451 * @param int $form_id The form ID.
1452 *
1453 * @since 1.0
1454 *
1455 */
1456 do_action( 'give_register_account_fields_after', $form_id );
1457 ?>
1458 </fieldset>
1459
1460 <?php
1461 /**
1462 * Fires while rendering user registration form, after registration fields.
1463 *
1464 * @param int $form_id The form ID.
1465 *
1466 * @since 1.0
1467 *
1468 */
1469 do_action( 'give_register_fields_after', $form_id );
1470 ?>
1471
1472 <input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1473
1474 <?php
1475 /**
1476 * Fire after register or login form render
1477 *
1478 * @since 1.7
1479 */
1480 do_action( 'give_donation_form_user_info', $form_id );
1481 ?>
1482
1483 </fieldset>
1484 <?php
1485 echo ob_get_clean();
1486 }
1487
1488 add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1489
1490 /**
1491 * Gets the login fields for the login form on the checkout. This function hooks
1492 * on the give_donation_form_login_fields to display the login form if a user already
1493 * had an account.
1494 *
1495 * @param int $form_id The form ID.
1496 *
1497 * @return string
1498 * @since 1.0
1499 *
1500 */
1501 function give_get_login_fields( $form_id ) {
1502
1503 $form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
1504 $show_register_form = give_show_login_register_option( $form_id );
1505
1506 ob_start();
1507 ?>
1508 <fieldset id="give-login-fields-<?php echo $form_id; ?>">
1509 <legend>
1510 <?php
1511 echo apply_filters( 'give_account_login_fieldset_heading', __( 'Log In to Your Account', 'give' ) );
1512 if ( ! give_logged_in_only( $form_id ) ) {
1513 echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>';
1514 }
1515 ?>
1516 </legend>
1517 <?php if ( $show_register_form == 'both' ) { ?>
1518 <p class="give-new-account-link">
1519 <?php _e( 'Don\'t have an account?', 'give' ); ?>&nbsp;
1520 <a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel"
1521 data-action="give_checkout_register">
1522 <?php
1523 if ( give_logged_in_only( $form_id ) ) {
1524 _e( 'Register as a part of your donation &raquo;', 'give' );
1525 } else {
1526 _e( 'Register or donate as a guest &raquo;', 'give' );
1527 }
1528 ?>
1529 </a>
1530 </p>
1531 <p class="give-loading-text">
1532 <span class="give-loading-animation"></span>
1533 </p>
1534 <?php } ?>
1535 <?php
1536 /**
1537 * Fires while rendering checkout login form, before the fields.
1538 *
1539 * @param int $form_id The form ID.
1540 *
1541 * @since 1.0
1542 *
1543 */
1544 do_action( 'give_donation_form_login_fields_before', $form_id );
1545 ?>
1546 <div class="give-user-login-fields-container">
1547 <div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive">
1548 <label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
1549 <?php _e( 'Username or Email Address', 'give' ); ?>
1550 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1551 <span class="give-required-indicator">*</span>
1552 <?php } ?>
1553 </label>
1554
1555 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1556 type="text"
1557 name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value=""
1558 placeholder="<?php _e( 'Your username or email', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1559 </div>
1560
1561 <div id="give-user-pass-wrap-<?php echo $form_id; ?>"
1562 class="give_login_password form-row form-row-last form-row-responsive">
1563 <label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
1564 <?php _e( 'Password', 'give' ); ?>
1565 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1566 <span class="give-required-indicator">*</span>
1567 <?php } ?>
1568 </label>
1569 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1570 type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>"
1571 placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1572 <?php if ( give_logged_in_only( $form_id ) ) : ?>
1573 <input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1574 <?php endif; ?>
1575 </div>
1576
1577 <div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
1578 <span class="give-forgot-password ">
1579 <a href="<?php echo wp_lostpassword_url(); ?>"
1580 target="_blank"><?php _e( 'Reset Password', 'give' ); ?></a>
1581 </span>
1582 </div>
1583 </div>
1584
1585
1586 <div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
1587 <input type="submit" class="give-submit give-btn button" name="give_login_submit"
1588 value="<?php _e( 'Login', 'give' ); ?>"/>
1589 <?php if ( $show_register_form !== 'login' ) { ?>
1590 <input type="button" data-action="give_cancel_login"
1591 class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1592 value="<?php _e( 'Cancel', 'give' ); ?>"/>
1593 <?php } ?>
1594 <span class="give-loading-animation"></span>
1595 </div>
1596 <?php
1597 /**
1598 * Fires while rendering checkout login form, after the fields.
1599 *
1600 * @param int $form_id The form ID.
1601 *
1602 * @since 1.0
1603 *
1604 */
1605 do_action( 'give_donation_form_login_fields_after', $form_id );
1606 ?>
1607 </fieldset><!--end #give-login-fields-->
1608 <?php
1609 echo ob_get_clean();
1610 }
1611
1612 add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1613
1614 /**
1615 * Payment Mode Select.
1616 *
1617 * Renders the payment mode form by getting all the enabled payment gateways and
1618 * outputting them as radio buttons for the user to choose the payment gateway. If
1619 * a default payment gateway has been chosen from the Give Settings, it will be
1620 * automatically selected.
1621 *
1622 * @param int $form_id The form ID.
1623 *
1624 * @return void
1625 * @since 1.0
1626 *
1627 */
1628 function give_payment_mode_select( $form_id, $args ) {
1629
1630 $gateways = give_get_enabled_payment_gateways( $form_id );
1631 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1632
1633 /**
1634 * Fires while selecting payment gateways, before the fields.
1635 *
1636 * @param int $form_id The form ID.
1637 *
1638 * @since 1.7
1639 *
1640 */
1641 do_action( 'give_payment_mode_top', $form_id );
1642 ?>
1643
1644 <fieldset id="give-payment-mode-select"
1645 <?php
1646 if ( count( $gateways ) <= 1 ) {
1647 echo 'style="display: none;"';
1648 }
1649 ?>
1650 >
1651 <?php
1652 /**
1653 * Fires while selecting payment gateways, before the wrap div.
1654 *
1655 * @param int $form_id The form ID.
1656 *
1657 * @since 1.7
1658 *
1659 */
1660 do_action( 'give_payment_mode_before_gateways_wrap' );
1661 ?>
1662 <legend
1663 class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
1664 <span class="give-loading-text"><span
1665 class="give-loading-animation"></span>
1666 </span>
1667 </legend>
1668
1669 <div id="give-payment-mode-wrap">
1670 <?php
1671 /**
1672 * Fires while selecting payment gateways, before the gateways list.
1673 *
1674 * @since 1.7
1675 */
1676 do_action( 'give_payment_mode_before_gateways' )
1677 ?>
1678 <ul id="give-gateway-radio-list">
1679 <?php
1680 /**
1681 * Loop through the active payment gateways.
1682 */
1683 $selected_gateway = give_get_chosen_gateway( $form_id );
1684 $give_settings = give_get_settings();
1685 $gateways_label = array_key_exists( 'gateways_label', $give_settings ) ?
1686 $give_settings['gateways_label'] :
1687 array();
1688
1689 foreach ( $gateways as $gateway_id => $gateway ) :
1690 // Determine the default gateway.
1691 $checked = checked( $gateway_id, $selected_gateway, false );
1692 $checked_class = $checked ? ' class="give-gateway-option-selected"' : '';
1693 $is_payment_method_visible = isset( $gateway['is_visible'] ) ? $gateway['is_visible'] : true;
1694
1695 if ( true === $is_payment_method_visible ) {
1696 ?>
1697 <li<?php echo $checked_class; ?>>
1698 <input type="radio" name="payment-mode" class="give-gateway"
1699 id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1700 value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
1701
1702 <?php
1703 $label = $gateway['checkout_label'];
1704 if ( ! empty( $gateways_label[ $gateway_id ] ) ) {
1705 $label = $gateways_label[ $gateway_id ];
1706 }
1707 ?>
1708 <label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1709 class="give-gateway-option"
1710 id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $label ); ?></label>
1711 </li>
1712 <?php
1713 }
1714 endforeach;
1715 ?>
1716 </ul>
1717 <?php
1718 /**
1719 * Fires while selecting payment gateways, before the gateways list.
1720 *
1721 * @since 1.7
1722 */
1723 do_action( 'give_payment_mode_after_gateways' );
1724 ?>
1725 </div>
1726 <?php
1727 /**
1728 * Fires while selecting payment gateways, after the wrap div.
1729 *
1730 * @param int $form_id The form ID.
1731 *
1732 * @since 1.7
1733 *
1734 */
1735 do_action( 'give_payment_mode_after_gateways_wrap' );
1736 ?>
1737 </fieldset>
1738
1739 <?php
1740 /**
1741 * Fires while selecting payment gateways, after the fields.
1742 *
1743 * @param int $form_id The form ID.
1744 *
1745 * @since 1.7
1746 *
1747 */
1748 do_action( 'give_payment_mode_bottom', $form_id );
1749 ?>
1750
1751 <div id="give_purchase_form_wrap">
1752
1753 <?php
1754 /**
1755 * Fire after payment field render.
1756 *
1757 * @since 1.7
1758 */
1759 do_action( 'give_donation_form', $form_id, $args );
1760 ?>
1761
1762 </div>
1763
1764 <?php
1765 /**
1766 * Fire after donation form render.
1767 *
1768 * @since 1.7
1769 */
1770 do_action( 'give_donation_form_wrap_bottom', $form_id );
1771 }
1772
1773 add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 );
1774
1775 /**
1776 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1777 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1778 * set in the Give Settings.
1779 *
1780 * @param int $form_id The form ID.
1781 *
1782 * @return bool
1783 * @since 1.0
1784 *
1785 */
1786 function give_terms_agreement( $form_id ) {
1787 $form_option = give_get_meta( $form_id, '_give_terms_option', true );
1788
1789 // Bailout if per form and global term and conditions is not setup.
1790 if (
1791 give_is_setting_enabled( $form_option, 'global' )
1792 && give_is_setting_enabled( give_get_option( 'terms' ) )
1793 ) {
1794 $label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1795 $terms = $terms = give_get_option( 'agreement_text', '' );
1796 $edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1797
1798 } elseif ( give_is_setting_enabled( $form_option ) ) {
1799 $label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1800 $terms = give_get_meta( $form_id, '_give_agree_text', true );
1801 $edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1802
1803 } else {
1804 return false;
1805 }
1806
1807 // Bailout: Check if term and conditions text is empty or not.
1808 if ( empty( $terms ) ) {
1809 if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1810 echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
1811 }
1812
1813 return false;
1814 }
1815
1816 /**
1817 * Filter the form term content
1818 *
1819 * @since 2.1.5
1820 */
1821 $terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id );
1822
1823 ?>
1824 <fieldset id="give_terms_agreement">
1825 <legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
1826 <div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
1827 <?php
1828 /**
1829 * Fires while rendering terms of agreement, before the fields.
1830 *
1831 * @since 1.0
1832 */
1833 do_action( 'give_before_terms' );
1834
1835 echo $terms;
1836 /**
1837 * Fires while rendering terms of agreement, after the fields.
1838 *
1839 * @since 1.0
1840 */
1841 do_action( 'give_after_terms' );
1842 ?>
1843 </div>
1844 <div id="give_show_terms">
1845 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1846 aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1847 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1848 aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1849 </div>
1850
1851 <input name="give_agree_to_terms" class="required" type="checkbox"
1852 id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
1853 <label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
1854
1855 </fieldset>
1856 <?php
1857 }
1858
1859 add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1860
1861 /**
1862 * Checkout Final Total.
1863 *
1864 * Shows the final donation total at the bottom of the checkout page.
1865 *
1866 * @param int $form_id The form ID.
1867 *
1868 * @return void
1869 * @since 1.0
1870 *
1871 */
1872 function give_checkout_final_total( $form_id ) {
1873
1874 $total = isset( $_POST['give_total'] ) ?
1875 apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) :
1876 give_get_default_form_amount( $form_id );
1877
1878 // Only proceed if give_total available.
1879 if ( empty( $total ) ) {
1880 return;
1881 }
1882 ?>
1883 <p id="give-final-total-wrap" class="form-wrap ">
1884 <?php
1885 /**
1886 * Fires before the donation total label
1887 *
1888 * @since 2.0.5
1889 */
1890 do_action( 'give_donation_final_total_label_before', $form_id );
1891 ?>
1892 <span class="give-donation-total-label">
1893 <?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?>
1894 </span>
1895 <span class="give-final-total-amount"
1896 data-total="<?php echo give_format_amount( $total, array( 'sanitize' => false ) ); ?>">
1897 <?php
1898 echo give_currency_filter(
1899 give_format_amount(
1900 $total, array(
1901 'sanitize' => false,
1902 'currency' => give_get_currency( $form_id ),
1903 )
1904 ), array( 'currency_code' => give_get_currency( $form_id ) )
1905 );
1906 ?>
1907 </span>
1908 <?php
1909 /**
1910 * Fires after the donation final total label
1911 *
1912 * @since 2.0.5
1913 */
1914 do_action( 'give_donation_final_total_label_after', $form_id );
1915 ?>
1916 </p>
1917 <?php
1918 }
1919
1920 add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1921
1922 /**
1923 * Renders the Checkout Submit section.
1924 *
1925 * @param int $form_id The donation form ID.
1926 * @param array $args List of arguments.
1927 *
1928 * @return void
1929 * @since 1.0
1930 *
1931 */
1932 function give_checkout_submit( $form_id, $args ) {
1933 ?>
1934 <fieldset id="give_purchase_submit" class="give-donation-submit">
1935 <?php
1936 /**
1937 * Fire before donation form submit.
1938 *
1939 * @since 1.7
1940 */
1941 do_action( 'give_donation_form_before_submit', $form_id, $args );
1942
1943 give_checkout_hidden_fields( $form_id );
1944
1945 echo give_get_donation_form_submit_button( $form_id, $args );
1946
1947 /**
1948 * Fire after donation form submit.
1949 *
1950 * @since 1.7
1951 */
1952 do_action( 'give_donation_form_after_submit', $form_id, $args );
1953 ?>
1954 </fieldset>
1955 <?php
1956 }
1957
1958 add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 );
1959
1960 /**
1961 * Give Donation form submit button.
1962 *
1963 * @param int $form_id The form ID.
1964 * @param array $args
1965 *
1966 * @return string
1967 * @since 1.8.8
1968 *
1969 */
1970 function give_get_donation_form_submit_button( $form_id, $args = array() ) {
1971
1972 $display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
1973 $display_label_field = apply_filters( 'give_donation_form_submit_button_text', $display_label_field, $form_id, $args );
1974 $display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1975 ob_start();
1976 ?>
1977 <div class="give-submit-button-wrap give-clearfix">
1978 <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1979 value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>"/>
1980 <span class="give-loading-animation"></span>
1981 </div>
1982 <?php
1983 return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id, $args );
1984 }
1985
1986 /**
1987 * Show Give Goals.
1988 *
1989 * @param int $form_id The form ID.
1990 * @param array $args An array of form arguments.
1991 *
1992 * @return mixed
1993 * @since 1.6 Add template for Give Goals Shortcode.
1994 * More info is on https://github.com/impress-org/give/issues/411
1995 *
1996 * @since 1.0
1997 */
1998 function give_show_goal_progress( $form_id, $args = array() ) {
1999
2000 ob_start();
2001 give_get_template(
2002 'shortcode-goal', array(
2003 'form_id' => $form_id,
2004 'args' => $args,
2005 )
2006 );
2007
2008 /**
2009 * Filter progress bar output
2010 *
2011 * @since 2.0
2012 */
2013 echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args );
2014
2015 return true;
2016 }
2017
2018 add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
2019
2020 /**
2021 * Show Give Totals Progress.
2022 *
2023 * @param int $total Total amount based on shortcode parameter.
2024 * @param int $total_goal Total Goal amount passed by Admin.
2025 *
2026 * @return mixed
2027 * @since 2.1
2028 *
2029 */
2030 function give_show_goal_totals_progress( $total, $total_goal ) {
2031
2032 // Bail out if total goal is set as an array.
2033 if ( isset( $total_goal ) && is_array( $total_goal ) ) {
2034 return false;
2035 }
2036
2037 ob_start();
2038 give_get_template(
2039 'shortcode-totals-progress', array(
2040 'total' => $total,
2041 'total_goal' => $total_goal,
2042 )
2043 );
2044
2045 echo apply_filters( 'give_total_progress_output', ob_get_clean() );
2046
2047 return true;
2048 }
2049
2050 add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
2051
2052 /**
2053 * Get form content position.
2054 *
2055 * @param $form_id
2056 * @param $args
2057 *
2058 * @return mixed|string
2059 * @since 1.8
2060 *
2061 */
2062 function give_get_form_content_placement( $form_id, $args ) {
2063 $show_content = '';
2064
2065 if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
2066 // Content positions.
2067 $content_placement = array(
2068 'above' => 'give_pre_form',
2069 'below' => 'give_post_form',
2070 );
2071
2072 // Check if content position already decoded.
2073 if ( in_array( $args['show_content'], $content_placement ) ) {
2074 return $args['show_content'];
2075 }
2076
2077 $show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
2078
2079 } elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
2080 $show_content = give_get_meta( $form_id, '_give_content_placement', true );
2081
2082 }
2083
2084 return $show_content;
2085 }
2086
2087 /**
2088 * Adds Actions to Render Form Content.
2089 *
2090 * @param int $form_id The form ID.
2091 * @param array $args An array of form arguments.
2092 *
2093 * @return void|bool
2094 * @since 1.0
2095 *
2096 */
2097 function give_form_content( $form_id, $args ) {
2098
2099 $show_content = give_get_form_content_placement( $form_id, $args );
2100
2101 // Bailout.
2102 if ( empty( $show_content ) ) {
2103 return false;
2104 }
2105
2106 // Add action according to value.
2107 add_action( $show_content, 'give_form_display_content', 10, 2 );
2108 }
2109
2110 add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
2111
2112 /**
2113 * Renders Post Form Content.
2114 *
2115 * Displays content for Give forms; fired by action from give_form_content.
2116 *
2117 * @param int $form_id The form ID.
2118 * @param array $args An array of form arguments.
2119 *
2120 * @return void
2121 * @since 1.0
2122 *
2123 */
2124 function give_form_display_content( $form_id, $args ) {
2125 $content = give_get_meta( $form_id, '_give_form_content', true );
2126 $show_content = give_get_form_content_placement( $form_id, $args );
2127
2128 if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
2129
2130 // Do not restore wpautop if we are still parsing blocks.
2131 $priority = has_filter( 'the_content', '_restore_wpautop_hook' );
2132 if ( false !== $priority && doing_filter( 'the_content' ) ) {
2133 remove_filter( 'the_content', '_restore_wpautop_hook', $priority );
2134 }
2135
2136 $content = apply_filters( 'the_content', $content );
2137
2138 // Restore wpautop after done with blocks parsing.
2139 if ( $priority ) {
2140 // Run wpautop manually if parsing block
2141 $content = wpautop( $content );
2142
2143 add_filter( 'the_content', '_restore_wpautop_hook', $priority );
2144 }
2145 } else {
2146 $content = wpautop( do_shortcode( $content ) );
2147 }
2148
2149 $output = sprintf(
2150 '<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>',
2151 $form_id,
2152 $show_content,
2153 $content
2154 );
2155
2156 /**
2157 * Filter form content html
2158 *
2159 * @param string $output
2160 * @param int $form_id
2161 * @param array $args
2162 *
2163 * @since 1.0
2164 *
2165 */
2166 echo apply_filters( 'give_form_content_output', $output, $form_id, $args );
2167
2168 // remove action to prevent content output on addition forms on page.
2169 // @see: https://github.com/impress-org/give/issues/634.
2170 remove_action( $show_content, 'give_form_display_content' );
2171 }
2172
2173 /**
2174 * Renders the hidden Checkout fields.
2175 *
2176 * @param int $form_id The form ID.
2177 *
2178 * @return void
2179 * @since 1.0
2180 *
2181 */
2182 function give_checkout_hidden_fields( $form_id ) {
2183
2184 /**
2185 * Fires while rendering hidden checkout fields, before the fields.
2186 *
2187 * @param int $form_id The form ID.
2188 *
2189 * @since 1.0
2190 *
2191 */
2192 do_action( 'give_hidden_fields_before', $form_id );
2193
2194 if ( is_user_logged_in() ) {
2195 ?>
2196 <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
2197 <?php } ?>
2198 <input type="hidden" name="give_action" value="purchase"/>
2199 <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
2200 <?php
2201 /**
2202 * Fires while rendering hidden checkout fields, after the fields.
2203 *
2204 * @param int $form_id The form ID.
2205 *
2206 * @since 1.0
2207 *
2208 */
2209 do_action( 'give_hidden_fields_after', $form_id );
2210
2211 }
2212
2213 /**
2214 * Filter Success Page Content.
2215 *
2216 * Applies filters to the success page content.
2217 *
2218 * @param string $content Content before filters.
2219 *
2220 * @return string $content Filtered content.
2221 * @since 1.0
2222 *
2223 */
2224 function give_filter_success_page_content( $content ) {
2225
2226 $give_options = give_get_settings();
2227
2228 if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
2229 if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
2230 $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
2231 }
2232 }
2233
2234 return $content;
2235 }
2236
2237 add_filter( 'the_content', 'give_filter_success_page_content' );
2238
2239 /**
2240 * Test Mode Frontend Warning.
2241 *
2242 * Displays a notice on the frontend for donation forms.
2243 *
2244 * @since 1.1
2245 */
2246 function give_test_mode_frontend_warning() {
2247
2248 if ( give_is_test_mode() ) {
2249 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>';
2250 }
2251 }
2252
2253 add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
2254
2255 /**
2256 * Members-only Form.
2257 *
2258 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
2259 *
2260 * @param string $final_output
2261 * @param array $args
2262 *
2263 * @return string
2264 * @since 1.4.1
2265 *
2266 */
2267 function give_members_only_form( $final_output, $args ) {
2268
2269 $form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
2270
2271 // Sanity Check: Must have form_id & not be logged in.
2272 if ( empty( $form_id ) || is_user_logged_in() ) {
2273 return $final_output;
2274 }
2275
2276 // Logged in only and Register / Login set to none.
2277 if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
2278
2279 $final_output = Give_Notices::print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
2280
2281 return apply_filters( 'give_members_only_output', $final_output, $form_id );
2282
2283 }
2284
2285 return $final_output;
2286
2287 }
2288
2289 add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
2290
2291
2292 /**
2293 * Add donation form hidden fields.
2294 *
2295 * @param int $form_id
2296 * @param array $args
2297 * @param Give_Donate_Form $form
2298 *
2299 * @since 1.8.17
2300 *
2301 */
2302 function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
2303 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
2304 ?>
2305 <input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/>
2306 <input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/>
2307 <input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/>
2308 <input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2309 <input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2310 <?php
2311 // Get the custom option amount.
2312 $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
2313
2314 // If custom amount enabled.
2315 if ( give_is_setting_enabled( $custom_amount ) ) {
2316 ?>
2317 <input type="hidden" name="give-form-minimum"
2318 value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/>
2319 <input type="hidden" name="give-form-maximum"
2320 value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/>
2321 <?php
2322 }
2323
2324 $data_attr = sprintf(
2325 'data-time="%1$s" data-nonce-life="%2$s" data-donor-session="%3$s"',
2326 time(),
2327 give_get_nonce_life(),
2328 absint( Give()->session->has_session() )
2329 );
2330
2331 // WP nonce field.
2332 echo str_replace(
2333 '/>',
2334 "{$data_attr}/>",
2335 give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
2336 );
2337
2338 // Price ID hidden field for variable (multi-level) donation forms.
2339 if ( give_has_variable_prices( $form_id ) ) {
2340 // Get the default price ID.
2341 $default_price = give_form_get_default_level( $form_id );
2342 $price_id = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0;
2343
2344 echo sprintf(
2345 '<input type="hidden" name="give-price-id" value="%s"/>',
2346 $price_id
2347 );
2348 }
2349 }
2350
2351 add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
2352
2353 /**
2354 * Add currency settings on donation form.
2355 *
2356 * @param array $form_html_tags
2357 * @param Give_Donate_Form $form
2358 *
2359 * @return array
2360 * @since 1.8.17
2361 *
2362 */
2363 function __give_form_add_currency_settings( $form_html_tags, $form ) {
2364 $form_currency = give_get_currency( $form->ID );
2365 $currency_settings = give_get_currency_formatting_settings( $form_currency );
2366
2367 // Check if currency exist.
2368 if ( empty( $currency_settings ) ) {
2369 return $form_html_tags;
2370 }
2371
2372 $form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2373 $form_html_tags['data-currency_code'] = $form_currency;
2374
2375 if ( ! empty( $currency_settings ) ) {
2376 foreach ( $currency_settings as $key => $value ) {
2377 $form_html_tags["data-{$key}"] = $value;
2378 }
2379 }
2380
2381 return $form_html_tags;
2382 }
2383
2384 add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2385
2386 /**
2387 * Adds classes to progress bar container.
2388 *
2389 * @param string $class_goal
2390 *
2391 * @return string
2392 * @since 2.1
2393 *
2394 */
2395 function add_give_goal_progress_class( $class_goal ) {
2396 $class_goal = 'progress progress-striped active';
2397
2398 return $class_goal;
2399 }
2400
2401 /**
2402 * Adds classes to progress bar span tag.
2403 *
2404 * @param string $class_bar
2405 *
2406 * @return string
2407 * @since 2.1
2408 *
2409 */
2410 function add_give_goal_progress_bar_class( $class_bar ) {
2411 $class_bar = 'bar';
2412
2413 return $class_bar;
2414 }
2415
2416 /**
2417 * Add a class to the form wrap on the grid page.
2418 *
2419 * @param array $class Array of form wrapper classes.
2420 * @param int $id ID of the form.
2421 * @param array $args Additional args.
2422 *
2423 * @return array
2424 * @since 2.1
2425 *
2426 */
2427 function add_class_for_form_grid( $class, $id, $args ) {
2428 $class[] = 'give-form-grid-wrap';
2429
2430 foreach ( $class as $index => $item ) {
2431 if ( false !== strpos( $item, 'give-display-' ) ) {
2432 unset( $class[ $index ] );
2433 }
2434 }
2435
2436 return $class;
2437 }
2438
2439 /**
2440 * Add hidden field to Form Grid page
2441 *
2442 * @param int $form_id The form ID.
2443 * @param array $args An array of form arguments.
2444 * @param Give_Donate_Form $form Form object.
2445 *
2446 * @since 2.1
2447 */
2448 function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
2449 echo '<input type="hidden" name="is-form-grid" value="true" />';
2450 }
2451
2452 /**
2453 * Redirect to the same paginated URL on the Form Grid page
2454 * and adds query parameters to open the popup again after
2455 * redirection.
2456 *
2457 * @param string $redirect URL for redirection.
2458 * @param array $args Array of additional args.
2459 *
2460 * @return string
2461 * @since 2.1
2462 */
2463 function give_redirect_and_popup_form( $redirect, $args ) {
2464
2465 // Check the page has Form Grid.
2466 $is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
2467
2468 if ( 'true' === $is_form_grid ) {
2469
2470 $payment_mode = give_clean( $_POST['payment-mode'] );
2471 $form_id = $args['form-id'];
2472
2473 // Get the URL without Query parameters.
2474 $redirect = strtok( $redirect, '?' );
2475
2476 // Add query parameters 'form-id' and 'payment-mode'.
2477 $redirect = add_query_arg(
2478 array(
2479 'form-id' => $form_id,
2480 'payment-mode' => $payment_mode,
2481 ), $redirect
2482 );
2483 }
2484
2485 // Return the modified URL.
2486 return $redirect;
2487 }
2488
2489 add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );
2490