Test Setup Failed
Push — master ( b36308...4ef638 )
by
unknown
08:57 queued 10s
created

template.php ➔ give_form_display_content()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 47

Duplication

Lines 0
Ratio 0 %

Importance

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