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