Test Failed
Push — travis/4010 ( cd7197 )
by Ravinder
12:19
created

template.php ➔ give_payment_mode_select()   C

Complexity

Conditions 9
Paths 104

Size

Total Lines 140

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 9
nc 104
nop 2
dl 0
loc 140
rs 6.4177
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * Give Form Template
4
 *
5
 * @package     Give
6
 * @subpackage  Forms
7
 * @copyright   Copyright (c) 2016, GiveWP
8
 * @license     https://opensource.org/licenses/gpl-license GNU Public License
9
 * @since       1.0
10
 */
11
12
// Exit if accessed directly.
13
if ( ! defined( 'ABSPATH' ) ) {
14
	exit;
15
}
16
17
/**
18
 * Get Donation Form.
19
 *
20
 * @param array $args An array of form arguments.
21
 *
22
 * @since 1.0
23
 *
24
 * @return string Donation form.
25
 */
26
function give_get_donation_form( $args = array() ) {
27
28
	global $post;
29
	static $count = 1;
30
31
	$args = wp_parse_args( $args, give_get_default_form_shortcode_args() );
32
33
	// Backward compatibility for `form_id` function param.
34
	// If are calling this function directly with `form_id` the use `id` instead.
35
	$args['id'] = ! empty( $args['form_id'] ) ? absint( $args['form_id'] ) : $args['id'];
36
37
	// If `id` does not set then maybe we are single donation form page, so lets render form.
38
	if ( empty( $args['id'] ) && is_object( $post ) && $post->ID ) {
39
		$args['id'] = $post->ID;
40
	}
41
42
	// set `form_id` for backward compatibility because many filter and function  using it.
43
	$args['form_id'] = $args['id'];
44
45
	/**
46
	 * Fire the filter
47
	 * Note: we will deprecated this filter soon. Use give_get_default_form_shortcode_args instead
48
	 *
49
	 * @deprecated 2.4.1
50
	 */
51
	$args = apply_filters( 'give_form_args_defaults', $args );
52
53
	$form = new Give_Donate_Form( $args['id'] );
54
55
	// Bail out, if no form ID.
56
	if ( empty( $form->ID ) ) {
57
		return false;
58
	}
59
60
	$args['id_prefix'] = "{$form->ID}-{$count}";
61
	$payment_mode      = give_get_chosen_gateway( $form->ID );
62
63
	$form_action = add_query_arg(
64
		apply_filters(
65
			'give_form_action_args', array(
66
				'payment-mode' => $payment_mode,
67
			)
68
		),
69
		give_get_current_page_url()
70
	);
71
72
	// Sanity Check: Donation form not published or user doesn't have permission to view drafts.
73
	if (
74
		( 'publish' !== $form->post_status && ! current_user_can( 'edit_give_forms', $form->ID ) )
75
		|| ( 'trash' === $form->post_status )
76
	) {
77
		return false;
78
	}
79
80
	// Get the form wrap CSS classes.
81
	$form_wrap_classes = $form->get_form_wrap_classes( $args );
82
83
	// Get the <form> tag wrap CSS classes.
84
	$form_classes = $form->get_form_classes( $args );
85
86
	ob_start();
87
88
	/**
89
	 * Fires while outputting donation form, before the form wrapper div.
90
	 *
91
	 * @since 1.0
92
	 *
93
	 * @param int   Give_Donate_Form::ID The form ID.
94
	 * @param array $args An array of form arguments.
95
	 */
96
	do_action( 'give_pre_form_output', $form->ID, $args, $form );
97
98
	?>
99
	<div id="give-form-<?php echo $form->ID; ?>-wrap" class="<?php echo $form_wrap_classes; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$form_wrap_classes'
Loading history...
100
		<?php
101
		if ( $form->is_close_donation_form() ) {
102
103
			$form_title = ! is_singular( 'give_forms' ) ? apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form->ID ) . '</h2>' ) : '';
104
105
			// Get Goal thank you message.
106
			$goal_achieved_message = get_post_meta( $form->ID, '_give_form_goal_achieved_message', true );
107
			$goal_achieved_message = ! empty( $goal_achieved_message ) ? $form_title . apply_filters( 'the_content', $goal_achieved_message ) : '';
108
109
			// Print thank you message.
110
			echo apply_filters( 'give_goal_closed_output', $goal_achieved_message, $form->ID, $form );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
111
112
		} else {
113
			/**
114
			 * Show form title:
115
			 * 1. if admin set form display_style to button or modal
116
			 */
117
			$form_title = apply_filters( 'give_form_title', '<h2 class="give-form-title">' . get_the_title( $form->ID ) . '</h2>' );
118
119
			if ( ! doing_action( 'give_single_form_summary' ) && true === $args['show_title'] ) {
120
				echo $form_title;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_title'
Loading history...
121
			}
122
123
			/**
124
			 * Fires while outputting donation form, before the form.
125
			 *
126
			 * @since 1.0
127
			 *
128
			 * @param int              Give_Donate_Form::ID The form ID.
129
			 * @param array            $args An array of form arguments.
130
			 * @param Give_Donate_Form $form Form object.
131
			 */
132
			do_action( 'give_pre_form', $form->ID, $args, $form );
133
134
			// Set form html tags.
135
			$form_html_tags = array(
136
				'id'      => "give-form-{$args['id_prefix']}",
137
				'class'   => $form_classes,
138
				'action'  => esc_url_raw( $form_action ),
139
				'data-id' => $args['id_prefix'],
140
			);
141
142
			/**
143
			 * Filter the form html tags.
144
			 *
145
			 * @since 1.8.17
146
			 *
147
			 * @param array            $form_html_tags Array of form html tags.
148
			 * @param Give_Donate_Form $form           Form object.
149
			 */
150
			$form_html_tags = apply_filters( 'give_form_html_tags', (array) $form_html_tags, $form );
151
			?>
152
			<form <?php echo give_get_attribute_str( $form_html_tags ); ?> method="post">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_attribute_str'
Loading history...
153
				<!-- The following field is for robots only, invisible to humans: -->
154
				<span class="give-hidden" style="display: none !important;">
155
					<label for="give-form-honeypot-<?php echo $form->ID; ?>"></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form'
Loading history...
156
					<input id="give-form-honeypot-<?php echo $form->ID; ?>" type="text" name="give-honeypot"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form'
Loading history...
157
						   class="give-honeypot give-hidden"/>
158
				</span>
159
160
				<?php
161
				/**
162
				 * Fires while outputting donation form, before all other fields.
163
				 *
164
				 * @since 1.0
165
				 *
166
				 * @param int              Give_Donate_Form::ID The form ID.
167
				 * @param array            $args An array of form arguments.
168
				 * @param Give_Donate_Form $form Form object.
169
				 */
170
				do_action( 'give_donation_form_top', $form->ID, $args, $form );
171
172
				/**
173
				 * Fires while outputting donation form, for payment gateway fields.
174
				 *
175
				 * @since 1.7
176
				 *
177
				 * @param int              Give_Donate_Form::ID The form ID.
178
				 * @param array            $args An array of form arguments.
179
				 * @param Give_Donate_Form $form Form object.
180
				 */
181
				do_action( 'give_payment_mode_select', $form->ID, $args, $form );
182
183
				/**
184
				 * Fires while outputting donation form, after all other fields.
185
				 *
186
				 * @since 1.0
187
				 *
188
				 * @param int              Give_Donate_Form::ID The form ID.
189
				 * @param array            $args An array of form arguments.
190
				 * @param Give_Donate_Form $form Form object.
191
				 */
192
				do_action( 'give_donation_form_bottom', $form->ID, $args, $form );
193
194
				?>
195
			</form>
196
197
			<?php
198
			/**
199
			 * Fires while outputting donation form, after the form.
200
			 *
201
			 * @since 1.0
202
			 *
203
			 * @param int              Give_Donate_Form::ID The form ID.
204
			 * @param array            $args An array of form arguments.
205
			 * @param Give_Donate_Form $form Form object.
206
			 */
207
			do_action( 'give_post_form', $form->ID, $args, $form );
208
209
		}
210
		?>
211
212
	</div><!--end #give-form-<?php echo absint( $form->ID ); ?>-->
213
	<?php
214
215
	/**
216
	 * Fires while outputting donation form, after the form wrapper div.
217
	 *
218
	 * @since 1.0
219
	 *
220
	 * @param int   Give_Donate_Form::ID The form ID.
221
	 * @param array $args An array of form arguments.
222
	 */
223
	do_action( 'give_post_form_output', $form->ID, $args );
224
225
	$final_output = ob_get_clean();
226
	$count ++;
227
228
	echo apply_filters( 'give_donate_form', $final_output, $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
229
}
230
231
/**
232
 * Give Show Donation Form.
233
 *
234
 * Renders the Donation Form, hooks are provided to add to the checkout form.
235
 * The default Donation Form rendered displays a list of the enabled payment
236
 * gateways, a user registration form (if enable) and a credit card info form
237
 * if credit cards are enabled.
238
 *
239
 * @since  1.0
240
 *
241
 * @param  int $form_id The form ID.
242
 *
243
 * @return string
244
 */
245
function give_show_purchase_form( $form_id, $args ) {
246
247
	$payment_mode = give_get_chosen_gateway( $form_id );
248
249
	if ( ! isset( $form_id ) && isset( $_POST['give_form_id'] ) ) {
250
		$form_id = $_POST['give_form_id'];
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
251
	}
252
253
	/**
254
	 * Fire before donation form render.
255
	 *
256
	 * @since 1.7
257
	 */
258
	do_action( 'give_payment_fields_top', $form_id );
259
260
	if ( give_can_checkout() && isset( $form_id ) ) {
261
262
		/**
263
		 * Fires while displaying donation form, before registration login.
264
		 *
265
		 * @since 1.7
266
		 */
267
		do_action( 'give_donation_form_before_register_login', $form_id, $args );
268
269
		/**
270
		 * Fire when register/login form fields render.
271
		 *
272
		 * @since 1.7
273
		 */
274
		do_action( 'give_donation_form_register_login_fields', $form_id, $args );
275
276
		/**
277
		 * Fire when credit card form fields render.
278
		 *
279
		 * @since 1.7
280
		 */
281
		do_action( 'give_donation_form_before_cc_form', $form_id, $args );
282
283
		// Load the credit card form and allow gateways to load their own if they wish.
284
		if ( has_action( 'give_' . $payment_mode . '_cc_form' ) ) {
285
			/**
286
			 * Fires while displaying donation form, credit card form fields for a given gateway.
287
			 *
288
			 * @since 1.0
289
			 *
290
			 * @param int $form_id The form ID.
291
			 */
292
			do_action( "give_{$payment_mode}_cc_form", $form_id, $args );
293
		} else {
294
			/**
295
			 * Fires while displaying donation form, credit card form fields.
296
			 *
297
			 * @since 1.0
298
			 *
299
			 * @param int $form_id The form ID.
300
			 */
301
			do_action( 'give_cc_form', $form_id, $args );
302
		}
303
304
		/**
305
		 * Fire after credit card form fields render.
306
		 *
307
		 * @since 1.7
308
		 */
309
		do_action( 'give_donation_form_after_cc_form', $form_id, $args );
310
311
	} else {
312
		/**
313
		 * Fire if user can not donate.
314
		 *
315
		 * @since 1.7
316
		 */
317
		do_action( 'give_donation_form_no_access', $form_id );
318
319
	}
320
321
	/**
322
	 * Fire after donation form rendered.
323
	 *
324
	 * @since 1.7
325
	 */
326
	do_action( 'give_payment_fields_bottom', $form_id, $args );
327
}
328
329
add_action( 'give_donation_form', 'give_show_purchase_form', 10, 2 );
330
331
/**
332
 * Give Show Login/Register Form Fields.
333
 *
334
 * @since  1.4.1
335
 *
336
 * @param  int $form_id The form ID.
337
 *
338
 * @return void
339
 */
340
function give_show_register_login_fields( $form_id ) {
341
342
	$show_register_form = give_show_login_register_option( $form_id );
343
344
	if ( ( $show_register_form === 'registration' || ( $show_register_form === 'both' && ! isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
345
		?>
346
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
347
			<?php
348
			/**
349
			 * Fire if user registration form render.
350
			 *
351
			 * @since 1.7
352
			 */
353
			do_action( 'give_donation_form_register_fields', $form_id );
354
			?>
355
		</div>
356
	<?php
357
	elseif ( ( $show_register_form === 'login' || ( $show_register_form === 'both' && isset( $_GET['login'] ) ) ) && ! is_user_logged_in() ) :
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
358
		?>
359
		<div id="give-checkout-login-register-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
360
			<?php
361
			/**
362
			 * Fire if user login form render.
363
			 *
364
			 * @since 1.7
365
			 */
366
			do_action( 'give_donation_form_login_fields', $form_id );
367
			?>
368
		</div>
369
	<?php
370
	endif;
371
372
	if ( ( ! isset( $_GET['login'] ) && is_user_logged_in() ) || ! isset( $show_register_form ) || 'none' === $show_register_form || 'login' === $show_register_form ) {
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
373
		/**
374
		 * Fire when user info render.
375
		 *
376
		 * @since 1.7
377
		 */
378
		do_action( 'give_donation_form_after_user_info', $form_id );
379
	}
380
}
381
382
add_action( 'give_donation_form_register_login_fields', 'give_show_register_login_fields' );
383
384
/**
385
 * Donation Amount Field.
386
 *
387
 * Outputs the donation amount field that appears at the top of the donation forms. If the user has custom amount
388
 * enabled the field will output as a customizable input.
389
 *
390
 * @since  1.0
391
 *
392
 * @param  int   $form_id The form ID.
393
 * @param  array $args    An array of form arguments.
394
 *
395
 * @return void
396
 */
397
function give_output_donation_amount_top( $form_id = 0, $args = array() ) {
398
399
	$give_options        = give_get_settings();
400
	$variable_pricing    = give_has_variable_prices( $form_id );
401
	$allow_custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
402
	$currency_position   = isset( $give_options['currency_position'] ) ? $give_options['currency_position'] : 'before';
403
	$symbol              = give_currency_symbol( give_get_currency( $form_id, $args ) );
404
	$currency_output     = '<span class="give-currency-symbol give-currency-position-' . $currency_position . '">' . $symbol . '</span>';
405
	$default_amount      = give_format_amount(
406
		give_get_default_form_amount( $form_id ), array(
407
			'sanitize' => false,
408
			'currency' => give_get_currency( $form_id ),
409
		)
410
	);
411
	$custom_amount_text  = give_get_meta( $form_id, '_give_custom_amount_text', true );
412
413
	/**
414
	 * Fires while displaying donation form, before donation level fields.
415
	 *
416
	 * @since 1.0
417
	 *
418
	 * @param int   $form_id The form ID.
419
	 * @param array $args    An array of form arguments.
420
	 */
421
	do_action( 'give_before_donation_levels', $form_id, $args );
422
423
	// Set Price, No Custom Amount Allowed means hidden price field.
424
	if ( ! give_is_setting_enabled( $allow_custom_amount ) ) {
425
		?>
426
		<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
427
		<input id="give-amount" class="give-amount-hidden" type="hidden" name="give-amount"
428
			   value="<?php echo $default_amount; ?>" required aria-required="true"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$default_amount'
Loading history...
429
		<div class="set-price give-donation-amount form-row-wide">
430
			<?php
431
			if ( 'before' === $currency_position ) {
432
				echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
433
			}
434
			?>
435
			<span id="give-amount-text" class="give-text-input give-amount-top"><?php echo $default_amount; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$default_amount'
Loading history...
436
			<?php
437
			if ( 'after' === $currency_position ) {
438
				echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
439
			}
440
			?>
441
		</div>
442
		<?php
443
	} else {
444
		// Custom Amount Allowed.
445
		?>
446
		<div class="give-total-wrap">
447
			<div class="give-donation-amount form-row-wide">
448
				<?php
449
				if ( 'before' === $currency_position ) {
450
					echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
451
				}
452
				?>
453
				<label class="give-hidden" for="give-amount"><?php esc_html_e( 'Donation Amount:', 'give' ); ?></label>
454
				<input class="give-text-input give-amount-top" id="give-amount" name="give-amount" type="tel"
455
					   placeholder="" value="<?php echo $default_amount; ?>" autocomplete="off">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$default_amount'
Loading history...
456
				<?php
457
				if ( 'after' === $currency_position ) {
458
					echo $currency_output;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$currency_output'
Loading history...
459
				}
460
				?>
461
			</div>
462
		</div>
463
		<?php
464
	}
465
466
	/**
467
	 * Fires while displaying donation form, after donation amounf field(s).
468
	 *
469
	 * @since 1.0
470
	 *
471
	 * @param int   $form_id The form ID.
472
	 * @param array $args    An array of form arguments.
473
	 */
474
	do_action( 'give_after_donation_amount', $form_id, $args );
475
476
	// Custom Amount Text
477
	if ( ! $variable_pricing && give_is_setting_enabled( $allow_custom_amount ) && ! empty( $custom_amount_text ) ) {
478
		?>
479
		<p class="give-custom-amount-text"><?php echo $custom_amount_text; ?></p>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$custom_amount_text'
Loading history...
480
		<?php
481
	}
482
483
	// Output Variable Pricing Levels.
484
	if ( $variable_pricing ) {
485
		give_output_levels( $form_id );
486
	}
487
488
	/**
489
	 * Fires while displaying donation form, after donation level fields.
490
	 *
491
	 * @since 1.0
492
	 *
493
	 * @param int   $form_id The form ID.
494
	 * @param array $args    An array of form arguments.
495
	 */
496
	do_action( 'give_after_donation_levels', $form_id, $args );
497
}
498
499
add_action( 'give_donation_form_top', 'give_output_donation_amount_top', 10, 2 );
500
501
/**
502
 * Outputs the Donation Levels in various formats such as dropdown, radios, and buttons.
503
 *
504
 * @since  1.0
505
 *
506
 * @param  int $form_id The form ID.
507
 *
508
 * @return string Donation levels.
509
 */
510
function give_output_levels( $form_id ) {
511
512
	/**
513
	 * Filter the variable pricing
514
	 *
515
	 * @since      1.0
516
	 * @deprecated 2.2 Use give_get_donation_levels filter instead of give_form_variable_prices.
517
	 *                 Check Give_Donate_Form::get_prices().
518
	 *
519
	 * @param array $prices Array of variable prices.
520
	 * @param int   $form   Form ID.
521
	 */
522
	$prices = apply_filters( 'give_form_variable_prices', give_get_variable_prices( $form_id ), $form_id );
523
524
	$display_style      = give_get_meta( $form_id, '_give_display_style', true );
525
	$custom_amount      = give_get_meta( $form_id, '_give_custom_amount', true );
526
	$custom_amount_text = give_get_meta( $form_id, '_give_custom_amount_text', true );
527
528
	if ( empty( $custom_amount_text ) ) {
529
		$custom_amount_text = esc_html__( 'Give a Custom Amount', 'give' );
530
	}
531
532
	$output = '';
533
534
	switch ( $display_style ) {
535 View Code Duplication
		case 'buttons':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
536
			$output .= '<ul id="give-donation-level-button-wrap" class="give-donation-levels-wrap give-list-inline">';
537
538
			foreach ( $prices as $price ) {
539
				$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 );
540
				$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 );
541
542
				$formatted_amount = give_format_amount(
543
					$price['_give_amount'], array(
544
						'sanitize' => false,
545
						'currency' => give_get_currency( $form_id ),
546
					)
547
				);
548
549
				$output .= sprintf(
550
					'<li><button type="button" data-price-id="%1$s" class="%2$s" value="%3$s" data-default="%4$s">%5$s</button></li>',
551
					$price['_give_id']['level_id'],
552
					$level_classes,
553
					$formatted_amount,
554
					array_key_exists( '_give_default', $price ) ? 1 : 0,
555
					$level_text
556
				);
557
			}
558
559
			// Custom Amount.
560
			if (
561
				give_is_setting_enabled( $custom_amount )
562
				&& ! empty( $custom_amount_text )
563
			) {
564
565
				$output .= sprintf(
566
					'<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>',
567
					$custom_amount_text
568
				);
569
			}
570
571
			$output .= '</ul>';
572
573
			break;
574
575 View Code Duplication
		case 'radios':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
576
			$output .= '<ul id="give-donation-level-radio-list" class="give-donation-levels-wrap">';
577
578
			foreach ( $prices as $price ) {
579
				$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 );
580
				$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 );
581
582
				$formatted_amount = give_format_amount(
583
					$price['_give_amount'], array(
584
						'sanitize' => false,
585
						'currency' => give_get_currency( $form_id ),
586
					)
587
				);
588
589
				$output .= sprintf(
590
					'<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>',
591
					$price['_give_id']['level_id'],
592
					$level_classes,
593
					$formatted_amount,
594
					( give_is_default_level_id( $price ) ? 'checked="checked"' : '' ),
595
					array_key_exists( '_give_default', $price ) ? 1 : 0,
596
					$level_text
597
				);
598
			}
599
600
			// Custom Amount.
601
			if (
602
				give_is_setting_enabled( $custom_amount )
603
				&& ! empty( $custom_amount_text )
604
			) {
605
				$output .= sprintf(
606
					'<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>',
607
					$custom_amount_text
608
				);
609
			}
610
611
			$output .= '</ul>';
612
613
			break;
614
615
		case 'dropdown':
616
			$output .= '<label for="give-donation-level-select-' . $form_id . '" class="give-hidden">' . esc_html__( 'Choose Your Donation Amount', 'give' ) . ':</label>';
617
			$output .= '<select id="give-donation-level-select-' . $form_id . '" class="give-select give-select-level give-donation-levels-wrap">';
618
619
			// first loop through prices.
620
			foreach ( $prices as $price ) {
621
				$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 );
622
				$level_classes = apply_filters(
623
					'give_form_level_classes', 'give-donation-level-' . $price['_give_id']['level_id'] . ( give_is_default_level_id( $price ) ? ' give-default-level' : '' ), $form_id,
624
					$price
625
				);
626
627
				$formatted_amount = give_format_amount(
628
					$price['_give_amount'], array(
629
						'sanitize' => false,
630
						'currency' => give_get_currency( $form_id ),
631
					)
632
				);
633
634
				$output .= sprintf(
635
					'<option data-price-id="%1$s" class="%2$s" value="%3$s" %4$s data-default="%5$s">%6$s</option>',
636
					$price['_give_id']['level_id'],
637
					$level_classes,
638
					$formatted_amount,
639
					( give_is_default_level_id( $price ) ? 'selected="selected"' : '' ),
640
					array_key_exists( '_give_default', $price ) ? 1 : 0,
641
					$level_text
642
				);
643
			}
644
645
			// Custom Amount.
646
			if ( give_is_setting_enabled( $custom_amount ) && ! empty( $custom_amount_text ) ) {
647
				$output .= sprintf(
648
					'<option data-price-id="custom" class="give-donation-level-custom" value="custom">%1$s</option>',
649
					$custom_amount_text
650
				);
651
			}
652
653
			$output .= '</select>';
654
655
			break;
656
	}
657
658
	echo apply_filters( 'give_form_level_output', $output, $form_id );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
659
}
660
661
/**
662
 * Display Reveal & Lightbox Button.
663
 *
664
 * Outputs a button to reveal form fields.
665
 *
666
 * @since  1.0
667
 *
668
 * @param  int   $form_id The form ID.
669
 * @param  array $args    An array of form arguments.
670
 *
671
 * @return string Checkout button.
672
 */
673
function give_display_checkout_button( $form_id, $args ) {
674
675
	$display_option = ( isset( $args['display_style'] ) && ! empty( $args['display_style'] ) )
676
		? $args['display_style']
677
		: give_get_meta( $form_id, '_give_payment_display', true );
678
679
	if ( 'button' === $display_option ) {
680
		$display_option = 'modal';
681
	} elseif ( $display_option === 'onpage' ) {
0 ignored issues
show
introduced by
Found "=== '". Use Yoda Condition checks, you must
Loading history...
682
		return '';
683
	}
684
685
	$display_label_field = give_get_meta( $form_id, '_give_reveal_label', true );
686
	$display_label       = ! empty( $args['continue_button_title'] ) ? $args['continue_button_title'] : ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
687
688
	$output = '<button type="button" class="give-btn give-btn-' . $display_option . '">' . $display_label . '</button>';
689
690
	echo apply_filters( 'give_display_checkout_button', $output );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
691
}
692
693
add_action( 'give_after_donation_levels', 'give_display_checkout_button', 10, 2 );
694
695
/**
696
 * Shows the User Info fields in the Personal Info box, more fields can be added via the hooks provided.
697
 *
698
 * @since  1.0
699
 *
700
 * @param  int $form_id The form ID.
701
 *
702
 * @see    For Pattern Attribute: https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Form_validation
703
 *
704
 * @return void
705
 */
706
function give_user_info_fields( $form_id ) {
707
708
	// Get user info.
709
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
710
	$title          = ! empty( $give_user_info['give_title'] ) ? $give_user_info['give_title'] : '';
711
	$first_name     = ! empty( $give_user_info['give_first'] ) ? $give_user_info['give_first'] : '';
712
	$last_name      = ! empty( $give_user_info['give_last'] ) ? $give_user_info['give_last'] : '';
713
	$company_name   = ! empty( $give_user_info['company_name'] ) ? $give_user_info['company_name'] : '';
714
	$email          = ! empty( $give_user_info['give_email'] ) ? $give_user_info['give_email'] : '';
715
	$title_prefixes = give_get_name_title_prefixes( $form_id );
716
717
	/**
718
	 * Fire before user personal information fields
719
	 *
720
	 * @since 1.7
721
	 */
722
	do_action( 'give_donation_form_before_personal_info', $form_id );
723
724
	$title_prefix_classes = '';
725
	if ( give_is_name_title_prefix_enabled( $form_id ) ) {
726
		$title_prefix_classes = 'give-title-prefix-wrap';
727
	}
728
	?>
729
	<fieldset id="give_checkout_user_info" class="<?php echo esc_html( $title_prefix_classes ); ?>">
730
		<legend>
731
			<?php echo esc_html( apply_filters( 'give_checkout_personal_info_text', __( 'Personal Info', 'give' ) ) ); ?>
732
		</legend>
733
734
		<?php if ( give_is_name_title_prefix_enabled( $form_id ) && is_array( $title_prefixes ) && count( $title_prefixes ) > 0 ) { ?>
735
			<p id="give-title-wrap" class="form-row form-row-title form-row-responsive">
736
				<label class="give-label" for="give-title">
737
					<?php esc_attr_e( 'Title', 'give' ); ?>
738
					<?php if ( give_field_is_required( 'give_title', $form_id ) ) : ?>
739
						<span class="give-required-indicator">*</span>
740
					<?php endif ?>
741
					<?php echo Give()->tooltips->render_help( __( 'Title is used to personalize your donation record..', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
742
				</label>
743
				<select
744
					class="give-input required"
745
					type="text"
746
					name="give_title"
747
					id="give-title"
748
					<?php echo( give_field_is_required( 'give_title', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
749
				>
750
					<?php foreach ( $title_prefixes as $key => $value ) { ?>
751
						<option
752
							value="<?php echo esc_html( $value ); ?>" <?php selected( $value, $title, true ); ?>><?php echo esc_html( $value ); ?></option>
753
					<?php } ?>
754
				</select>
755
			</p>
756
		<?php } ?>
757
758
		<p id="give-first-name-wrap" class="form-row form-row-first form-row-responsive">
759
			<label class="give-label" for="give-first">
760
				<?php esc_attr_e( 'First Name', 'give' ); ?>
761
				<?php if ( give_field_is_required( 'give_first', $form_id ) ) : ?>
762
					<span class="give-required-indicator">*</span>
763
				<?php endif ?>
764
				<?php echo Give()->tooltips->render_help( __( 'First Name is used to personalize your donation record.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
765
			</label>
766
			<input
767
				class="give-input required"
768
				type="text"
769
				name="give_first"
770
				autocomplete="given-name"
771
				placeholder="<?php esc_attr_e( 'First Name', 'give' ); ?>"
772
				id="give-first"
773
				value="<?php echo esc_html( $first_name ); ?>"
774
				<?php echo( give_field_is_required( 'give_first', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
775
			/>
776
		</p>
777
778
		<p id="give-last-name-wrap" class="form-row form-row-last form-row-responsive">
779
			<label class="give-label" for="give-last">
780
				<?php esc_attr_e( 'Last Name', 'give' ); ?>
781
				<?php if ( give_field_is_required( 'give_last', $form_id ) ) : ?>
782
					<span class="give-required-indicator">*</span>
783
				<?php endif ?>
784
				<?php echo Give()->tooltips->render_help( __( 'Last Name is used to personalize your donation record.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
785
			</label>
786
787
			<input
788
				class="give-input<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
789
				type="text"
790
				name="give_last"
791
				autocomplete="family-name"
792
				id="give-last"
793
				placeholder="<?php esc_attr_e( 'Last Name', 'give' ); ?>"
794
				value="<?php echo esc_html( $last_name ); ?>"
795
				<?php echo( give_field_is_required( 'give_last', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
796
			/>
797
		</p>
798
799
		<?php if ( give_is_company_field_enabled( $form_id ) ) : ?>
800
			<?php $give_company = give_field_is_required( 'give_company_name', $form_id ); ?>
801
			<p id="give-company-wrap" class="form-row form-row-wide">
802
				<label class="give-label" for="give-company">
803
					<?php esc_attr_e( 'Company Name', 'give' ); ?>
804
					<?php if ( $give_company ) : ?>
805
						<span class="give-required-indicator">*</span>
806
					<?php endif; ?>
807
					<?php echo Give()->tooltips->render_help( __( 'Donate on behalf of Company', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
808
				</label>
809
				<input
810
					class="give-input<?php echo( $give_company ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
811
					type="text"
812
					name="give_company_name"
813
					placeholder="<?php esc_attr_e( 'Company Name', 'give' ); ?>"
814
					id="give-company"
815
					value="<?php echo esc_html( $company_name ); ?>"
816
					<?php echo( $give_company ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
817
				/>
818
			</p>
819
		<?php endif ?>
820
821
		<?php
822
		/**
823
		 * Fire before user email field
824
		 *
825
		 * @since 1.7
826
		 */
827
		do_action( 'give_donation_form_before_email', $form_id );
828
		?>
829
		<p id="give-email-wrap" class="form-row form-row-wide">
830
			<label class="give-label" for="give-email">
831
				<?php esc_attr_e( 'Email Address', 'give' ); ?>
832
				<?php if ( give_field_is_required( 'give_email', $form_id ) ) { ?>
833
					<span class="give-required-indicator">*</span>
834
				<?php } ?>
835
				<?php echo Give()->tooltips->render_help( __( 'We will send the donation receipt to this address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
836
			</label>
837
			<input
838
				class="give-input required"
839
				type="email"
840
				name="give_email"
841
				autocomplete="email"
842
				placeholder="<?php esc_attr_e( 'Email Address', 'give' ); ?>"
843
				id="give-email"
844
				value="<?php echo esc_html( $email ); ?>"
845
				<?php echo( give_field_is_required( 'give_email', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
846
			/>
847
848
		</p>
849
850
		<?php if ( give_is_anonymous_donation_field_enabled( $form_id ) ) : ?>
851
			<?php $is_anonymous_donation = isset( $_POST['give_anonymous_donation'] ) ? absint( $_POST['give_anonymous_donation'] ) : 0; ?>
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
852
			<p id="give-anonymous-donation-wrap" class="form-row form-row-wide">
853
				<label class="give-label" for="give-anonymous-donation">
854
					<input
855
						type="checkbox"
856
						class="give-input<?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
857
						name="give_anonymous_donation"
858
						id="give-anonymous-donation"
859
						value="1"
860
						<?php echo( give_field_is_required( 'give_anonymous_donation', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
861
						<?php checked( 1, $is_anonymous_donation ); ?>
862
					>
863
					<?php
864
					/**
865
					 * Filters the checkbox label.
866
					 *
867
					 * @since 2.4.1
868
					 */
869
					echo apply_filters( 'give_anonymous_donation_checkbox_label', __( 'Make this an anonymous donation.', 'give' ), $form_id );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
870
871
					if ( give_field_is_required( 'give_comment', $form_id ) ) {
872
					?>
873
						<span class="give-required-indicator">*</span>
874
					<?php } ?>
875
					<?php
876
					// Conditional tooltip text when comments enabled:
877
					// https://github.com/impress-org/give/issues/3911
878
					$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' );
879
880
					echo Give()->tooltips->render_help( $anonymous_donation_tooltip );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
881
					?>
882
883
				</label>
884
			</p>
885
		<?php endif; ?>
886
887
		<?php if ( give_is_donor_comment_field_enabled( $form_id ) ) : ?>
888
			<p id="give-comment-wrap" class="form-row form-row-wide">
889
				<label class="give-label" for="give-comment">
890
					<?php _e( 'Comment', 'give' ); ?>
891
					<?php if ( give_field_is_required( 'give_comment', $form_id ) ) { ?>
892
						<span class="give-required-indicator">*</span>
893
					<?php } ?>
894
					<?php echo Give()->tooltips->render_help( __( 'Would you like to add a comment to this donation?', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
895
				</label>
896
897
				<textarea
898
					class="give-input<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
899
					name="give_comment"
900
					placeholder="<?php _e( 'Leave a comment', 'give' ); ?>"
901
					id="give-comment"
902
					<?php echo( give_field_is_required( 'give_comment', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
903
				><?php echo isset( $_POST['give_comment'] ) ? give_clean( $_POST['give_comment'] ) : ''; ?></textarea>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
904
905
			</p>
906
		<?php endif; ?>
907
		<?php
908
		/**
909
		 * Fire after user email field
910
		 *
911
		 * @since 1.7
912
		 */
913
		do_action( 'give_donation_form_after_email', $form_id );
914
915
		/**
916
		 * Fire after personal email field
917
		 *
918
		 * @since 1.7
919
		 */
920
		do_action( 'give_donation_form_user_info', $form_id );
921
		?>
922
	</fieldset>
923
	<?php
924
	/**
925
	 * Fire after user personal information fields
926
	 *
927
	 * @since 1.7
928
	 */
929
	do_action( 'give_donation_form_after_personal_info', $form_id );
930
}
931
932
add_action( 'give_donation_form_after_user_info', 'give_user_info_fields' );
933
add_action( 'give_register_fields_before', 'give_user_info_fields' );
934
935
/**
936
 * Renders the credit card info form.
937
 *
938
 * @since  1.0
939
 *
940
 * @param  int $form_id The form ID.
941
 *
942
 * @return void
943
 */
944
function give_get_cc_form( $form_id ) {
945
946
	ob_start();
947
948
	/**
949
	 * Fires while rendering credit card info form, before the fields.
950
	 *
951
	 * @since 1.0
952
	 *
953
	 * @param int $form_id The form ID.
954
	 */
955
	do_action( 'give_before_cc_fields', $form_id );
956
	?>
957
	<fieldset id="give_cc_fields-<?php echo $form_id; ?>" class="give-do-validate">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
958
		<legend><?php echo apply_filters( 'give_credit_card_fieldset_heading', esc_html__( 'Credit Card Info', 'give' ) ); ?></legend>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
959
		<?php if ( is_ssl() ) : ?>
960
			<div id="give_secure_site_wrapper-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
961
				<span class="give-icon padlock"></span>
962
				<span><?php _e( 'This is a secure SSL encrypted payment.', 'give' ); ?></span>
963
			</div>
964
		<?php endif; ?>
965
		<p id="give-card-number-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
966
			<label for="card_number-<?php echo $form_id; ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
967
				<?php _e( 'Card Number', 'give' ); ?>
968
				<span class="give-required-indicator">*</span>
969
				<?php echo Give()->tooltips->render_help( __( 'The (typically) 16 digits on the front of your credit card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
970
				<span class="card-type"></span>
971
			</label>
972
973
			<input type="tel" autocomplete="off" name="card_number" id="card_number-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
974
				   class="card-number give-input required" placeholder="<?php _e( 'Card number', 'give' ); ?>"
975
				   required aria-required="true"/>
976
		</p>
977
978
		<p id="give-card-cvc-wrap-<?php echo $form_id; ?>" class="form-row form-row-one-third form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
979
			<label for="card_cvc-<?php echo $form_id; ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
980
				<?php _e( 'CVC', 'give' ); ?>
981
				<span class="give-required-indicator">*</span>
982
				<?php echo Give()->tooltips->render_help( __( 'The 3 digit (back) or 4 digit (front) value on your card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
983
			</label>
984
985
			<input type="tel" size="4" autocomplete="off" name="card_cvc" id="card_cvc-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
986
				   class="card-cvc give-input required" placeholder="<?php _e( 'Security code', 'give' ); ?>"
987
				   required aria-required="true"/>
988
		</p>
989
990
		<p id="give-card-name-wrap-<?php echo $form_id; ?>" class="form-row form-row-two-thirds form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
991
			<label for="card_name-<?php echo $form_id; ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
992
				<?php _e( 'Cardholder Name', 'give' ); ?>
993
				<span class="give-required-indicator">*</span>
994
				<?php echo Give()->tooltips->render_help( __( 'The name of the credit card account holder.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
995
			</label>
996
997
			<input type="text" autocomplete="off" name="card_name" id="card_name-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
998
				   class="card-name give-input required" placeholder="<?php esc_attr_e( 'Cardholder Name', 'give' ); ?>"
999
				   required aria-required="true"/>
1000
		</p>
1001
		<?php
1002
		/**
1003
		 * Fires while rendering credit card info form, before expiration fields.
1004
		 *
1005
		 * @since 1.0
1006
		 *
1007
		 * @param int $form_id The form ID.
1008
		 */
1009
		do_action( 'give_before_cc_expiration' );
1010
		?>
1011
		<p class="card-expiration form-row form-row-one-third form-row-responsive">
1012
			<label for="card_expiry-<?php echo $form_id; ?>" class="give-label">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1013
				<?php _e( 'Expiration', 'give' ); ?>
1014
				<span class="give-required-indicator">*</span>
1015
				<?php echo Give()->tooltips->render_help( __( 'The date your credit card expires, typically on the front of the card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1016
			</label>
1017
1018
			<input type="hidden" id="card_exp_month-<?php echo $form_id; ?>" name="card_exp_month"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1019
				   class="card-expiry-month"/>
1020
			<input type="hidden" id="card_exp_year-<?php echo $form_id; ?>" name="card_exp_year"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1021
				   class="card-expiry-year"/>
1022
1023
			<input type="tel" autocomplete="off" name="card_expiry" id="card_expiry-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1024
				   class="card-expiry give-input required" placeholder="<?php esc_attr_e( 'MM / YY', 'give' ); ?>"
1025
				   required aria-required="true"/>
1026
		</p>
1027
		<?php
1028
		/**
1029
		 * Fires while rendering credit card info form, after expiration fields.
1030
		 *
1031
		 * @since 1.0
1032
		 *
1033
		 * @param int $form_id The form ID.
1034
		 */
1035
		do_action( 'give_after_cc_expiration', $form_id );
1036
		?>
1037
	</fieldset>
1038
	<?php
1039
	/**
1040
	 * Fires while rendering credit card info form, before the fields.
1041
	 *
1042
	 * @since 1.0
1043
	 *
1044
	 * @param int $form_id The form ID.
1045
	 */
1046
	do_action( 'give_after_cc_fields', $form_id );
1047
1048
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1049
}
1050
1051
add_action( 'give_cc_form', 'give_get_cc_form' );
1052
1053
/**
1054
 * Outputs the default credit card address fields.
1055
 *
1056
 * @since  1.0
1057
 *
1058
 * @param  int $form_id The form ID.
1059
 *
1060
 * @return void
1061
 */
1062
function give_default_cc_address_fields( $form_id ) {
1063
	// Get user info.
1064
	$give_user_info = _give_get_prefill_form_field_values( $form_id );
1065
1066
	ob_start();
1067
	?>
1068
	<fieldset id="give_cc_address" class="cc-address">
1069
		<legend><?php echo apply_filters( 'give_billing_details_fieldset_heading', esc_html__( 'Billing Details', 'give' ) ); ?></legend>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1070
		<?php
1071
		/**
1072
		 * Fires while rendering credit card billing form, before address fields.
1073
		 *
1074
		 * @since 1.0
1075
		 *
1076
		 * @param int $form_id The form ID.
1077
		 */
1078
		do_action( 'give_cc_billing_top' );
1079
1080
		// For Country.
1081
		$selected_country = give_get_country();
1082 View Code Duplication
		if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1083
			$selected_country = $give_user_info['billing_country'];
1084
		}
1085
		$countries = give_get_country_list();
1086
1087
		// For state.
1088
		$selected_state = '';
1089
		if ( $selected_country === give_get_country() ) {
1090
			// Get default selected state by admin.
1091
			$selected_state = give_get_state();
1092
		}
1093
		// Get the last payment made by user states.
1094
		if ( ! empty( $give_user_info['card_state'] ) && '*' !== $give_user_info['card_state'] ) {
1095
			$selected_state = $give_user_info['card_state'];
1096
		}
1097
		// Get the country code.
1098 View Code Duplication
		if ( ! empty( $give_user_info['billing_country'] ) && '*' !== $give_user_info['billing_country'] ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1099
			$selected_country = $give_user_info['billing_country'];
1100
		}
1101
		$label        = __( 'State', 'give' );
1102
		$states_label = give_get_states_label();
1103
		// Check if $country code exists in the array key for states label.
1104
		if ( array_key_exists( $selected_country, $states_label ) ) {
1105
			$label = $states_label[ $selected_country ];
1106
		}
1107
		$states = give_get_states( $selected_country );
1108
		// Get the country list that do not have any states init.
1109
		$no_states_country = give_no_states_country_list();
1110
		// Get the country list that does not require states.
1111
		$states_not_required_country_list = give_states_not_required_country_list();
1112
1113
		// Get the country list that does not require city.
1114
		$city_required = ! array_key_exists( $selected_country, give_city_not_required_country_list() );
1115
1116
		?>
1117
		<p id="give-card-country-wrap" class="form-row form-row-wide">
1118
			<label for="billing_country" class="give-label">
1119
				<?php esc_html_e( 'Country', 'give' ); ?>
1120
				<?php if ( give_field_is_required( 'billing_country', $form_id ) ) : ?>
1121
					<span class="give-required-indicator">*</span>
1122
				<?php endif; ?>
1123
				<span class="give-tooltip give-icon give-icon-question"
1124
					  data-tooltip="<?php esc_attr_e( 'The country for your billing address.', 'give' ); ?>"></span>
1125
			</label>
1126
1127
			<select
1128
				name="billing_country"
1129
				autocomplete="country"
1130
				id="billing_country"
1131
				class="billing-country billing_country give-select<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1132
				<?php echo( give_field_is_required( 'billing_country', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1133
			>
1134
				<?php
1135
				foreach ( $countries as $country_code => $country ) {
1136
					echo '<option value="' . esc_attr( $country_code ) . '"' . selected( $country_code, $selected_country, false ) . '>' . $country . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$country'
Loading history...
1137
				}
1138
				?>
1139
			</select>
1140
		</p>
1141
1142
		<p id="give-card-address-wrap" class="form-row form-row-wide">
1143
			<label for="card_address" class="give-label">
1144
				<?php _e( 'Address 1', 'give' ); ?>
1145
				<?php
1146
				if ( give_field_is_required( 'card_address', $form_id ) ) :
1147
					?>
1148
					<span class="give-required-indicator">*</span>
1149
				<?php endif; ?>
1150
				<?php echo Give()->tooltips->render_help( __( 'The primary billing address for your credit card.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1151
			</label>
1152
1153
			<input
1154
				type="text"
1155
				id="card_address"
1156
				name="card_address"
1157
				autocomplete="address-line1"
1158
				class="card-address give-input<?php echo( give_field_is_required( 'card_address', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1159
				placeholder="<?php _e( 'Address line 1', 'give' ); ?>"
1160
				value="<?php echo isset( $give_user_info['card_address'] ) ? $give_user_info['card_address'] : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
1161
				<?php echo( give_field_is_required( 'card_address', $form_id ) ? '  required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1162
			/>
1163
		</p>
1164
1165
		<p id="give-card-address-2-wrap" class="form-row form-row-wide">
1166
			<label for="card_address_2" class="give-label">
1167
				<?php _e( 'Address 2', 'give' ); ?>
1168
				<?php if ( give_field_is_required( 'card_address_2', $form_id ) ) : ?>
1169
					<span class="give-required-indicator">*</span>
1170
				<?php endif; ?>
1171
				<?php echo Give()->tooltips->render_help( __( '(optional) The suite, apartment number, post office box (etc) associated with your billing address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1172
			</label>
1173
1174
			<input
1175
				type="text"
1176
				id="card_address_2"
1177
				name="card_address_2"
1178
				autocomplete="address-line2"
1179
				class="card-address-2 give-input<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1180
				placeholder="<?php _e( 'Address line 2', 'give' ); ?>"
1181
				value="<?php echo isset( $give_user_info['card_address_2'] ) ? $give_user_info['card_address_2'] : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
1182
				<?php echo( give_field_is_required( 'card_address_2', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1183
			/>
1184
		</p>
1185
1186
		<p id="give-card-city-wrap" class="form-row form-row-wide">
1187
			<label for="card_city" class="give-label">
1188
				<?php _e( 'City', 'give' ); ?>
1189
				<?php if ( give_field_is_required( 'card_city', $form_id ) ) : ?>
1190
					<span class="give-required-indicator <?php echo( $city_required ? '' : 'give-hidden' ); ?>">*</span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1191
				<?php endif; ?>
1192
				<?php echo Give()->tooltips->render_help( __( 'The city for your billing address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1193
			</label>
1194
			<input
1195
				type="text"
1196
				id="card_city"
1197
				name="card_city"
1198
				autocomplete="address-level2"
1199
				class="card-city give-input<?php echo( give_field_is_required( 'card_city', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1200
				placeholder="<?php _e( 'City', 'give' ); ?>"
1201
				value="<?php echo( isset( $give_user_info['card_city'] ) ? $give_user_info['card_city'] : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1202
				<?php echo( give_field_is_required( 'card_city', $form_id ) && $city_required ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1203
			/>
1204
		</p>
1205
1206
		<p id="give-card-state-wrap"
1207
		   class="form-row form-row-first form-row-responsive <?php echo ( ! empty( $selected_country ) && array_key_exists( $selected_country, $no_states_country ) ) ? 'give-hidden' : ''; ?> ">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1208
			<label for="card_state" class="give-label">
1209
				<span class="state-label-text"><?php echo $label; ?></span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
1210
				<?php
1211
				if ( give_field_is_required( 'card_state', $form_id ) ) :
1212
				?>
1213
					<span
1214
						class="give-required-indicator <?php echo( array_key_exists( $selected_country, $states_not_required_country_list ) ? 'give-hidden' : '' ); ?> ">*</span>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1215
				<?php endif; ?>
1216
				<span class="give-tooltip give-icon give-icon-question"
1217
					  data-tooltip="<?php esc_attr_e( 'The state, province, or county for your billing address.', 'give' ); ?>"></span>
1218
			</label>
1219
			<?php
1220
1221
			if ( ! empty( $states ) ) :
1222
				?>
1223
				<select
1224
					name="card_state"
1225
					autocomplete="address-level1"
1226
					id="card_state"
1227
					class="card_state give-select<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1228
					<?php echo( give_field_is_required( 'card_state', $form_id ) ? ' required aria-required="true" ' : '' ); ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1229
					<?php
1230
					foreach ( $states as $state_code => $state ) {
1231
						echo '<option value="' . $state_code . '"' . selected( $state_code, $selected_state, false ) . '>' . $state . '</option>';
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$state_code'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$state'
Loading history...
1232
					}
1233
					?>
1234
				</select>
1235
			<?php else : ?>
1236
				<input type="text" size="6" name="card_state" id="card_state" class="card_state give-input"
1237
					   placeholder="<?php echo $label; ?>" value="<?php echo $selected_state; ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$selected_state'
Loading history...
1238
			<?php endif; ?>
1239
		</p>
1240
1241
		<p id="give-card-zip-wrap" class="form-row form-row-last form-row-responsive">
1242
			<label for="card_zip" class="give-label">
1243
				<?php _e( 'Zip / Postal Code', 'give' ); ?>
1244
				<?php if ( give_field_is_required( 'card_zip', $form_id ) ) : ?>
1245
					<span class="give-required-indicator">*</span>
1246
				<?php endif; ?>
1247
				<?php echo Give()->tooltips->render_help( __( 'The ZIP Code or postal code for your billing address.', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1248
			</label>
1249
1250
			<input
1251
				type="text"
1252
				size="4"
1253
				id="card_zip"
1254
				name="card_zip"
1255
				autocomplete="postal-code"
1256
				class="card-zip give-input<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required' : '' ); ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1257
				placeholder="<?php _e( 'Zip / Postal Code', 'give' ); ?>"
1258
				value="<?php echo isset( $give_user_info['card_zip'] ) ? $give_user_info['card_zip'] : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not 'isset'
Loading history...
1259
				<?php echo( give_field_is_required( 'card_zip', $form_id ) ? ' required aria-required="true" ' : '' ); ?>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1260
			/>
1261
		</p>
1262
		<?php
1263
		/**
1264
		 * Fires while rendering credit card billing form, after address fields.
1265
		 *
1266
		 * @since 1.0
1267
		 *
1268
		 * @param int $form_id The form ID.
1269
		 */
1270
		do_action( 'give_cc_billing_bottom' );
1271
		?>
1272
	</fieldset>
1273
	<?php
1274
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1275
}
1276
1277
add_action( 'give_after_cc_fields', 'give_default_cc_address_fields' );
1278
1279
1280
/**
1281
 * Renders the user registration fields. If the user is logged in, a login form is displayed other a registration form
1282
 * is provided for the user to create an account.
1283
 *
1284
 * @since  1.0
1285
 *
1286
 * @param  int $form_id The form ID.
1287
 *
1288
 * @return string
1289
 */
1290
function give_get_register_fields( $form_id ) {
1291
1292
	global $user_ID;
1293
1294
	if ( is_user_logged_in() ) {
1295
		$user_data = get_userdata( $user_ID );
0 ignored issues
show
Unused Code introduced by
$user_data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1296
	}
1297
1298
	$show_register_form = give_show_login_register_option( $form_id );
1299
1300
	ob_start();
1301
	?>
1302
	<fieldset id="give-register-fields-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1303
1304
		<?php
1305
		/**
1306
		 * Fires while rendering user registration form, before registration fields.
1307
		 *
1308
		 * @since 1.0
1309
		 *
1310
		 * @param int $form_id The form ID.
1311
		 */
1312
		do_action( 'give_register_fields_before', $form_id );
1313
		?>
1314
1315
		<fieldset id="give-register-account-fields-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1316
			<?php
1317
			/**
1318
			 * Fires while rendering user registration form, before account fields.
1319
			 *
1320
			 * @since 1.0
1321
			 *
1322
			 * @param int $form_id The form ID.
1323
			 */
1324
			do_action( 'give_register_account_fields_before', $form_id );
1325
1326
			$class = ( 'registration' === $show_register_form ) ? 'form-row-wide' : 'form-row-first';
1327
			?>
1328
			<div id="give-create-account-wrap-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1329
				 class="form-row <?php echo esc_attr( $class ); ?> form-row-responsive">
1330
				<label for="give-create-account-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1331
					<?php
1332
					// Add attributes to checkbox, if Guest Checkout is disabled.
1333
					$is_guest_checkout = give_get_meta( $form_id, '_give_logged_in_only', true );
1334
					$id                = 'give-create-account-' . $form_id;
1335
					if ( ! give_is_setting_enabled( $is_guest_checkout ) ) {
1336
						echo Give()->tooltips->render(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1337
							array(
1338
								'tag_content' => sprintf(
1339
									'<input type="checkbox" name="give_create_account" value="on" id="%s" class="give-input give-disabled" checked />',
1340
									$id
1341
								),
1342
								'label'       => __( 'Registration is required to donate.', 'give' ),
1343
							)
1344
						);
1345
					} else {
1346
						?>
1347
						<input type="checkbox" name="give_create_account" value="on" id="<?php echo $id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id'
Loading history...
1348
							   class="give-input"/>
1349
						<?php
1350
					}
1351
1352
					_e( 'Create an account', 'give' );
1353
					echo Give()->tooltips->render_help( __( 'Create an account on the site to see and manage donation history.', 'give' ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'Give'
Loading history...
1354
					echo str_replace(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'str_replace'
Loading history...
1355
						'/>',
1356
						'data-time="' . time() . '" data-nonce-life="' . give_get_nonce_life() . '"/>',
1357
						give_get_nonce_field( "give_form_create_user_nonce_{$form_id}", 'give-form-user-register-hash', false )
1358
					);
1359
					?>
1360
				</label>
1361
			</div>
1362
1363
			<?php if ( 'both' === $show_register_form ) { ?>
1364
				<div class="give-login-account-wrap form-row form-row-last form-row-responsive">
1365
					<p class="give-login-message"><?php esc_html_e( 'Already have an account?', 'give' ); ?>&nbsp;
1366
						<a href="<?php echo esc_url( add_query_arg( 'login', 1 ) ); ?>" class="give-checkout-login"
1367
						   data-action="give_checkout_login"><?php esc_html_e( 'Login', 'give' ); ?></a>
1368
					</p>
1369
					<p class="give-loading-text">
1370
						<span class="give-loading-animation"></span>
1371
					</p>
1372
				</div>
1373
			<?php } ?>
1374
1375
			<?php
1376
			/**
1377
			 * Fires while rendering user registration form, after account fields.
1378
			 *
1379
			 * @since 1.0
1380
			 *
1381
			 * @param int $form_id The form ID.
1382
			 */
1383
			do_action( 'give_register_account_fields_after', $form_id );
1384
			?>
1385
		</fieldset>
1386
1387
		<?php
1388
		/**
1389
		 * Fires while rendering user registration form, after registration fields.
1390
		 *
1391
		 * @since 1.0
1392
		 *
1393
		 * @param int $form_id The form ID.
1394
		 */
1395
		do_action( 'give_register_fields_after', $form_id );
1396
		?>
1397
1398
		<input type="hidden" name="give-purchase-var" value="needs-to-register"/>
1399
1400
		<?php
1401
		/**
1402
		 * Fire after register or login form render
1403
		 *
1404
		 * @since 1.7
1405
		 */
1406
		do_action( 'give_donation_form_user_info', $form_id );
1407
		?>
1408
1409
	</fieldset>
1410
	<?php
1411
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1412
}
1413
1414
add_action( 'give_donation_form_register_fields', 'give_get_register_fields' );
1415
1416
/**
1417
 * Gets the login fields for the login form on the checkout. This function hooks
1418
 * on the give_donation_form_login_fields to display the login form if a user already
1419
 * had an account.
1420
 *
1421
 * @since  1.0
1422
 *
1423
 * @param  int $form_id The form ID.
1424
 *
1425
 * @return string
1426
 */
1427
function give_get_login_fields( $form_id ) {
1428
1429
	$form_id            = isset( $_POST['form_id'] ) ? $_POST['form_id'] : $form_id;
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
1430
	$show_register_form = give_show_login_register_option( $form_id );
1431
1432
	ob_start();
1433
	?>
1434
	<fieldset id="give-login-fields-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1435
		<legend>
1436
			<?php
1437
			echo apply_filters( 'give_account_login_fieldset_heading', __( 'Log In to Your Account', 'give' ) );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1438
			if ( ! give_logged_in_only( $form_id ) ) {
1439
				echo ' <span class="sub-text">' . __( '(optional)', 'give' ) . '</span>';
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw '__'
Loading history...
1440
			}
1441
			?>
1442
		</legend>
1443
		<?php if ( $show_register_form == 'both' ) { ?>
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
1444
			<p class="give-new-account-link">
1445
				<?php _e( 'Don\'t have an account?', 'give' ); ?>&nbsp;
1446
				<a href="<?php echo remove_query_arg( 'login' ); ?>" class="give-checkout-register-cancel"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'remove_query_arg'
Loading history...
1447
				   data-action="give_checkout_register">
1448
					<?php
1449
					if ( give_logged_in_only( $form_id ) ) {
1450
						_e( 'Register as a part of your donation &raquo;', 'give' );
1451
					} else {
1452
						_e( 'Register or donate as a guest &raquo;', 'give' );
1453
					}
1454
					?>
1455
				</a>
1456
			</p>
1457
			<p class="give-loading-text">
1458
				<span class="give-loading-animation"></span>
1459
			</p>
1460
		<?php } ?>
1461
		<?php
1462
		/**
1463
		 * Fires while rendering checkout login form, before the fields.
1464
		 *
1465
		 * @since 1.0
1466
		 *
1467
		 * @param int $form_id The form ID.
1468
		 */
1469
		do_action( 'give_donation_form_login_fields_before', $form_id );
1470
		?>
1471
		<div class="give-user-login-fields-container">
1472
			<div id="give-user-login-wrap-<?php echo $form_id; ?>" class="form-row form-row-first form-row-responsive">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1473
				<label class="give-label" for="give-user-login-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1474
					<?php _e( 'Username or Email Address', 'give' ); ?>
1475
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1476
						<span class="give-required-indicator">*</span>
1477
					<?php } ?>
1478
				</label>
1479
1480
				<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1481
					   type="text"
1482
					   name="give_user_login" id="give-user-login-<?php echo $form_id; ?>" value=""
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1483
					   placeholder="<?php _e( 'Your username or email', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1484
			</div>
1485
1486
			<div id="give-user-pass-wrap-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1487
				 class="give_login_password form-row form-row-last form-row-responsive">
1488
				<label class="give-label" for="give-user-pass-<?php echo $form_id; ?>">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1489
					<?php _e( 'Password', 'give' ); ?>
1490
					<?php if ( give_logged_in_only( $form_id ) ) { ?>
1491
						<span class="give-required-indicator">*</span>
1492
					<?php } ?>
1493
				</label>
1494
				<input class="give-input<?php echo ( give_logged_in_only( $form_id ) ) ? ' required' : ''; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1495
					   type="password" name="give_user_pass" id="give-user-pass-<?php echo $form_id; ?>"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1496
					   placeholder="<?php _e( 'Your password', 'give' ); ?>"<?php echo ( give_logged_in_only( $form_id ) ) ? ' required aria-required="true" ' : ''; ?>/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '('
Loading history...
1497
				<?php if ( give_logged_in_only( $form_id ) ) : ?>
1498
					<input type="hidden" name="give-purchase-var" value="needs-to-login"/>
1499
				<?php endif; ?>
1500
			</div>
1501
1502
			<div id="give-forgot-password-wrap-<?php echo $form_id; ?>" class="give_login_forgot_password">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1503
				 <span class="give-forgot-password ">
1504
					 <a href="<?php echo wp_lostpassword_url(); ?>"
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'wp_lostpassword_url'
Loading history...
1505
						target="_blank"><?php _e( 'Reset Password', 'give' ); ?></a>
1506
				 </span>
1507
			</div>
1508
		</div>
1509
1510
1511
		<div id="give-user-login-submit-<?php echo $form_id; ?>" class="give-clearfix">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1512
			<input type="submit" class="give-submit give-btn button" name="give_login_submit"
1513
				   value="<?php _e( 'Login', 'give' ); ?>"/>
1514
			<?php if ( $show_register_form !== 'login' ) { ?>
0 ignored issues
show
introduced by
Found "!== '". Use Yoda Condition checks, you must
Loading history...
1515
				<input type="button" data-action="give_cancel_login"
1516
					   class="give-cancel-login give-checkout-register-cancel give-btn button" name="give_login_cancel"
1517
					   value="<?php _e( 'Cancel', 'give' ); ?>"/>
1518
			<?php } ?>
1519
			<span class="give-loading-animation"></span>
1520
		</div>
1521
		<?php
1522
		/**
1523
		 * Fires while rendering checkout login form, after the fields.
1524
		 *
1525
		 * @since 1.0
1526
		 *
1527
		 * @param int $form_id The form ID.
1528
		 */
1529
		do_action( 'give_donation_form_login_fields_after', $form_id );
1530
		?>
1531
	</fieldset><!--end #give-login-fields-->
1532
	<?php
1533
	echo ob_get_clean();
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'ob_get_clean'
Loading history...
1534
}
1535
1536
add_action( 'give_donation_form_login_fields', 'give_get_login_fields', 10, 1 );
1537
1538
/**
1539
 * Payment Mode Select.
1540
 *
1541
 * Renders the payment mode form by getting all the enabled payment gateways and
1542
 * outputting them as radio buttons for the user to choose the payment gateway. If
1543
 * a default payment gateway has been chosen from the Give Settings, it will be
1544
 * automatically selected.
1545
 *
1546
 * @since  1.0
1547
 *
1548
 * @param  int $form_id The form ID.
1549
 *
1550
 * @return void
1551
 */
1552
function give_payment_mode_select( $form_id, $args ) {
1553
1554
	$gateways  = give_get_enabled_payment_gateways( $form_id );
1555
	$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
1556
1557
	/**
1558
	 * Fires while selecting payment gateways, before the fields.
1559
	 *
1560
	 * @since 1.7
1561
	 *
1562
	 * @param int $form_id The form ID.
1563
	 */
1564
	do_action( 'give_payment_mode_top', $form_id );
1565
	?>
1566
1567
	<fieldset id="give-payment-mode-select"
1568
		<?php
1569
		if ( count( $gateways ) <= 1 ) {
1570
			echo 'style="display: none;"';
1571
		}
1572
		?>
1573
	>
1574
		<?php
1575
		/**
1576
		 * Fires while selecting payment gateways, before the wrap div.
1577
		 *
1578
		 * @since 1.7
1579
		 *
1580
		 * @param int $form_id The form ID.
1581
		 */
1582
		do_action( 'give_payment_mode_before_gateways_wrap' );
1583
		?>
1584
		<legend
1585
			class="give-payment-mode-label"><?php echo apply_filters( 'give_checkout_payment_method_text', esc_html__( 'Select Payment Method', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1586
			<span class="give-loading-text"><span
1587
					class="give-loading-animation"></span>
1588
			</span>
1589
		</legend>
1590
1591
		<div id="give-payment-mode-wrap">
1592
			<?php
1593
			/**
1594
			 * Fires while selecting payment gateways, before the gateways list.
1595
			 *
1596
			 * @since 1.7
1597
			 */
1598
			do_action( 'give_payment_mode_before_gateways' )
1599
			?>
1600
			<ul id="give-gateway-radio-list">
1601
				<?php
1602
				/**
1603
				 * Loop through the active payment gateways.
1604
				 */
1605
				$selected_gateway = give_get_chosen_gateway( $form_id );
1606
				$give_settings    = give_get_settings();
1607
				$gateways_label   = array_key_exists( 'gateways_label', $give_settings ) ?
1608
					$give_settings['gateways_label'] :
1609
					array();
1610
1611
				foreach ( $gateways as $gateway_id => $gateway ) :
1612
					// Determine the default gateway.
1613
					$checked                   = checked( $gateway_id, $selected_gateway, false );
1614
					$checked_class             = $checked ? ' class="give-gateway-option-selected"' : '';
1615
					$is_payment_method_visible = isset( $gateway['is_visible'] ) ? $gateway['is_visible'] : true;
1616
1617
					if ( true === $is_payment_method_visible ) {
1618
						?>
1619
						<li<?php echo $checked_class; ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$checked_class'
Loading history...
1620
							<input type="radio" name="payment-mode" class="give-gateway"
1621
								id="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1622
								value="<?php echo esc_attr( $gateway_id ); ?>"<?php echo $checked; ?>>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$checked'
Loading history...
1623
1624
							<?php
1625
							$label = $gateway['checkout_label'];
1626
							if ( ! empty( $gateways_label[ $gateway_id ] ) ) {
1627
								$label = $gateways_label[ $gateway_id ];
1628
							}
1629
							?>
1630
							<label for="give-gateway-<?php echo esc_attr( $gateway_id . '-' . $id_prefix ); ?>"
1631
								class="give-gateway-option"
1632
								id="give-gateway-option-<?php echo esc_attr( $gateway_id ); ?>"> <?php echo esc_html( $label ); ?></label>
1633
						</li>
1634
					<?php
1635
					}
1636
				endforeach;
1637
				?>
1638
			</ul>
1639
			<?php
1640
			/**
1641
			 * Fires while selecting payment gateways, before the gateways list.
1642
			 *
1643
			 * @since 1.7
1644
			 */
1645
			do_action( 'give_payment_mode_after_gateways' );
1646
			?>
1647
		</div>
1648
		<?php
1649
		/**
1650
		 * Fires while selecting payment gateways, after the wrap div.
1651
		 *
1652
		 * @since 1.7
1653
		 *
1654
		 * @param int $form_id The form ID.
1655
		 */
1656
		do_action( 'give_payment_mode_after_gateways_wrap' );
1657
		?>
1658
	</fieldset>
1659
1660
	<?php
1661
	/**
1662
	 * Fires while selecting payment gateways, after the fields.
1663
	 *
1664
	 * @since 1.7
1665
	 *
1666
	 * @param int $form_id The form ID.
1667
	 */
1668
	do_action( 'give_payment_mode_bottom', $form_id );
1669
	?>
1670
1671
	<div id="give_purchase_form_wrap">
1672
1673
		<?php
1674
		/**
1675
		 * Fire after payment field render.
1676
		 *
1677
		 * @since 1.7
1678
		 */
1679
		do_action( 'give_donation_form', $form_id, $args );
1680
		?>
1681
1682
	</div>
1683
1684
	<?php
1685
	/**
1686
	 * Fire after donation form render.
1687
	 *
1688
	 * @since 1.7
1689
	 */
1690
	do_action( 'give_donation_form_wrap_bottom', $form_id );
1691
}
1692
1693
add_action( 'give_payment_mode_select', 'give_payment_mode_select', 10, 2 );
1694
1695
/**
1696
 * Renders the Checkout Agree to Terms, this displays a checkbox for users to
1697
 * agree the T&Cs set in the Give Settings. This is only displayed if T&Cs are
1698
 * set in the Give Settings.
1699
 *
1700
 * @since  1.0
1701
 *
1702
 * @param  int $form_id The form ID.
1703
 *
1704
 * @return bool
1705
 */
1706
function give_terms_agreement( $form_id ) {
1707
	$form_option = give_get_meta( $form_id, '_give_terms_option', true );
1708
1709
	// Bailout if per form and global term and conditions is not setup.
1710
	if (
1711
		give_is_setting_enabled( $form_option, 'global' )
1712
		&& give_is_setting_enabled( give_get_option( 'terms' ) )
1713
	) {
1714
		$label         = give_get_option( 'agree_to_terms_label', esc_html__( 'Agree to Terms?', 'give' ) );
1715
		$terms         = $terms = give_get_option( 'agreement_text', '' );
1716
		$edit_term_url = admin_url( 'edit.php?post_type=give_forms&page=give-settings&tab=display&section=term-and-conditions' );
1717
1718
	} elseif ( give_is_setting_enabled( $form_option ) ) {
1719
		$label         = ( $label = give_get_meta( $form_id, '_give_agree_label', true ) ) ? stripslashes( $label ) : esc_html__( 'Agree to Terms?', 'give' );
1720
		$terms         = give_get_meta( $form_id, '_give_agree_text', true );
1721
		$edit_term_url = admin_url( 'post.php?post=' . $form_id . '&action=edit#form_terms_options' );
1722
1723
	} else {
1724
		return false;
1725
	}
1726
1727
	// Bailout: Check if term and conditions text is empty or not.
1728
	if ( empty( $terms ) ) {
1729
		if ( is_user_logged_in() && current_user_can( 'edit_give_forms' ) ) {
1730
			echo sprintf( __( 'Please enter valid terms and conditions in <a href="%s">this form\'s settings</a>.', 'give' ), $edit_term_url );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
1731
		}
1732
1733
		return false;
1734
	}
1735
1736
	/**
1737
	 * Filter the form term content
1738
	 *
1739
	 * @since  2.1.5
1740
	 */
1741
	$terms = apply_filters( 'give_the_term_content', wpautop( do_shortcode( $terms ) ), $terms, $form_id );
1742
1743
	?>
1744
	<fieldset id="give_terms_agreement">
1745
		<legend><?php echo apply_filters( 'give_terms_agreement_text', esc_html__( 'Terms', 'give' ) ); ?></legend>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1746
		<div id="give_terms" class="give_terms-<?php echo $form_id; ?>" style="display:none;">
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1747
			<?php
1748
			/**
1749
			 * Fires while rendering terms of agreement, before the fields.
1750
			 *
1751
			 * @since 1.0
1752
			 */
1753
			do_action( 'give_before_terms' );
1754
1755
			echo $terms;
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$terms'
Loading history...
1756
			/**
1757
			 * Fires while rendering terms of agreement, after the fields.
1758
			 *
1759
			 * @since 1.0
1760
			 */
1761
			do_action( 'give_after_terms' );
1762
			?>
1763
		</div>
1764
		<div id="give_show_terms">
1765
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1766
			   aria-controls="give_terms"><?php esc_html_e( 'Show Terms', 'give' ); ?></a>
1767
			<a href="#" class="give_terms_links give_terms_links-<?php echo $form_id; ?>" role="button"
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1768
			   aria-controls="give_terms" style="display:none;"><?php esc_html_e( 'Hide Terms', 'give' ); ?></a>
1769
		</div>
1770
1771
		<input name="give_agree_to_terms" class="required" type="checkbox"
1772
			   id="give_agree_to_terms-<?php echo $form_id; ?>" value="1" required aria-required="true"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
1773
		<label for="give_agree_to_terms-<?php echo $form_id; ?>"><?php echo $label; ?></label>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$form_id'
Loading history...
introduced by
Expected next thing to be a escaping function, not '$label'
Loading history...
1774
1775
	</fieldset>
1776
	<?php
1777
}
1778
1779
add_action( 'give_donation_form_after_cc_form', 'give_terms_agreement', 8888, 1 );
1780
1781
/**
1782
 * Checkout Final Total.
1783
 *
1784
 * Shows the final donation total at the bottom of the checkout page.
1785
 *
1786
 * @since  1.0
1787
 *
1788
 * @param  int $form_id The form ID.
1789
 *
1790
 * @return void
1791
 */
1792
function give_checkout_final_total( $form_id ) {
1793
1794
	$total = isset( $_POST['give_total'] ) ?
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
1795
		apply_filters( 'give_donation_total', give_maybe_sanitize_amount( $_POST['give_total'] ) ) :
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
1796
		give_get_default_form_amount( $form_id );
1797
1798
	// Only proceed if give_total available.
1799
	if ( empty( $total ) ) {
1800
		return;
1801
	}
1802
	?>
1803
	<p id="give-final-total-wrap" class="form-wrap ">
1804
		<?php
1805
		/**
1806
		 * Fires before the donation total label
1807
		 *
1808
		 * @since 2.0.5
1809
		 */
1810
		do_action( 'give_donation_final_total_label_before', $form_id );
1811
		?>
1812
		<span class="give-donation-total-label">
1813
			<?php echo apply_filters( 'give_donation_total_label', esc_html__( 'Donation Total:', 'give' ) ); ?>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1814
		</span>
1815
		<span class="give-final-total-amount"
1816
			  data-total="<?php echo give_format_amount( $total, array( 'sanitize' => false ) ); ?>">
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_format_amount'
Loading history...
1817
			<?php
1818
			echo give_currency_filter(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_currency_filter'
Loading history...
1819
				give_format_amount(
1820
					$total, array(
1821
						'sanitize' => false,
1822
						'currency' => give_get_currency( $form_id ),
1823
					)
1824
				), array( 'currency_code' => give_get_currency( $form_id ) )
1825
			);
1826
			?>
1827
		</span>
1828
		<?php
1829
		/**
1830
		 * Fires after the donation final total label
1831
		 *
1832
		 * @since 2.0.5
1833
		 */
1834
		do_action( 'give_donation_final_total_label_after', $form_id );
1835
		?>
1836
	</p>
1837
	<?php
1838
}
1839
1840
add_action( 'give_donation_form_before_submit', 'give_checkout_final_total', 999 );
1841
1842
/**
1843
 * Renders the Checkout Submit section.
1844
 *
1845
 * @since  1.0
1846
 *
1847
 * @param int   $form_id The donation form ID.
1848
 * @param array $args    List of arguments.
1849
 *
1850
 * @return void
1851
 */
1852
function give_checkout_submit( $form_id, $args ) {
1853
	?>
1854
	<fieldset id="give_purchase_submit" class="give-donation-submit">
1855
		<?php
1856
		/**
1857
		 * Fire before donation form submit.
1858
		 *
1859
		 * @since 1.7
1860
		 */
1861
		do_action( 'give_donation_form_before_submit', $form_id, $args );
1862
1863
		give_checkout_hidden_fields( $form_id );
1864
1865
		echo give_get_donation_form_submit_button( $form_id, $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_donation_form_submit_button'
Loading history...
1866
1867
		/**
1868
		 * Fire after donation form submit.
1869
		 *
1870
		 * @since 1.7
1871
		 */
1872
		do_action( 'give_donation_form_after_submit', $form_id, $args );
1873
		?>
1874
	</fieldset>
1875
	<?php
1876
}
1877
1878
add_action( 'give_donation_form_after_cc_form', 'give_checkout_submit', 9999, 2 );
1879
1880
/**
1881
 * Give Donation form submit button.
1882
 *
1883
 * @since  1.8.8
1884
 *
1885
 * @param  int $form_id The form ID.
1886
 *
1887
 * @return string
1888
 */
1889
function give_get_donation_form_submit_button( $form_id, $args ) {
1890
1891
	$display_label_field = give_get_meta( $form_id, '_give_checkout_label', true );
1892
	$display_label       = ( ! empty( $display_label_field ) ? $display_label_field : esc_html__( 'Donate Now', 'give' ) );
1893
	ob_start();
1894
	?>
1895
	<div class="give-submit-button-wrap give-clearfix">
1896
		<input type="submit" class="give-submit give-btn" id="give-purchase-button" name="give-purchase"
1897
			   value="<?php echo $display_label; ?>" data-before-validation-label="<?php echo $display_label; ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$display_label'
Loading history...
1898
		<span class="give-loading-animation"></span>
1899
	</div>
1900
	<?php
1901
	return apply_filters( 'give_donation_form_submit_button', ob_get_clean(), $form_id, $args );
1902
}
1903
1904
/**
1905
 * Show Give Goals.
1906
 *
1907
 * @since  1.0
1908
 * @since  1.6   Add template for Give Goals Shortcode.
1909
 *               More info is on https://github.com/impress-org/give/issues/411
1910
 *
1911
 * @param  int   $form_id The form ID.
1912
 * @param  array $args    An array of form arguments.
1913
 *
1914
 * @return mixed
1915
 */
1916
function give_show_goal_progress( $form_id, $args = array() ) {
1917
1918
	ob_start();
1919
	give_get_template(
1920
		'shortcode-goal', array(
1921
			'form_id' => $form_id,
1922
			'args'    => $args,
1923
		)
1924
	);
1925
1926
	/**
1927
	 * Filter progress bar output
1928
	 *
1929
	 * @since 2.0
1930
	 */
1931
	echo apply_filters( 'give_goal_output', ob_get_clean(), $form_id, $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1932
1933
	return true;
1934
}
1935
1936
add_action( 'give_pre_form', 'give_show_goal_progress', 10, 2 );
1937
1938
/**
1939
 * Show Give Totals Progress.
1940
 *
1941
 * @since  2.1
1942
 *
1943
 * @param  int $total      Total amount based on shortcode parameter.
1944
 * @param  int $total_goal Total Goal amount passed by Admin.
1945
 *
1946
 * @return mixed
1947
 */
1948
function give_show_goal_totals_progress( $total, $total_goal ) {
1949
1950
	// Bail out if total goal is set as an array.
1951
	if ( isset( $total_goal ) && is_array( $total_goal ) ) {
1952
		return false;
1953
	}
1954
1955
	ob_start();
1956
	give_get_template(
1957
		'shortcode-totals-progress', array(
1958
			'total'      => $total,
1959
			'total_goal' => $total_goal,
1960
		)
1961
	);
1962
1963
	echo apply_filters( 'give_total_progress_output', ob_get_clean() );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
1964
1965
	return true;
1966
}
1967
1968
add_action( 'give_pre_form', 'give_show_goal_totals_progress', 10, 2 );
1969
1970
/**
1971
 * Get form content position.
1972
 *
1973
 * @since  1.8
1974
 *
1975
 * @param  $form_id
1976
 * @param  $args
1977
 *
1978
 * @return mixed|string
1979
 */
1980
function give_get_form_content_placement( $form_id, $args ) {
1981
	$show_content = '';
1982
1983
	if ( isset( $args['show_content'] ) && ! empty( $args['show_content'] ) ) {
1984
		// Content positions.
1985
		$content_placement = array(
1986
			'above' => 'give_pre_form',
1987
			'below' => 'give_post_form',
1988
		);
1989
1990
		// Check if content position already decoded.
1991
		if ( in_array( $args['show_content'], $content_placement ) ) {
1992
			return $args['show_content'];
1993
		}
1994
1995
		$show_content = ( 'none' !== $args['show_content'] ? $content_placement[ $args['show_content'] ] : '' );
1996
1997
	} elseif ( give_is_setting_enabled( give_get_meta( $form_id, '_give_display_content', true ) ) ) {
1998
		$show_content = give_get_meta( $form_id, '_give_content_placement', true );
1999
2000
	}
2001
2002
	return $show_content;
2003
}
2004
2005
/**
2006
 * Adds Actions to Render Form Content.
2007
 *
2008
 * @since  1.0
2009
 *
2010
 * @param  int   $form_id The form ID.
2011
 * @param  array $args    An array of form arguments.
2012
 *
2013
 * @return void|bool
2014
 */
2015
function give_form_content( $form_id, $args ) {
2016
2017
	$show_content = give_get_form_content_placement( $form_id, $args );
2018
2019
	// Bailout.
2020
	if ( empty( $show_content ) ) {
2021
		return false;
2022
	}
2023
2024
	// Add action according to value.
2025
	add_action( $show_content, 'give_form_display_content', 10, 2 );
2026
}
2027
2028
add_action( 'give_pre_form_output', 'give_form_content', 10, 2 );
2029
2030
/**
2031
 * Renders Post Form Content.
2032
 *
2033
 * Displays content for Give forms; fired by action from give_form_content.
2034
 *
2035
 * @since  1.0
2036
 *
2037
 * @param  int   $form_id The form ID.
2038
 * @param  array $args    An array of form arguments.
2039
 *
2040
 * @return void
2041
 */
2042
function give_form_display_content( $form_id, $args ) {
2043
	$content      = give_get_meta( $form_id, '_give_form_content', true );
2044
	$show_content = give_get_form_content_placement( $form_id, $args );
2045
2046
	if ( give_is_setting_enabled( give_get_option( 'the_content_filter' ) ) ) {
2047
2048
		// Do not restore wpautop if we are still parsing blocks.
2049
		$priority = has_filter( 'the_content', '_restore_wpautop_hook' );
2050
		if ( false !== $priority && doing_filter( 'the_content' ) ) {
2051
			remove_filter( 'the_content', '_restore_wpautop_hook', $priority );
2052
		}
2053
2054
		$content = apply_filters( 'the_content', $content );
2055
2056
		// Restore wpautop after done with blocks parsing.
2057
		if ( $priority ) {
2058
			// Run wpautop manually if parsing block
2059
			$content = wpautop( $content );
2060
2061
			add_filter( 'the_content', '_restore_wpautop_hook', $priority );
2062
		}
2063
	} else {
2064
		$content = wpautop( do_shortcode( $content ) );
2065
	}
2066
2067
	$output = sprintf(
2068
		'<div id="give-form-content-%s" class="give-form-content-wrap %s-content">%s</div>',
2069
		$form_id,
2070
		$show_content,
2071
		$content
2072
	);
2073
2074
	/**
2075
	 * Filter form content html
2076
	 *
2077
	 * @since 1.0
2078
	 *
2079
	 * @param string $output
2080
	 * @param int    $form_id
2081
	 * @param array  $args
2082
	 */
2083
	echo apply_filters( 'give_form_content_output', $output, $form_id, $args );
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'apply_filters'
Loading history...
2084
2085
	// remove action to prevent content output on addition forms on page.
2086
	// @see: https://github.com/impress-org/give/issues/634.
2087
	remove_action( $show_content, 'give_form_display_content' );
2088
}
2089
2090
/**
2091
 * Renders the hidden Checkout fields.
2092
 *
2093
 * @since 1.0
2094
 *
2095
 * @param  int $form_id The form ID.
2096
 *
2097
 * @return void
2098
 */
2099
function give_checkout_hidden_fields( $form_id ) {
2100
2101
	/**
2102
	 * Fires while rendering hidden checkout fields, before the fields.
2103
	 *
2104
	 * @since 1.0
2105
	 *
2106
	 * @param int $form_id The form ID.
2107
	 */
2108
	do_action( 'give_hidden_fields_before', $form_id );
2109
2110
	if ( is_user_logged_in() ) {
2111
		?>
2112
		<input type="hidden" name="give-user-id" value="<?php echo get_current_user_id(); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'get_current_user_id'
Loading history...
2113
	<?php } ?>
2114
	<input type="hidden" name="give_action" value="purchase"/>
2115
	<input type="hidden" name="give-gateway" value="<?php echo give_get_chosen_gateway( $form_id ); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_get_chosen_gateway'
Loading history...
2116
	<?php
2117
	/**
2118
	 * Fires while rendering hidden checkout fields, after the fields.
2119
	 *
2120
	 * @since 1.0
2121
	 *
2122
	 * @param int $form_id The form ID.
2123
	 */
2124
	do_action( 'give_hidden_fields_after', $form_id );
2125
2126
}
2127
2128
/**
2129
 * Filter Success Page Content.
2130
 *
2131
 * Applies filters to the success page content.
2132
 *
2133
 * @since 1.0
2134
 *
2135
 * @param  string $content Content before filters.
2136
 *
2137
 * @return string $content Filtered content.
2138
 */
2139
function give_filter_success_page_content( $content ) {
2140
2141
	$give_options = give_get_settings();
2142
2143
	if ( isset( $give_options['success_page'] ) && isset( $_GET['payment-confirmation'] ) && is_page( $give_options['success_page'] ) ) {
2144
		if ( has_filter( 'give_payment_confirm_' . $_GET['payment-confirmation'] ) ) {
2145
			$content = apply_filters( 'give_payment_confirm_' . $_GET['payment-confirmation'], $content );
0 ignored issues
show
introduced by
Detected access of super global var $_GET, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_GET
Loading history...
2146
		}
2147
	}
2148
2149
	return $content;
2150
}
2151
2152
add_filter( 'the_content', 'give_filter_success_page_content' );
2153
2154
/**
2155
 * Test Mode Frontend Warning.
2156
 *
2157
 * Displays a notice on the frontend for donation forms.
2158
 *
2159
 * @since 1.1
2160
 */
2161
function give_test_mode_frontend_warning() {
2162
2163
	if ( give_is_test_mode() ) {
2164
		echo '<div class="give_error give_warning" id="give_error_test_mode"><p><strong>' . esc_html__( 'Notice:', 'give' ) . '</strong> ' . esc_html__( 'Test mode is enabled. While in test mode no live donations are processed.', 'give' ) . '</p></div>';
2165
	}
2166
}
2167
2168
add_action( 'give_pre_form', 'give_test_mode_frontend_warning', 10 );
2169
2170
/**
2171
 * Members-only Form.
2172
 *
2173
 * If "Disable Guest Donations" and "Display Register / Login" is set to none.
2174
 *
2175
 * @since  1.4.1
2176
 *
2177
 * @param  string $final_output
2178
 * @param  array  $args
2179
 *
2180
 * @return string
2181
 */
2182
function give_members_only_form( $final_output, $args ) {
2183
2184
	$form_id = isset( $args['form_id'] ) ? $args['form_id'] : 0;
2185
2186
	// Sanity Check: Must have form_id & not be logged in.
2187
	if ( empty( $form_id ) || is_user_logged_in() ) {
2188
		return $final_output;
2189
	}
2190
2191
	// Logged in only and Register / Login set to none.
2192
	if ( give_logged_in_only( $form_id ) && give_show_login_register_option( $form_id ) == 'none' ) {
0 ignored issues
show
introduced by
Found "== '". Use Yoda Condition checks, you must
Loading history...
2193
2194
		$final_output = Give()->notices->print_frontend_notice( esc_html__( 'Please log in in order to complete your donation.', 'give' ), false );
2195
2196
		return apply_filters( 'give_members_only_output', $final_output, $form_id );
2197
2198
	}
2199
2200
	return $final_output;
2201
2202
}
2203
2204
add_filter( 'give_donate_form', 'give_members_only_form', 10, 2 );
2205
2206
2207
/**
2208
 * Add donation form hidden fields.
2209
 *
2210
 * @since 1.8.17
2211
 *
2212
 * @param int              $form_id
2213
 * @param array            $args
2214
 * @param Give_Donate_Form $form
2215
 */
2216
function __give_form_add_donation_hidden_field( $form_id, $args, $form ) {
2217
	$id_prefix = ! empty( $args['id_prefix'] ) ? $args['id_prefix'] : '';
2218
	?>
2219
	<input type="hidden" name="give-form-id-prefix" value="<?php echo $id_prefix; ?>"/>
0 ignored issues
show
introduced by
Expected next thing to be a escaping function, not '$id_prefix'
Loading history...
2220
	<input type="hidden" name="give-form-id" value="<?php echo intval( $form_id ); ?>"/>
2221
	<input type="hidden" name="give-form-title" value="<?php echo esc_html( $form->post_title ); ?>"/>
2222
	<input type="hidden" name="give-current-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2223
	<input type="hidden" name="give-form-url" value="<?php echo esc_url( give_get_current_page_url() ); ?>"/>
2224
	<?php
2225
	// Get the custom option amount.
2226
	$custom_amount = give_get_meta( $form_id, '_give_custom_amount', true );
2227
2228
	// If custom amount enabled.
2229
	if ( give_is_setting_enabled( $custom_amount ) ) {
2230
		?>
2231
		<input type="hidden" name="give-form-minimum"
2232
			   value="<?php echo give_maybe_sanitize_amount( give_get_form_minimum_price( $form_id ) ); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_maybe_sanitize_amount'
Loading history...
2233
		<input type="hidden" name="give-form-maximum"
2234
			   value="<?php echo give_maybe_sanitize_amount( give_get_form_maximum_price( $form_id ) ); ?>"/>
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'give_maybe_sanitize_amount'
Loading history...
2235
		<?php
2236
	}
2237
2238
	$data_attr = sprintf(
2239
		'data-time="%1$s" data-nonce-life="%2$s" data-donor-session="%3$s"',
2240
		time(),
2241
		give_get_nonce_life(),
2242
		absint( Give()->session->has_session() )
2243
	);
2244
2245
	// WP nonce field.
2246
	echo str_replace(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'str_replace'
Loading history...
2247
		'/>',
2248
		"{$data_attr}/>",
2249
		give_get_nonce_field( "give_donation_form_nonce_{$form_id}", 'give-form-hash', false )
2250
	);
2251
2252
	// Price ID hidden field for variable (multi-level) donation forms.
2253
	if ( give_has_variable_prices( $form_id ) ) {
2254
		// Get the default price ID.
2255
		$default_price = give_form_get_default_level( $form_id );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $default_price is correct as give_form_get_default_level($form_id) (which targets give_form_get_default_level()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
2256
		$price_id      = isset( $default_price['_give_id']['level_id'] ) ? $default_price['_give_id']['level_id'] : 0;
2257
2258
		echo sprintf(
0 ignored issues
show
introduced by
Expected a sanitizing function (see Codex for 'Data Validation'), but instead saw 'sprintf'
Loading history...
2259
			'<input type="hidden" name="give-price-id" value="%s"/>',
2260
			$price_id
2261
		);
2262
	}
2263
}
2264
2265
add_action( 'give_donation_form_top', '__give_form_add_donation_hidden_field', 0, 3 );
2266
2267
/**
2268
 * Add currency settings on donation form.
2269
 *
2270
 * @since 1.8.17
2271
 *
2272
 * @param array            $form_html_tags
2273
 * @param Give_Donate_Form $form
2274
 *
2275
 * @return array
2276
 */
2277
function __give_form_add_currency_settings( $form_html_tags, $form ) {
2278
	$form_currency     = give_get_currency( $form->ID );
2279
	$currency_settings = give_get_currency_formatting_settings( $form_currency );
2280
2281
	// Check if currency exist.
2282
	if ( empty( $currency_settings ) ) {
2283
		return $form_html_tags;
2284
	}
2285
2286
	$form_html_tags['data-currency_symbol'] = give_currency_symbol( $form_currency );
2287
	$form_html_tags['data-currency_code']   = $form_currency;
2288
2289
	if ( ! empty( $currency_settings ) ) {
2290
		foreach ( $currency_settings as $key => $value ) {
2291
			$form_html_tags[ "data-{$key}" ] = $value;
2292
		}
2293
	}
2294
2295
	return $form_html_tags;
2296
}
2297
2298
add_filter( 'give_form_html_tags', '__give_form_add_currency_settings', 0, 2 );
2299
2300
/**
2301
 * Adds classes to progress bar container.
2302
 *
2303
 * @since 2.1
2304
 *
2305
 * @param string $class_goal
2306
 *
2307
 * @return string
2308
 */
2309
function add_give_goal_progress_class( $class_goal ) {
0 ignored issues
show
Unused Code introduced by
The parameter $class_goal is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2310
	$class_goal = 'progress progress-striped active';
2311
2312
	return $class_goal;
2313
}
2314
2315
/**
2316
 * Adds classes to progress bar span tag.
2317
 *
2318
 * @since 2.1
2319
 *
2320
 * @param string $class_bar
2321
 *
2322
 * @return string
2323
 */
2324
function add_give_goal_progress_bar_class( $class_bar ) {
0 ignored issues
show
Unused Code introduced by
The parameter $class_bar is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2325
	$class_bar = 'bar';
2326
2327
	return $class_bar;
2328
}
2329
2330
/**
2331
 * Add a class to the form wrap on the grid page.
2332
 *
2333
 * @param array $class Array of form wrapper classes.
2334
 * @param int   $id    ID of the form.
2335
 * @param array $args  Additional args.
2336
 *
2337
 * @since 2.1
2338
 *
2339
 * @return array
2340
 */
2341
function add_class_for_form_grid( $class, $id, $args ) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2342
	$class[] = 'give-form-grid-wrap';
2343
2344
	foreach ( $class as $index => $item ) {
2345
		if ( false !== strpos( $item, 'give-display-' ) ) {
2346
			unset( $class[ $index ] );
2347
		}
2348
	}
2349
2350
	return $class;
2351
}
2352
2353
/**
2354
 * Add hidden field to Form Grid page
2355
 *
2356
 * @param int              $form_id The form ID.
0 ignored issues
show
Bug introduced by
There is no parameter named $form_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
2357
 * @param array            $args    An array of form arguments.
2358
 * @param Give_Donate_Form $form    Form object.
2359
 *
2360
 * @since 2.1
2361
 */
2362
function give_is_form_grid_page_hidden_field( $id, $args, $form ) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $form is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
2363
	echo '<input type="hidden" name="is-form-grid" value="true" />';
2364
}
2365
2366
/**
2367
 * Redirect to the same paginated URL on the Form Grid page
2368
 * and adds query parameters to open the popup again after
2369
 * redirection.
2370
 *
2371
 * @param string $redirect URL for redirection.
2372
 * @param array  $args     Array of additional args.
2373
 *
2374
 * @since 2.1
2375
 * @return string
2376
 */
2377
function give_redirect_and_popup_form( $redirect, $args ) {
2378
2379
	// Check the page has Form Grid.
2380
	$is_form_grid = isset( $_POST['is-form-grid'] ) ? give_clean( $_POST['is-form-grid'] ) : '';
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
2381
2382
	if ( 'true' === $is_form_grid ) {
2383
2384
		$payment_mode = give_clean( $_POST['payment-mode'] );
0 ignored issues
show
introduced by
Detected access of super global var $_POST, probably need manual inspection.
Loading history...
introduced by
Detected usage of a non-validated input variable: $_POST
Loading history...
introduced by
Detected usage of a non-sanitized input variable: $_POST
Loading history...
2385
		$form_id      = $args['form-id'];
2386
2387
		// Get the URL without Query parameters.
2388
		$redirect = strtok( $redirect, '?' );
2389
2390
		// Add query parameters 'form-id' and 'payment-mode'.
2391
		$redirect = add_query_arg(
2392
			array(
2393
				'form-id'      => $form_id,
2394
				'payment-mode' => $payment_mode,
2395
			), $redirect
2396
		);
2397
	}
2398
2399
	// Return the modified URL.
2400
	return $redirect;
2401
}
2402
2403
add_filter( 'give_send_back_to_checkout', 'give_redirect_and_popup_form', 10, 2 );
2404