template.php ➔ give_payment_mode_select()   B
last analyzed

Complexity

Conditions 7
Paths 40

Size

Total Lines 136

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
nc 40
nop 2
dl 0
loc 136
rs 7.0666
c 0
b 0
f 0

How to fix   Long Method   

Long Method

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

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

Commonly applied refactorings include:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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