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