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