PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.1.4
GiveWP – Donation Plugin and Fundraising Platform v2.1.4
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 8 years ago template.php 8 years ago widget.php 8 years ago
template.php
2185 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 //Get variable pricing.
492 $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
493 $display_style = give_get_meta( $form_id, '_give_display_style', true );
494 $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
495 $custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true );
496
497 if ( empty( $custom_amount_text ) ) {
498 $custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
499 }
500
501 $output = '';
502
503 switch ( $display_style ) {
504 case 'buttons':
505
506 $output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
507
508 foreach ( $prices as $price ) {
509 $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 ) ) ), $form_id, $price );
510 $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-btn give-btn give-btn-level-' . $price['_give_id']['level_id'] . ' ' . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'give-default-level' : '' ), $form_id, $price );
511
512 $formatted_amount = give_format_amount( $price['_give_amount'], array(
513 'sanitize' => false,
514 'currency' => give_get_currency( $form_id ),
515 ) );
516
517 $output .= sprintf(
518 '<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s">%4$s</button></li>',
519 $price['_give_id']['level_id'],
520 $level_classes,
521 $formatted_amount,
522 $level_text
523 );
524 }
525
526 //Custom Amount.
527 if (
528 give_is_setting_enabled( $custom_amount )
529 && ! empty( $custom_amount_text )
530 ) {
531
532 $output .= sprintf(
533 '<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>',
534 $custom_amount_text
535 );
536 }
537
538 $output .= '</ul>';
539
540 break;
541
542 case 'radios':
543
544 $output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
545
546 foreach ( $prices as $price ) {
547 $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 ) ) ), $form_id, $price );
548 $level_classes = apply_filters( 'give_form_level_classes', 'give-radio-input give-radio-input-level give-radio-level-' . $price['_give_id']['level_id'] . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price );
549
550 $formatted_amount = give_format_amount( $price['_give_amount'], array(
551 'sanitize' => false,
552 'currency' => give_get_currency( $form_id ),
553 ) );
554
555 $output .= sprintf(
556 '<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 ><label for="give-radio-level-%1$s">%5$s</label></li>',
557 $price['_give_id']['level_id'],
558 $level_classes,
559 $formatted_amount,
560 ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'checked="checked"' : '' ),
561 $level_text
562 );
563 }
564
565 //Custom Amount.
566 if (
567 give_is_setting_enabled( $custom_amount )
568 && ! empty( $custom_amount_text )
569 ) {
570 $output .= sprintf(
571 '<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>',
572 $custom_amount_text
573 );
574 }
575
576 $output .= '</ul>';
577
578 break;
579
580 case 'dropdown':
581
582 $output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
583 $output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
584
585 //first loop through prices.
586 foreach ( $prices as $price ) {
587 $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 ) ) ), $form_id, $price );
588 $level_classes = apply_filters( 'give_form_level_classes', 'give-donation-level-' . $price['_give_id']['level_id'] . ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? ' give-default-level' : '' ), $form_id, $price );
589
590 $formatted_amount = give_format_amount( $price['_give_amount'], array(
591 'sanitize' => false,
592 'currency' => give_get_currency( $form_id ),
593 ) );
594
595 $output .= sprintf(
596 '<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s >%5$s</option>',
597 $price['_give_id']['level_id'],
598 $level_classes,
599 $formatted_amount,
600 ( ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) ? 'selected="selected"' : '' ),
601 $level_text
602 );
603 }
604
605 //Custom Amount.
606 if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
607 $output .= sprintf(
608 '<option data-price-id="custom" class="give-donation-level-custom" value="custom">%1$s</option>',
609 $custom_amount_text
610 );
611 }
612
613 $output .= '</select>';
614
615 break;
616 }
617
618 echo apply_filters( 'give_form_level_output', $output, $form_id );
619 }
620
621 /**
622 * Display Reveal & Lightbox Button.
623 *
624 * Outputs a button to reveal form fields.
625 *
626 * @since 1.0
627 *
628 * @param int $form_id The form ID.
629 * @param array $args An array of form arguments.
630 *
631 * @return string Checkout button.
632 */
633 function give_display_checkout_button( $form_id, $args ) {
634
635 $display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
636 ? $args['display_style']
637 : give_get_meta( $form_id, '_give_payment_display', true );
638
639 if ( 'button' === $display_option ) {
640 $display_option = 'modal';
641 } elseif ( $display_option === 'onpage' ) {
642 return '';
643 }
644
645 $display_label_field = give_get_meta( $form_id, '_give_reveal_label', true );
646 $display_label = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
647
648 $output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
649
650 echo apply_filters( 'give_display_checkout_button', $output );
651 }
652
653 add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
654
655 /**
656 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
657 *
658 * @since 1.0
659 *
660 * @param int $form_id The form ID.
661 *
662 * @see For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
663 *
664 * @return void
665 */
666 function give_user_info_fields( $form_id ) {
667 // Get user info.
668 $give_user_info = _give_get_prefill_form_field_values( $form_id );
669
670 /**
671 * Fire before user personal information fields
672 *
673 * @since 1.7
674 */
675 do_action( 'give_donation_form_before_personal_info', $form_id );
676 ?>
677 <fieldset id="give_checkout_user_info">
678 <legend><?php echo apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ); ?></legend>
679 <p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive">
680 <label class="give-label" for="give-first">
681 <?php _e( 'First Name', 'give' ); ?>
682 <?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
683 <span class="give-required-indicator">*</span>
684 <?php endif ?>
685 <?php echo Give()->tooltips->render_help( __( 'We will use this to personalize your account experience.', 'give' ) ); ?>
686 </label>
687 <input
688 class="give-input required"
689 type="text"
690 name="give_first"
691 autocomplete="given-name"
692 placeholder="<?php _e( 'First Name', 'give' ); ?>"
693 id="give-first"
694 value="<?php echo isset( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : ''; ?>"
695 <?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
696 />
697 </p>
698
699 <p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive">
700 <label class="give-label" for="give-last">
701 <?php _e( 'Last Name', 'give' ); ?>
702 <?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
703 <span class="give-required-indicator">*</span>
704 <?php endif ?>
705 <?php echo Give()->tooltips->render_help( __( 'We will use this as well to personalize your account experience.', 'give' ) ); ?>
706 </label>
707
708 <input
709 class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>"
710 type="text"
711 name="give_last"
712 autocomplete="family-name"
713 id="give-last"
714 placeholder="<?php _e( 'Last Name', 'give' ); ?>"
715 value="<?php echo isset( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : ''; ?>"
716 <?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
717 />
718 </p>
719
720 <?php if ( give_is_company_field_enabled( $form_id ) ) : ?>
721 <?php $give_company = give_field_is_required( 'give_company_name', $form_id ); ?>
722 <p id="give-company-wrap" class="form-row form-row-wide">
723 <label class="give-label" for="give-company">
724 <?php _e( 'Company Name', 'give' ); ?>
725 <?php if ( $give_company ) : ?>
726 <span class="give-required-indicator">*</span>
727 <?php endif; ?>
728 <?php echo Give()->tooltips->render_help( __( 'Donate on behalf of Company', 'give' ) ); ?>
729 </label>
730
731 <input
732 class="give-input<?php echo( $give_company ? ' required' : '' ); ?>"
733 type="text"
734 name="give_company_name"
735 placeholder="<?php _e( 'Company Name', 'give' ); ?>"
736 id="give-company"
737 value="<?php echo isset( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : ''; ?>"
738 <?php echo( $give_company ? ' required aria-required="true" ' : '' ); ?>
739 />
740
741 </p>
742 <?php endif ?>
743
744 <?php
745 /**
746 * Fire before user email field
747 *
748 * @since 1.7
749 */
750 do_action( 'give_donation_form_before_email', $form_id );
751 ?>
752 <p id="give-email-wrap" class="form-row form-row-wide">
753 <label class="give-label" for="give-email">
754 <?php _e( 'Email Address', 'give' ); ?>
755 <?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
756 <span class="give-required-indicator">*</span>
757 <?php } ?>
758 <?php echo Give()->tooltips->render_help( __( 'We will send the donation receipt to this address.', 'give' ) ); ?>
759 </label>
760
761 <input
762 class="give-input required"
763 type="email"
764 name="give_email"
765 autocomplete="email"
766 placeholder="<?php _e( 'Email Address', 'give' ); ?>"
767 id="give-email"
768 value="<?php echo isset( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : ''; ?>"
769 <?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
770 />
771
772 </p>
773 <?php
774 /**
775 * Fire after user email field
776 *
777 * @since 1.7
778 */
779 do_action( 'give_donation_form_after_email', $form_id );
780
781 /**
782 * Fire after personal email field
783 *
784 * @since 1.7
785 */
786 do_action( 'give_donation_form_user_info', $form_id );
787 ?>
788 </fieldset>
789 <?php
790 /**
791 * Fire after user personal information fields
792 *
793 * @since 1.7
794 */
795 do_action( 'give_donation_form_after_personal_info', $form_id );
796 }
797
798 add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
799 add_action( 'give_register_fields_before', 'give_user_info_fields' );
800
801 /**
802 * Renders the credit card info form.
803 *
804 * @since 1.0
805 *
806 * @param int $form_id The form ID.
807 *
808 * @return void
809 */
810 function give_get_cc_form( $form_id ) {
811
812 ob_start();
813
814 /**
815 * Fires while rendering credit card info form, before the fields.
816 *
817 * @since 1.0
818 *
819 * @param int $form_id The form ID.
820 */
821 do_action( 'give_before_cc_fields', $form_id );
822 ?>
823 <fieldset id="give_cc_fields-<?php echo $form_id ?>" class="give-do-validate">
824 <legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
825 <?php if ( is_ssl() ) : ?>
826 <div id="give_secure_site_wrapper-<?php echo $form_id ?>">
827 <span class="give-icon padlock"></span>
828 <span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
829 </div>
830 <?php endif; ?>
831 <p id="give-card-number-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive">
832 <label for="card_number-<?php echo $form_id ?>" class="give-label">
833 <?php _e( 'Card Number', 'give' ); ?>
834 <span class="give-required-indicator">*</span>
835 <?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?>
836 <span class="card-type"></span>
837 </label>
838
839 <input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id ?>"
840 class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>"
841 required aria-required="true"/>
842 </p>
843
844 <p id="give-card-cvc-wrap-<?php echo $form_id ?>" class="form-row form-row-one-third form-row-responsive">
845 <label for="card_cvc-<?php echo $form_id ?>" class="give-label">
846 <?php _e( 'CVC', 'give' ); ?>
847 <span class="give-required-indicator">*</span>
848 <?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?>
849 </label>
850
851 <input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id ?>"
852 class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>"
853 required aria-required="true"/>
854 </p>
855
856 <p id="give-card-name-wrap-<?php echo $form_id ?>" class="form-row form-row-two-thirds form-row-responsive">
857 <label for="card_name-<?php echo $form_id ?>" class="give-label">
858 <?php _e( 'Name on the Card', 'give' ); ?>
859 <span class="give-required-indicator">*</span>
860 <?php echo Give()->tooltips->render_help( __( 'The name printed on the front of your credit card.', 'give' ) ); ?>
861 </label>
862
863 <input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id ?>"
864 class="card-name give-input required" placeholder="<?php esc_attr_e( 'Card name', 'give' ); ?>"
865 required aria-required="true"/>
866 </p>
867 <?php
868 /**
869 * Fires while rendering credit card info form, before expiration fields.
870 *
871 * @since 1.0
872 *
873 * @param int $form_id The form ID.
874 */
875 do_action( 'give_before_cc_expiration' );
876 ?>
877 <p class="card-expiration form-row form-row-one-third form-row-responsive">
878 <label for="card_expiry-<?php echo $form_id ?>" class="give-label">
879 <?php _e( 'Expiration', 'give' ); ?>
880 <span class="give-required-indicator">*</span>
881 <?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?>
882 </label>
883
884 <input type="hidden" id="card_exp_month-<?php echo $form_id ?>" name="card_exp_month" class="card-expiry-month"/>
885 <input type="hidden" id="card_exp_year-<?php echo $form_id ?>" name="card_exp_year" class="card-expiry-year"/>
886
887 <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"/>
888 </p>
889 <?php
890 /**
891 * Fires while rendering credit card info form, after expiration fields.
892 *
893 * @since 1.0
894 *
895 * @param int $form_id The form ID.
896 */
897 do_action( 'give_after_cc_expiration', $form_id );
898 ?>
899 </fieldset>
900 <?php
901 /**
902 * Fires while rendering credit card info form, before the fields.
903 *
904 * @since 1.0
905 *
906 * @param int $form_id The form ID.
907 */
908 do_action( 'give_after_cc_fields', $form_id );
909
910 echo ob_get_clean();
911 }
912
913 add_action( 'give_cc_form', 'give_get_cc_form' );
914
915 /**
916 * Outputs the default credit card address fields.
917 *
918 * @since 1.0
919 *
920 * @param int $form_id The form ID.
921 *
922 * @return void
923 */
924 function give_default_cc_address_fields( $form_id ) {
925 // Get user info.
926 $give_user_info = _give_get_prefill_form_field_values( $form_id );
927
928 $logged_in = is_user_logged_in();
929
930 if ( $logged_in ) {
931 $user_address = give_get_donor_address( get_current_user_id() );
932 }
933
934 ob_start();
935 ?>
936 <fieldset id="give_cc_address" class="cc-address">
937 <legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
938 <?php
939 /**
940 * Fires while rendering credit card billing form, before address fields.
941 *
942 * @since 1.0
943 *
944 * @param int $form_id The form ID.
945 */
946 do_action( 'give_cc_billing_top' );
947
948 // For Country.
949 $selected_country = give_get_country();
950 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
951 $selected_country = $give_user_info['billing_country'];
952 }
953 $countries = give_get_country_list();
954
955 // For state
956 $selected_state = '';
957 if ( $selected_country === give_get_country() ) {
958 // Get defalut selected state by admin.
959 $selected_state = give_get_state();
960 }
961 // Get the last payment made by user states.
962 if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
963 $selected_state = $give_user_info['card_state'];
964 }
965 // Get the country code
966 if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
967 $selected_country = $give_user_info['billing_country'];
968 }
969 $label = __( 'State', 'give' );
970 $states_label = give_get_states_label();
971 // Check if $country code exists in the array key for states label.
972 if ( array_key_exists( $selected_country, $states_label ) ) {
973 $label = $states_label[ $selected_country ];
974 }
975 $states = give_get_states( $selected_country );
976 // Get the country list that do not have any states init.
977 $no_states_country = give_no_states_country_list();
978 // Get the country list that does not require states.
979 $states_not_required_country_list = give_states_not_required_country_list();
980 ?>
981 <p id="give-card-country-wrap" class="form-row form-row-wide">
982 <label for="billing_country" class="give-label">
983 <?php esc_html_e( 'Country', 'give' ); ?>
984 <?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
985 <span class="give-required-indicator">*</span>
986 <?php endif; ?>
987 <span class="give-tooltip give-icon give-icon-question"
988 data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
989 </label>
990
991 <select
992 name="billing_country"
993 autocomplete="country-name"
994 id="billing_country"
995 class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
996 <?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
997 >
998 <?php
999 foreach ( $countries as $country_code => $country ) {
1000 echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
1001 }
1002 ?>
1003 </select>
1004 </p>
1005
1006 <p id="give-card-address-wrap" class="form-row form-row-wide">
1007 <label for="card_address" class="give-label">
1008 <?php _e( 'Address 1', 'give' ); ?>
1009 <?php
1010 if ( give_field_is_required( 'card_address', $form_id ) ) : ?>
1011 <span class="give-required-indicator">*</span>
1012 <?php endif; ?>
1013 <?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?>
1014 </label>
1015
1016 <input
1017 type="text"
1018 id="card_address"
1019 name="card_address"
1020 autocomplete="address-line1"
1021 class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
1022 placeholder="<?php _e( 'Address line 1', 'give' ); ?>"
1023 value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
1024 <?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1025 />
1026 </p>
1027
1028 <p id="give-card-address-2-wrap" class="form-row form-row-wide">
1029 <label for="card_address_2" class="give-label">
1030 <?php _e( 'Address 2', 'give' ); ?>
1031 <?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
1032 <span class="give-required-indicator">*</span>
1033 <?php endif; ?>
1034 <?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?>
1035 </label>
1036
1037 <input
1038 type="text"
1039 id="card_address_2"
1040 name="card_address_2"
1041 autocomplete="address-line2"
1042 class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
1043 placeholder="<?php _e( 'Address line 2', 'give' ); ?>"
1044 value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
1045 <?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1046 />
1047 </p>
1048
1049 <p id="give-card-city-wrap" class="form-row form-row-wide">
1050 <label for="card_city" class="give-label">
1051 <?php _e( 'City', 'give' ); ?>
1052 <?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
1053 <span class="give-required-indicator">*</span>
1054 <?php endif; ?>
1055 <?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?>
1056 </label>
1057 <input
1058 type="text"
1059 id="card_city"
1060 name="card_city"
1061 autocomplete="address-level3"
1062 class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
1063 placeholder="<?php _e( 'City', 'give' ); ?>"
1064 value="<?php echo isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : ''; ?>"
1065 <?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1066 />
1067 </p>
1068
1069 <p id="give-card-state-wrap"
1070 class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ) ? 'give-hidden' : ''; ?> ">
1071 <label for="card_state" class="give-label">
1072 <span class="state-label-text"><?php echo $label; ?></span>
1073 <?php if ( give_field_is_required( 'card_state', $form_id ) ) :
1074 ?>
1075 <span class="give-required-indicator <?php echo( array_key_exists( $selected_country, $states_not_required_country_list ) ? 'give-hidden' : '' ) ?> ">*</span>
1076 <?php endif; ?>
1077 <span class="give-tooltip give-icon give-icon-question"
1078 data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1079 </label>
1080 <?php
1081
1082 if ( ! empty( $states ) ) : ?>
1083 <select
1084 name="card_state"
1085 autocomplete="address-level4"
1086 id="card_state"
1087 class="card_state give-select<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required' : '' ); ?>"
1088 <?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required aria-required="true" ' : '' ); ?>>
1089 <?php
1090 foreach ( $states as $state_code => $state ) {
1091 echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
1092 }
1093 ?>
1094 </select>
1095 <?php else : ?>
1096 <input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1097 placeholder="<?php echo $label; ?>" value="<?php echo $selected_state; ?>"/>
1098 <?php endif; ?>
1099 </p>
1100
1101 <p id="give-card-zip-wrap" class="form-row form-row-last form-row-responsive">
1102 <label for="card_zip" class="give-label">
1103 <?php _e( 'Zip / Postal Code', 'give' ); ?>
1104 <?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
1105 <span class="give-required-indicator">*</span>
1106 <?php endif; ?>
1107 <?php echo Give()->tooltips->render_help( __( 'The ZIP Code or postal code for your billing address.', 'give' ) ); ?>
1108 </label>
1109
1110 <input
1111 type="text"
1112 size="4"
1113 id="card_zip"
1114 name="card_zip"
1115 autocomplete="postal-code"
1116 class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>"
1117 placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>"
1118 value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
1119 <?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
1120 />
1121 </p>
1122 <?php
1123 /**
1124 * Fires while rendering credit card billing form, after address fields.
1125 *
1126 * @since 1.0
1127 *
1128 * @param int $form_id The form ID.
1129 */
1130 do_action( 'give_cc_billing_bottom' );
1131 ?>
1132 </fieldset>
1133 <?php
1134 echo ob_get_clean();
1135 }
1136
1137 add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1138
1139
1140 /**
1141 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1142 * is provided for the user to create an account.
1143 *
1144 * @since 1.0
1145 *
1146 * @param int $form_id The form ID.
1147 *
1148 * @return string
1149 */
1150 function give_get_register_fields( $form_id ) {
1151
1152 global $user_ID;
1153
1154 if ( is_user_logged_in() ) {
1155 $user_data = get_userdata( $user_ID );
1156 }
1157
1158 $show_register_form = give_show_login_register_option( $form_id );
1159
1160 ob_start(); ?>
1161 <fieldset id="give-register-fields-<?php echo $form_id; ?>">
1162
1163 <?php
1164 /**
1165 * Fires while rendering user registration form, before registration fields.
1166 *
1167 * @since 1.0
1168 *
1169 * @param int $form_id The form ID.
1170 */
1171 do_action( 'give_register_fields_before', $form_id );
1172 ?>
1173
1174 <fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
1175 <?php
1176 /**
1177 * Fires while rendering user registration form, before account fields.
1178 *
1179 * @since 1.0
1180 *
1181 * @param int $form_id The form ID.
1182 */
1183 do_action( 'give_register_account_fields_before', $form_id );
1184 ?>
1185 <div id="give-create-account-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive">
1186 <label for="give-create-account-<?php echo $form_id; ?>">
1187 <?php
1188 // Add attributes to checkbox, if Guest Checkout is disabled.
1189 $is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true );
1190 $id = 'give-create-account-' . $form_id;
1191 if ( ! give_is_setting_enabled( $is_guest_checkout ) ) {
1192 echo Give()->tooltips->render(
1193 array(
1194 'tag_content' => sprintf(
1195 '<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />',
1196 $id
1197 ),
1198 'label' => __( 'Registration is required to donate.', 'give' ),
1199 ) );
1200 } else {
1201 ?>
1202 <input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>" class="give-input" />
1203 <?php
1204 }
1205 ?>
1206 <?php _e( 'Create an account', 'give' ); ?>
1207 <?php echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) ); ?>
1208 <?php wp_nonce_field( 'give_form_create_user_nonce', 'give-form-user-register-hash', false, true );?>
1209 </label>
1210 </div>
1211
1212 <?php if ( 'both' === $show_register_form ) { ?>
1213 <div class="give-login-account-wrap form-row form-row-last form-row-responsive">
1214 <p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1215 <a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1216 data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1217 </p>
1218 <p class="give-loading-text">
1219 <span class="give-loading-animation"></span>
1220 </p>
1221 </div>
1222 <?php } ?>
1223
1224 <?php
1225 /**
1226 * Fires while rendering user registration form, after account fields.
1227 *
1228 * @since 1.0
1229 *
1230 * @param int $form_id The form ID.
1231 */
1232 do_action( 'give_register_account_fields_after', $form_id );
1233 ?>
1234 </fieldset>
1235
1236 <?php
1237 /**
1238 * Fires while rendering user registration form, after registration fields.
1239 *
1240 * @since 1.0
1241 *
1242 * @param int $form_id The form ID.
1243 */
1244 do_action( 'give_register_fields_after', $form_id );
1245 ?>
1246
1247 <input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1248
1249 <?php
1250 /**
1251 * Fire after register or login form render
1252 *
1253 * @since 1.7
1254 */
1255 do_action( 'give_donation_form_user_info', $form_id );
1256 ?>
1257
1258 </fieldset>
1259 <?php
1260 echo ob_get_clean();
1261 }
1262
1263 add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1264
1265 /**
1266 * Gets the login fields for the login form on the checkout. This function hooks
1267 * on the give_donation_form_login_fields to display the login form if a user already
1268 * had an account.
1269 *
1270 * @since 1.0
1271 *
1272 * @param int $form_id The form ID.
1273 *
1274 * @return string
1275 */
1276 function give_get_login_fields( $form_id ) {
1277
1278 $form_id = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
1279 $show_register_form = give_show_login_register_option( $form_id );
1280
1281 ob_start();
1282 ?>
1283 <fieldset id="give-login-fields-<?php echo $form_id; ?>">
1284 <legend><?php echo apply_filters( 'give_account_login_fieldset_heading', __( 'Login to Your Account', 'give' ) );
1285 if ( ! give_logged_in_only( $form_id ) ) {
1286 echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>';
1287 } ?>
1288 </legend>
1289 <?php if ( $show_register_form == 'both' ) { ?>
1290 <p class="give-new-account-link">
1291 <?php _e( 'Don\'t have an account?', 'give' ); ?>&nbsp;
1292 <a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel"
1293 data-action="give_checkout_register">
1294 <?php if ( give_logged_in_only( $form_id ) ) {
1295 _e( 'Register as a part of your donation &raquo;', 'give' );
1296 } else {
1297 _e( 'Register or donate as a guest &raquo;', 'give' );
1298 } ?>
1299 </a>
1300 </p>
1301 <p class="give-loading-text">
1302 <span class="give-loading-animation"></span>
1303 </p>
1304 <?php } ?>
1305 <?php
1306 /**
1307 * Fires while rendering checkout login form, before the fields.
1308 *
1309 * @since 1.0
1310 *
1311 * @param int $form_id The form ID.
1312 */
1313 do_action( 'give_checkout_login_fields_before', $form_id );
1314 ?>
1315 <div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive">
1316 <label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
1317 <?php _e( 'Username', 'give' ); ?>
1318 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1319 <span class="give-required-indicator">*</span>
1320 <?php } ?>
1321 </label>
1322
1323 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>" type="text"
1324 name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value=""
1325 placeholder="<?php _e( 'Your username', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1326 </div>
1327
1328 <div id="give-user-pass-wrap-<?php echo $form_id; ?>"
1329 class="give_login_password form-row form-row-last form-row-responsive">
1330 <label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
1331 <?php _e( 'Password', 'give' ); ?>
1332 <?php if ( give_logged_in_only( $form_id ) ) { ?>
1333 <span class="give-required-indicator">*</span>
1334 <?php } ?>
1335 </label>
1336 <input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
1337 type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>"
1338 placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
1339 <input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1340 </div>
1341
1342 <div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
1343 <span class="give-forgot-password ">
1344 <a href="<?php echo wp_lostpassword_url() ?>"
1345 target="_blank"><?php _e( 'Reset Password', 'give' ) ?></a>
1346 </span>
1347 </div>
1348
1349 <div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
1350 <input type="submit" class="give-submit give-btn button" name="give_login_submit"
1351 value="<?php _e( 'Login', 'give' ); ?>"/>
1352 <?php if ( $show_register_form !== 'login' ) { ?>
1353 <input type="button" data-action="give_cancel_login"
1354 class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1355 value="<?php _e( 'Cancel', 'give' ); ?>"/>
1356 <?php } ?>
1357 <span class="give-loading-animation"></span>
1358 </div>
1359 <?php
1360 /**
1361 * Fires while rendering checkout login form, after the fields.
1362 *
1363 * @since 1.0
1364 *
1365 * @param int $form_id The form ID.
1366 */
1367 do_action( 'give_checkout_login_fields_after', $form_id );
1368 ?>
1369 </fieldset><!--end #give-login-fields-->
1370 <?php
1371 echo ob_get_clean();
1372 }
1373
1374 add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1375
1376 /**
1377 * Payment Mode Select.
1378 *
1379 * Renders the payment mode form by getting all the enabled payment gateways and
1380 * outputting them as radio buttons for the user to choose the payment gateway. If
1381 * a default payment gateway has been chosen from the Give Settings, it will be
1382 * automatically selected.
1383 *
1384 * @since 1.0
1385 *
1386 * @param int $form_id The form ID.
1387 *
1388 * @return void
1389 */
1390 function give_payment_mode_select( $form_id, $args ) {
1391
1392 $gateways = give_get_enabled_payment_gateways( $form_id );
1393 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1394
1395 /**
1396 * Fires while selecting payment gateways, before the fields.
1397 *
1398 * @since 1.7
1399 *
1400 * @param int $form_id The form ID.
1401 */
1402 do_action( 'give_payment_mode_top', $form_id );
1403 ?>
1404
1405 <fieldset id="give-payment-mode-select" <?php if ( count( $gateways ) <= 1 ) {
1406 echo 'style="display: none;"';
1407 } ?>>
1408 <?php
1409 /**
1410 * Fires while selecting payment gateways, before the wrap div.
1411 *
1412 * @since 1.7
1413 *
1414 * @param int $form_id The form ID.
1415 */
1416 do_action( 'give_payment_mode_before_gateways_wrap' );
1417 ?>
1418 <legend
1419 class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
1420 <span class="give-loading-text"><span
1421 class="give-loading-animation"></span>
1422 </span>
1423 </legend>
1424
1425 <div id="give-payment-mode-wrap">
1426 <?php
1427 /**
1428 * Fires while selecting payment gateways, before the gateways list.
1429 *
1430 * @since 1.7
1431 */
1432 do_action( 'give_payment_mode_before_gateways' )
1433 ?>
1434 <ul id="give-gateway-radio-list">
1435 <?php
1436 /**
1437 * Loop through the active payment gateways.
1438 */
1439 $selected_gateway = give_get_chosen_gateway( $form_id );
1440 $give_settings = give_get_settings();
1441 $gateways_label = array_key_exists( 'gateways_label', $give_settings ) ?
1442 $give_settings['gateways_label'] :
1443 array();
1444
1445 foreach ( $gateways as $gateway_id => $gateway ) :
1446 //Determine the default gateway.
1447 $checked = checked( $gateway_id, $selected_gateway, false );
1448 $checked_class = $checked ? ' class="give-gateway-option-selected"' : ''; ?>
1449 <li<?php echo $checked_class ?>>
1450 <input type="radio" name="payment-mode" class="give-gateway"
1451 id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1452 value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
1453
1454 <?php
1455 $label = $gateway['checkout_label'];
1456 if ( ! empty( $gateways_label[ $gateway_id ] ) ) {
1457 $label = $gateways_label[ $gateway_id ];
1458 }
1459 ?>
1460 <label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1461 class="give-gateway-option"
1462 id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $label ); ?></label>
1463 </li>
1464 <?php
1465 endforeach;
1466 ?>
1467 </ul>
1468 <?php
1469 /**
1470 * Fires while selecting payment gateways, before the gateways list.
1471 *
1472 * @since 1.7
1473 */
1474 do_action( 'give_payment_mode_after_gateways' );
1475 ?>
1476 </div>
1477 <?php
1478 /**
1479 * Fires while selecting payment gateways, after the wrap div.
1480 *
1481 * @since 1.7
1482 *
1483 * @param int $form_id The form ID.
1484 */
1485 do_action( 'give_payment_mode_after_gateways_wrap' );
1486 ?>
1487 </fieldset>
1488
1489 <?php
1490 /**
1491 * Fires while selecting payment gateways, after the fields.
1492 *
1493 * @since 1.7
1494 *
1495 * @param int $form_id The form ID.
1496 */
1497 do_action( 'give_payment_mode_bottom', $form_id );
1498 ?>
1499
1500 <div id="give_purchase_form_wrap">
1501
1502 <?php
1503 /**
1504 * Fire after payment field render.
1505 *
1506 * @since 1.7
1507 */
1508 do_action( 'give_donation_form', $form_id, $args );
1509 ?>
1510
1511 </div>
1512
1513 <?php
1514 /**
1515 * Fire after donation form render.
1516 *
1517 * @since 1.7
1518 */
1519 do_action( 'give_donation_form_wrap_bottom', $form_id );
1520 }
1521
1522 add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 );
1523
1524 /**
1525 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1526 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1527 * set in the Give Settings.
1528 *
1529 * @since 1.0
1530 *
1531 * @param int $form_id The form ID.
1532 *
1533 * @return bool
1534 */
1535 function give_terms_agreement( $form_id ) {
1536 $form_option = give_get_meta( $form_id, '_give_terms_option', true );
1537
1538 // Bailout if per form and global term and conditions is not setup.
1539 if (
1540 give_is_setting_enabled( $form_option, 'global' )
1541 && give_is_setting_enabled( give_get_option( 'terms' ) )
1542 ) {
1543 $label = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1544 $terms = $terms = give_get_option( 'agreement_text', '' );
1545 $edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1546
1547 } elseif ( give_is_setting_enabled( $form_option ) ) {
1548 $label = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1549 $terms = give_get_meta( $form_id, '_give_agree_text', true );
1550 $edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1551
1552 } else {
1553 return false;
1554 }
1555
1556 // Bailout: Check if term and conditions text is empty or not.
1557 if ( empty( $terms ) ) {
1558 if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1559 echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
1560 }
1561
1562 return false;
1563 }
1564
1565 ?>
1566 <fieldset id="give_terms_agreement">
1567 <legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
1568 <div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
1569 <?php
1570 /**
1571 * Fires while rendering terms of agreement, before the fields.
1572 *
1573 * @since 1.0
1574 */
1575 do_action( 'give_before_terms' );
1576
1577 echo wpautop( stripslashes( $terms ) );
1578 /**
1579 * Fires while rendering terms of agreement, after the fields.
1580 *
1581 * @since 1.0
1582 */
1583 do_action( 'give_after_terms' );
1584 ?>
1585 </div>
1586 <div id="give_show_terms">
1587 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1588 aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1589 <a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
1590 aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1591 </div>
1592
1593 <input name="give_agree_to_terms" class="required" type="checkbox"
1594 id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
1595 <label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
1596
1597 </fieldset>
1598 <?php
1599 }
1600
1601 add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1602
1603 /**
1604 * Checkout Final Total.
1605 *
1606 * Shows the final donation total at the bottom of the checkout page.
1607 *
1608 * @since 1.0
1609 *
1610 * @param int $form_id The form ID.
1611 *
1612 * @return void
1613 */
1614 function give_checkout_final_total( $form_id ) {
1615
1616 $total = isset( $_POST['give_total'] ) ?
1617 apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) :
1618 give_get_default_form_amount( $form_id );
1619
1620
1621 // Only proceed if give_total available.
1622 if ( empty( $total ) ) {
1623 return;
1624 }
1625 ?>
1626 <p id="give-final-total-wrap" class="form-wrap ">
1627 <?php
1628 /**
1629 * Fires before the donation total label
1630 *
1631 * @since 2.0.5
1632 */
1633 do_action( 'give_donation_final_total_label_before', $form_id );
1634 ?>
1635 <span class="give-donation-total-label">
1636 <?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?>
1637 </span>
1638 <span class="give-final-total-amount"
1639 data-total="<?php echo give_format_amount( $total, array( 'sanitize' => false ) ); ?>">
1640 <?php
1641
1642 echo give_currency_filter( give_format_amount( $total, array(
1643 'sanitize' => false,
1644 'currency' => give_get_currency( $form_id ),
1645 ) ), array( 'currency_code' => give_get_currency( $form_id ) ) ); ?>
1646 </span>
1647 <?php
1648 /**
1649 * Fires after the donation final total label
1650 *
1651 * @since 2.0.5
1652 */
1653 do_action( 'give_donation_final_total_label_after', $form_id );
1654 ?>
1655 </p>
1656 <?php
1657 }
1658
1659 add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1660
1661 /**
1662 * Renders the Checkout Submit section.
1663 *
1664 * @since 1.0
1665 *
1666 * @param int $form_id The donation form ID.
1667 * @param array $args List of arguments.
1668 *
1669 * @return void
1670 */
1671 function give_checkout_submit( $form_id, $args ) {
1672 ?>
1673 <fieldset id="give_purchase_submit" class="give-donation-submit">
1674 <?php
1675 /**
1676 * Fire before donation form submit.
1677 *
1678 * @since 1.7
1679 */
1680 do_action( 'give_donation_form_before_submit', $form_id, $args );
1681
1682 give_checkout_hidden_fields( $form_id );
1683
1684 echo give_get_donation_form_submit_button( $form_id );
1685
1686 /**
1687 * Fire after donation form submit.
1688 *
1689 * @since 1.7
1690 */
1691 do_action( 'give_donation_form_after_submit', $form_id, $args );
1692 ?>
1693 </fieldset>
1694 <?php
1695 }
1696
1697 add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 );
1698
1699 /**
1700 * Give Donation form submit button.
1701 *
1702 * @since 1.8.8
1703 *
1704 * @param int $form_id The form ID.
1705 *
1706 * @return string
1707 */
1708 function give_get_donation_form_submit_button( $form_id ) {
1709
1710 $display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
1711 $display_label = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1712 ob_start();
1713 ?>
1714 <div class="give-submit-button-wrap give-clearfix">
1715 <input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1716 value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>" />
1717 <span class="give-loading-animation"></span>
1718 </div>
1719 <?php
1720 return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id );
1721 }
1722
1723 /**
1724 * Show Give Goals.
1725 *
1726 * @since 1.0
1727 * @since 1.6 Add template for Give Goals Shortcode.
1728 * More info is on https://github.com/WordImpress/Give/issues/411
1729 *
1730 * @param int $form_id The form ID.
1731 * @param array $args An array of form arguments.
1732 *
1733 * @return mixed
1734 */
1735 function give_show_goal_progress( $form_id, $args = array() ) {
1736
1737 ob_start();
1738 give_get_template( 'shortcode-goal', array( 'form_id' => $form_id, 'args' => $args ) );
1739
1740 /**
1741 * Filter progress bar output
1742 *
1743 * @since 2.0
1744 */
1745 echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args );
1746
1747 return true;
1748 }
1749
1750 add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1751
1752 /**
1753 * Show Give Totals Progress.
1754 *
1755 * @since 2.1
1756 *
1757 * @param int $total Total amount based on shortcode parameter.
1758 * @param int $total_goal Total Goal amount passed by Admin.
1759 *
1760 * @return mixed
1761 */
1762 function give_show_goal_totals_progress( $total, $total_goal ) {
1763
1764 // Bail out if total goal is set as an array.
1765 if ( isset( $total_goal ) && is_array( $total_goal ) ) {
1766 return false;
1767 }
1768
1769 ob_start();
1770 give_get_template( 'shortcode-totals-progress', array( 'total' => $total, 'total_goal' => $total_goal ) );
1771
1772 echo apply_filters( 'give_total_progress_output', ob_get_clean() );
1773
1774 return true;
1775 }
1776
1777 add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
1778
1779 /**
1780 * Get form content position.
1781 *
1782 * @since 1.8
1783 *
1784 * @param $form_id
1785 * @param $args
1786 *
1787 * @return mixed|string
1788 */
1789 function give_get_form_content_placement( $form_id, $args ) {
1790 $show_content = '';
1791
1792 if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1793 // Content positions.
1794 $content_placement = array(
1795 'above' => 'give_pre_form',
1796 'below' => 'give_post_form',
1797 );
1798
1799 // Check if content position already decoded.
1800 if ( in_array( $args['show_content'], $content_placement ) ) {
1801 return $args['show_content'];
1802 }
1803
1804 $show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1805
1806 } elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
1807 $show_content = give_get_meta( $form_id, '_give_content_placement', true );
1808
1809 } elseif ( 'none' !== give_get_meta( $form_id, '_give_content_option', true ) ) {
1810 // Backward compatibility for _give_content_option for v18.
1811 $show_content = give_get_meta( $form_id, '_give_content_option', true );
1812 }
1813
1814 return $show_content;
1815 }
1816
1817 /**
1818 * Adds Actions to Render Form Content.
1819 *
1820 * @since 1.0
1821 *
1822 * @param int $form_id The form ID.
1823 * @param array $args An array of form arguments.
1824 *
1825 * @return void|bool
1826 */
1827 function give_form_content( $form_id, $args ) {
1828
1829 $show_content = give_get_form_content_placement( $form_id, $args );
1830
1831 // Bailout.
1832 if ( empty( $show_content ) ) {
1833 return false;
1834 }
1835
1836 // Add action according to value.
1837 add_action( $show_content, 'give_form_display_content', 10, 2 );
1838 }
1839
1840 add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
1841
1842 /**
1843 * Renders Post Form Content.
1844 *
1845 * Displays content for Give forms; fired by action from give_form_content.
1846 *
1847 * @since 1.0
1848 *
1849 * @param int $form_id The form ID.
1850 * @param array $args An array of form arguments.
1851 *
1852 * @return void
1853 */
1854 function give_form_display_content( $form_id, $args ) {
1855
1856 $content = wpautop( give_get_meta( $form_id, '_give_form_content', true ) );
1857 $show_content = give_get_form_content_placement( $form_id, $args );
1858
1859 if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
1860 $content = apply_filters( 'the_content', $content );
1861 }
1862
1863 $output = '<div id="give-form-content-' . $form_id . '" class="give-form-content-wrap ' . $show_content . '-content">' . $content . '</div>';
1864
1865 echo apply_filters( 'give_form_content_output', $output );
1866
1867 // remove action to prevent content output on addition forms on page.
1868 // @see: https://github.com/WordImpress/Give/issues/634.
1869 remove_action( $show_content, 'give_form_display_content' );
1870 }
1871
1872 /**
1873 * Renders the hidden Checkout fields.
1874 *
1875 * @since 1.0
1876 *
1877 * @param int $form_id The form ID.
1878 *
1879 * @return void
1880 */
1881 function give_checkout_hidden_fields( $form_id ) {
1882
1883 /**
1884 * Fires while rendering hidden checkout fields, before the fields.
1885 *
1886 * @since 1.0
1887 *
1888 * @param int $form_id The form ID.
1889 */
1890 do_action( 'give_hidden_fields_before', $form_id );
1891
1892 if ( is_user_logged_in() ) { ?>
1893 <input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
1894 <?php } ?>
1895 <input type="hidden" name="give_action" value="purchase"/>
1896 <input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
1897 <?php
1898 /**
1899 * Fires while rendering hidden checkout fields, after the fields.
1900 *
1901 * @since 1.0
1902 *
1903 * @param int $form_id The form ID.
1904 */
1905 do_action( 'give_hidden_fields_after', $form_id );
1906
1907 }
1908
1909 /**
1910 * Filter Success Page Content.
1911 *
1912 * Applies filters to the success page content.
1913 *
1914 * @since 1.0
1915 *
1916 * @param string $content Content before filters.
1917 *
1918 * @return string $content Filtered content.
1919 */
1920 function give_filter_success_page_content( $content ) {
1921
1922 $give_options = give_get_settings();
1923
1924 if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
1925 if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
1926 $content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
1927 }
1928 }
1929
1930 return $content;
1931 }
1932
1933 add_filter( 'the_content', 'give_filter_success_page_content' );
1934
1935 /**
1936 * Test Mode Frontend Warning.
1937 *
1938 * Displays a notice on the frontend for donation forms.
1939 *
1940 * @since 1.1
1941 */
1942 function give_test_mode_frontend_warning() {
1943
1944 if ( give_is_test_mode() ) {
1945 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>';
1946 }
1947 }
1948
1949 add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
1950
1951 /**
1952 * Members-only Form.
1953 *
1954 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
1955 *
1956 * @since 1.4.1
1957 *
1958 * @param string $final_output
1959 * @param array $args
1960 *
1961 * @return string
1962 */
1963 function give_members_only_form( $final_output, $args ) {
1964
1965 $form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
1966
1967 //Sanity Check: Must have form_id & not be logged in.
1968 if ( empty( $form_id ) || is_user_logged_in() ) {
1969 return $final_output;
1970 }
1971
1972 //Logged in only and Register / Login set to none.
1973 if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
1974
1975 $final_output = Give()->notices->print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
1976
1977 return apply_filters( 'give_members_only_output', $final_output, $form_id );
1978
1979 }
1980
1981 return $final_output;
1982
1983 }
1984
1985 add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
1986
1987
1988 /**
1989 * Add donation form hidden fields.
1990 *
1991 * @since 1.8.17
1992 *
1993 * @param int $form_id
1994 * @param array $args
1995 * @param Give_Donate_Form $form
1996 */
1997 function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
1998 $id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1999 ?>
2000 <input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/>
2001 <input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/>
2002 <input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/>
2003 <input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2004 <input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2005 <?php
2006 // Get the custom option amount.
2007 $custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
2008
2009 // If custom amount enabled.
2010 if ( give_is_setting_enabled( $custom_amount ) ) {
2011 ?>
2012 <input type="hidden" name="give-form-minimum"
2013 value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/>
2014 <input type="hidden" name="give-form-maximum"
2015 value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/>
2016 <?php
2017 }
2018
2019 // WP nonce field.
2020 echo str_replace(
2021 '/>',
2022 'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
2023 give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
2024 );
2025
2026 // Price ID hidden field for variable (multi-level) donation forms.
2027 if ( give_has_variable_prices( $form_id ) ) {
2028
2029 // Get default selected price ID.
2030 $prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
2031 $price_id = 0;
2032
2033 // Loop through prices.
2034 foreach ( $prices as $price ) {
2035 if ( isset( $price['_give_default'] ) && $price['_give_default'] === 'default' ) {
2036 $price_id = $price['_give_id']['level_id'];
2037 };
2038 }
2039
2040
2041 echo sprintf(
2042 '<input type="hidden" name="give-price-id" value="%s"/>',
2043 $price_id
2044 );
2045 }
2046 }
2047
2048 add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
2049
2050 /**
2051 * Add currency settings on donation form.
2052 *
2053 * @since 1.8.17
2054 *
2055 * @param array $form_html_tags
2056 * @param Give_Donate_Form $form
2057 *
2058 * @return array
2059 */
2060 function __give_form_add_currency_settings( $form_html_tags, $form ) {
2061 $form_currency = give_get_currency( $form->ID );
2062 $currency_settings = give_get_currency_formatting_settings( $form_currency );
2063
2064 // Check if currency exist.
2065 if ( empty( $currency_settings ) ) {
2066 return $form_html_tags;
2067 }
2068
2069 $form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2070 $form_html_tags['data-currency_code'] = $form_currency;
2071
2072 if ( ! empty( $currency_settings ) ) {
2073 foreach ( $currency_settings as $key => $value ) {
2074 $form_html_tags["data-{$key}"] = $value;
2075 }
2076 }
2077
2078 return $form_html_tags;
2079 }
2080
2081 add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2082
2083 /**
2084 * Adds classes to progress bar container.
2085 *
2086 * @since 2.1
2087 *
2088 * @param string $class_goal
2089 *
2090 * @return string
2091 */
2092 function add_give_goal_progress_class( $class_goal ) {
2093 $class_goal = 'progress progress-striped active';
2094
2095 return $class_goal;
2096 }
2097
2098 /**
2099 * Adds classes to progress bar span tag.
2100 *
2101 * @since 2.1
2102 *
2103 * @param string $class_bar
2104 *
2105 * @return string
2106 */
2107 function add_give_goal_progress_bar_class( $class_bar ) {
2108 $class_bar = 'bar';
2109
2110 return $class_bar;
2111 }
2112
2113 /**
2114 * Add a class to the form wrap on the grid page.
2115 *
2116 * @param array $class Array of form wrapper classes.
2117 * @param int $id ID of the form.
2118 * @param array $args Additional args.
2119 *
2120 * @since 2.1
2121 *
2122 * @return array
2123 */
2124 function add_class_for_form_grid( $class, $id, $args ) {
2125 $class[] = 'give-form-grid-wrap';
2126
2127 foreach ( $class as $index => $item ) {
2128 if( false !== strpos( $item, 'give-display-' ) ) {
2129 unset( $class[$index] );
2130 }
2131 }
2132
2133 return $class;
2134 }
2135
2136 /**
2137 * Add hidden field to Form Grid page
2138 *
2139 * @param int $form_id The form ID.
2140 * @param array $args An array of form arguments.
2141 * @param Give_Donate_Form $form Form object.
2142 *
2143 * @since 2.1
2144 */
2145 function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
2146 echo '<input type="hidden" name="is-form-grid" value="true" />';
2147 }
2148
2149 /**
2150 * Redirect to the same paginated URL on the Form Grid page
2151 * and adds query parameters to open the popup again after
2152 * redirection.
2153 *
2154 * @param string $redirect URL for redirection.
2155 * @param array $args Array of additional args.
2156 *
2157 * @since 2.1
2158 * @return string
2159 */
2160 function give_redirect_and_popup_form( $redirect, $args ) {
2161
2162 // Check the page has Form Grid.
2163 $is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
2164
2165 if ( 'true' === $is_form_grid ) {
2166
2167 $payment_mode = give_clean( $_POST['payment-mode'] );
2168 $form_id = $args['form-id'];
2169
2170 // Get the URL without Query parameters.
2171 $redirect = strtok( $redirect, '?' );
2172
2173 // Add query parameters 'form-id' and 'payment-mode'.
2174 $redirect = add_query_arg( array(
2175 'form-id' => $form_id,
2176 'payment-mode' => $payment_mode,
2177 ), $redirect );
2178 }
2179
2180 // Return the modified URL.
2181 return $redirect;
2182 }
2183
2184 add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );
2185