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