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