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